From fd4d46025e7ddff3d87ac022cb1d4c550f168dac Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:29:14 -0500 Subject: [PATCH 1/2] Support to_native for SCVal Address (#344) Co-authored-by: norn --- lib/tx_build/sc_val.ex | 26 ++++++++++++++++++++++++++ test/tx_build/sc_val_test.exs | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/tx_build/sc_val.ex b/lib/tx_build/sc_val.ex index 86fab91..1472939 100644 --- a/lib/tx_build/sc_val.ex +++ b/lib/tx_build/sc_val.ex @@ -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() diff --git a/test/tx_build/sc_val_test.exs b/test/tx_build/sc_val_test.exs index d2fde5d..5d00b6f 100644 --- a/test/tx_build/sc_val_test.exs +++ b/test/tx_build/sc_val_test.exs @@ -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{ @@ -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}, @@ -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}, @@ -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" } ] From 93c434a7e7f00c1726251ab3afedc59a59e5e6c2 Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:58:18 -0500 Subject: [PATCH 2/2] Prepare release v0.19.0 (#345) * Prepare release v0.19.0 Co-authored-by: norn * Capitalize Elixir --------- Co-authored-by: norn --- CHANGELOG.md | 4 ++++ README.md | 2 +- mix.exs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23fd6c1..5b0fea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 38b4433..c9b89cc 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/mix.exs b/mix.exs index 8f96044..aadb272 100644 --- a/mix.exs +++ b/mix.exs @@ -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 [