Skip to content

Commit

Permalink
Merge pull request #346 from kommitters/v0.19
Browse files Browse the repository at this point in the history
Release v0.19.0
  • Loading branch information
CristhianRodriguezMolina authored Oct 27, 2023
2 parents e2d3d49 + 93c434a commit 2e85785
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.19.0 (27.10.2023)

* Add support for `SCAddress` type in the `SCVal` to obtain the Elixir native value.

## 0.18.1 (11.10.2023)

* Add remaining changes for Protocol 20: Soroban.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** +
```elixir
def deps do
[
{:stellar_sdk, "~> 0.18.1"}
{:stellar_sdk, "~> 0.19.0"}
]
end
```
Expand Down
26 changes: 26 additions & 0 deletions lib/tx_build/sc_val.ex
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,32 @@ defmodule Stellar.TxBuild.SCVal do
%{}
end

def to_native(%SCVal{
type: %StellarBase.XDR.SCValType{identifier: :SCV_ADDRESS},
value: %StellarBase.XDR.SCAddress{
sc_address: %StellarBase.XDR.AccountID{
account_id: %StellarBase.XDR.PublicKey{
public_key: %StellarBase.XDR.UInt256{
datum: public_key
}
}
},
type: %StellarBase.XDR.SCAddressType{identifier: :SC_ADDRESS_TYPE_ACCOUNT}
}
}) do
StellarBase.StrKey.encode!(public_key, :ed25519_public_key)
end

def to_native(%SCVal{
type: %StellarBase.XDR.SCValType{identifier: :SCV_ADDRESS},
value: %StellarBase.XDR.SCAddress{
sc_address: %StellarBase.XDR.Hash{value: hash},
type: %StellarBase.XDR.SCAddressType{identifier: :SC_ADDRESS_TYPE_CONTRACT}
}
}) do
StellarBase.StrKey.encode!(hash, :contract)
end

def to_native(_sc_val), do: {:error, :invalid_or_not_supported_sc_val}

@spec validate_xdr_decoding(xdr :: String.t()) :: validation()
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Stellar.MixProject do
use Mix.Project

@github_url "https://github.com/kommitters/stellar_sdk"
@version "0.18.1"
@version "0.19.0"

def project do
[
Expand Down
26 changes: 26 additions & 0 deletions test/tx_build/sc_val_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule Stellar.TxBuild.SCValTest do
# SCAddress
public_key = "GB6FIXFOEK46VBDAG5USXRKKDJYFOBQZDMAPOYY6MC4KMRTSPVUH3X2A"
sc_address = SCAddress.new(public_key)
contract = "CCEMOFO5TE7FGOAJOA3RDHPC6RW3CFXRVIGOFQPFE4ZGOKA2QEA636SN"
sc_address_contract = SCAddress.new(contract)

sc_address_xdr = %StellarBase.XDR.SCAddress{
sc_address: %StellarBase.XDR.AccountID{
Expand All @@ -37,6 +39,15 @@ defmodule Stellar.TxBuild.SCValTest do
type: %StellarBase.XDR.SCAddressType{identifier: :SC_ADDRESS_TYPE_ACCOUNT}
}

sc_address_contract_xdr = %StellarBase.XDR.SCAddress{
sc_address: %StellarBase.XDR.Hash{
value:
<<136, 199, 21, 221, 153, 62, 83, 56, 9, 112, 55, 17, 157, 226, 244, 109, 177, 22, 241,
170, 12, 226, 193, 229, 39, 50, 103, 40, 26, 129, 1, 237>>
},
type: %StellarBase.XDR.SCAddressType{identifier: :SC_ADDRESS_TYPE_CONTRACT}
}

discriminants = [
%{type: :bool, value: true},
%{type: :void, value: nil},
Expand All @@ -56,6 +67,7 @@ defmodule Stellar.TxBuild.SCValTest do
%{type: :vec, value: [sc_val]},
%{type: :map, value: [sc_map_entry]},
%{type: :address, value: sc_address},
%{type: :address, value: sc_address_contract},
%{type: :ledger_key_contract_instance, value: nil},
%{type: :ledger_key_nonce, value: 132_131},
%{type: :contract_instance, value: :token},
Expand Down Expand Up @@ -258,6 +270,20 @@ defmodule Stellar.TxBuild.SCValTest do
type: :map,
value: [sc_map_entry],
native_value: %{"sc_val_key" => 123}
},
%{
val_type: :SCV_ADDRESS,
module: sc_address_xdr,
type: :address,
value: sc_address,
native_value: "GB6FIXFOEK46VBDAG5USXRKKDJYFOBQZDMAPOYY6MC4KMRTSPVUH3X2A"
},
%{
val_type: :SCV_ADDRESS,
module: sc_address_contract_xdr,
type: :address,
value: sc_address_contract,
native_value: "CCEMOFO5TE7FGOAJOA3RDHPC6RW3CFXRVIGOFQPFE4ZGOKA2QEA636SN"
}
]

Expand Down

0 comments on commit 2e85785

Please sign in to comment.