Skip to content

Commit

Permalink
Merge pull request #222 from kommitters/v0.9
Browse files Browse the repository at this point in the history
Release v0.9.3
  • Loading branch information
miguelnietoa authored Sep 5, 2022
2 parents 205c1bd + cba523b commit a55ebf8
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
```
Expand Down
15 changes: 14 additions & 1 deletion lib/tx_build/default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/tx_build/preconditions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions lib/tx_build/signer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.9.2"
@version "0.9.3"

def project do
[
Expand Down
42 changes: 40 additions & 2 deletions test/tx_build/default_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Stellar.TxBuild.DefaultTest do
Signature,
TimeBounds,
Transaction,
TransactionEnvelope
TransactionEnvelope,
OptionalSequenceNumber
}

setup do
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/tx_build/signer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit a55ebf8

Please sign in to comment.