diff --git a/CHANGELOG.md b/CHANGELOG.md index 7faead61..bac3ab6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.3 (05.09.2022) +* Fix bug in `SetOptions` when setting a signer. +* Fix bug in `TimeBounds` to allow backward compatibility (merged with preconditions). + ## 0.9.2 (09.08.2022) * Fix preconditions to allow minimum sequence number field to be optional. * Add stellar protocol 19 documentation. @@ -13,7 +17,7 @@ * Add CAP-21 preconditions for transaction attributes. * Add CAP-40 decorate signature hint and support for signed payload signature. * Refactor signer key signatures implementation. -* Remove unused alias in tests and fix documentation examples. +* Remove unused alias in tests and fix documentation examples. * Add Trade Agreggations endpoint. ## 0.8.1 (28.07.2022) diff --git a/README.md b/README.md index 1575b5ad..a66fd8c7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The **Stellar SDK** enables the construction, signing and encoding of Stellar [t This library is aimed at developers building Elixir applications that interact with the [**Stellar network**][stellar]. #### Protocol Version Support -| Protocol | Version | +| Protocol | Version | | --------- | ------------ | | 18 | >= v0.8 | | 19 | >= v0.9 | @@ -27,7 +27,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** + ```elixir def deps do [ - {:stellar_sdk, "~> 0.9.2"} + {:stellar_sdk, "~> 0.9.3"} ] end ``` diff --git a/lib/tx_build/default.ex b/lib/tx_build/default.ex index 344f0ee8..9fe7ff54 100644 --- a/lib/tx_build/default.ex +++ b/lib/tx_build/default.ex @@ -20,14 +20,27 @@ defmodule Stellar.TxBuild.Default do @behaviour Stellar.TxBuild.Spec + @preconditions_keys [ + :time_bounds, + :ledger_bounds, + :min_seq_num, + :min_seq_age, + :min_seq_ledger_gap, + :extra_signers + ] + @impl true def new(%Account{} = source_account, opts) do sequence_number = Keyword.get(opts, :sequence_number, SequenceNumber.new()) base_fee = Keyword.get(opts, :base_fee, BaseFee.new()) - preconditions = Keyword.get(opts, :preconditions, Preconditions.new()) memo = Keyword.get(opts, :memo, Memo.new()) operations = Keyword.get(opts, :operations, Operations.new()) + preconditions = + opts + |> Keyword.take(@preconditions_keys) + |> Preconditions.new() + case Transaction.new( source_account: source_account, sequence_number: sequence_number, diff --git a/lib/tx_build/preconditions.ex b/lib/tx_build/preconditions.ex index 421a9d18..d60cc387 100644 --- a/lib/tx_build/preconditions.ex +++ b/lib/tx_build/preconditions.ex @@ -59,7 +59,7 @@ defmodule Stellar.TxBuild.Preconditions do min_seq_num = Keyword.get(preconditions, :min_seq_num) min_seq_age = Keyword.get(preconditions, :min_seq_age, 0) min_seq_ledger_gap = Keyword.get(preconditions, :min_seq_ledger_gap, 0) - extra_signers = Keyword.get(preconditions, :extra_signers) + extra_signers = Keyword.get(preconditions, :extra_signers, []) with {:ok, time_bounds} <- validate_time_bounds(time_bounds), {:ok, ledger_bounds} <- validate_ledger_bounds(ledger_bounds), diff --git a/lib/tx_build/signer.ex b/lib/tx_build/signer.ex index 714145d8..e0c8fb0e 100644 --- a/lib/tx_build/signer.ex +++ b/lib/tx_build/signer.ex @@ -16,6 +16,8 @@ defmodule Stellar.TxBuild.Signer do @impl true def new(args, opts \\ []) + def new([{_key_type, signer_key}, {:weight, weight}], _opts), do: new({signer_key, weight}) + def new({signer_key, weight}, _opts) do with {:ok, signer_key} <- validate_signer_key(signer_key), {:ok, weight} <- validate_signer_weight(weight) do diff --git a/mix.exs b/mix.exs index a47e01d0..0f6248e2 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.9.2" + @version "0.9.3" def project do [ diff --git a/test/tx_build/default_test.exs b/test/tx_build/default_test.exs index 61c69931..4ec90ca0 100644 --- a/test/tx_build/default_test.exs +++ b/test/tx_build/default_test.exs @@ -17,7 +17,8 @@ defmodule Stellar.TxBuild.DefaultTest do Signature, TimeBounds, Transaction, - TransactionEnvelope + TransactionEnvelope, + OptionalSequenceNumber } setup do @@ -98,8 +99,45 @@ defmodule Stellar.TxBuild.DefaultTest do ) end + test "new/2 with preconditions with only time_bounds for precond_time", %{ + source_account: source_account + } do + time_bounds = TimeBounds.new(min_time: 123, max_time: 321) + + {:ok, + %TxBuild{ + tx: %Transaction{ + preconditions: %{type: :precond_time, preconditions: ^time_bounds} + } + }} = TxBuild.new(source_account, time_bounds: time_bounds) + end + + test "new/2 with preconditions with ledger_bounds and time_bounds for precond_v2", %{ + source_account: source_account + } do + time_bounds = TimeBounds.new(min_time: 123, max_time: 321) + ledger_bounds = LedgerBounds.new(min_ledger: 123, max_ledger: 456) + + {:ok, + %TxBuild{ + tx: %Transaction{ + preconditions: %{ + type: :precond_v2, + preconditions: [ + time_bounds: ^time_bounds, + ledger_bounds: ^ledger_bounds, + min_seq_num: %OptionalSequenceNumber{sequence_number: nil}, + min_seq_age: 0, + min_seq_ledger_gap: 0, + extra_signers: [] + ] + } + } + }} = TxBuild.new(source_account, time_bounds: time_bounds, ledger_bounds: ledger_bounds) + end + test "new/2 with_bad_options", %{source_account: source_account} do - {:error, :invalid_preconditions} = TxBuild.new(source_account, preconditions: []) + {:error, :invalid_preconditions} = TxBuild.new(source_account, time_bounds: []) end test "new/2 invalid_source_account" do diff --git a/test/tx_build/signer_test.exs b/test/tx_build/signer_test.exs index a60f39e9..0d3eed80 100644 --- a/test/tx_build/signer_test.exs +++ b/test/tx_build/signer_test.exs @@ -33,6 +33,14 @@ defmodule Stellar.TxBuild.SignerTest do %Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({ed25519, 2}) end + test "new/2 ed25519 with_input_as_keywordlist", %{ + ed25519: ed25519, + ed25519_signer_key: signer_key, + weight: weight + } do + %Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new(ed25519: ed25519, weight: 2) + end + test "new/2 sha256_hash", %{ sha256_hash: sha256_hash, sha256_hash_signer_key: signer_key, @@ -41,6 +49,15 @@ defmodule Stellar.TxBuild.SignerTest do %Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({sha256_hash, 2}) end + test "new/2 sha256_hash with_input_as_keywordlist", %{ + sha256_hash: sha256_hash, + sha256_hash_signer_key: signer_key, + weight: weight + } do + %Signer{signer_key: ^signer_key, weight: ^weight} = + Signer.new(sha256_hash: sha256_hash, weight: 2) + end + test "new/2 pre_auth_tx", %{ pre_auth_tx: pre_auth_tx, pre_auth_tx_signer_key: signer_key, @@ -49,6 +66,15 @@ defmodule Stellar.TxBuild.SignerTest do %Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({pre_auth_tx, 2}) end + test "new/2 pre_auth_tx with_input_as_keywordlist", %{ + pre_auth_tx: pre_auth_tx, + pre_auth_tx_signer_key: signer_key, + weight: weight + } do + %Signer{signer_key: ^signer_key, weight: ^weight} = + Signer.new(pre_auth_tx: pre_auth_tx, weight: 2) + end + test "new/2 signed_payload", %{ signed_payload: signed_payload, signed_payload_signer_key: signer_key, @@ -57,6 +83,15 @@ defmodule Stellar.TxBuild.SignerTest do %Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({signed_payload, 2}) end + test "new/2 signed_payload with_input_as_keywordlist", %{ + signed_payload: signed_payload, + signed_payload_signer_key: signer_key, + weight: weight + } do + %Signer{signer_key: ^signer_key, weight: ^weight} = + Signer.new(signed_payload: signed_payload, weight: 2) + end + test "new/2 with_invalid_signer_key" do {:error, :invalid_signer_key} = Signer.new({"XCTP2Y5GZ7TTGHLM3JJKDIPR36", 2}) end