-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from kommitters/v0.9
Release v0.9.2
- Loading branch information
Showing
7 changed files
with
253 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule Stellar.TxBuild.OptionalSequenceNumber do | ||
@moduledoc """ | ||
`OptionalSequenceNumber` struct definition. | ||
""" | ||
alias StellarBase.XDR.OptionalSequenceNumber | ||
alias Stellar.TxBuild.SequenceNumber | ||
|
||
@behaviour Stellar.TxBuild.XDR | ||
|
||
@type sequence_number :: SequenceNumber.t() | nil | ||
|
||
@type t :: %__MODULE__{sequence_number: sequence_number()} | ||
|
||
defstruct [:sequence_number] | ||
|
||
@impl true | ||
def new(sequence_number \\ nil, opts \\ []) | ||
|
||
def new(%SequenceNumber{} = sequence_number, _opts) do | ||
%__MODULE__{sequence_number: sequence_number} | ||
end | ||
|
||
def new(nil, _opts), do: %__MODULE__{sequence_number: nil} | ||
|
||
@impl true | ||
def to_xdr(%__MODULE__{sequence_number: nil}), do: OptionalSequenceNumber.new() | ||
|
||
def to_xdr(%__MODULE__{sequence_number: sequence_number}) do | ||
sequence_number | ||
|> SequenceNumber.to_xdr() | ||
|> OptionalSequenceNumber.new() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Stellar.TxBuild.OptionalSequenceNumberTest do | ||
use ExUnit.Case | ||
|
||
alias Stellar.TxBuild.{SequenceNumber, OptionalSequenceNumber} | ||
alias StellarBase.XDR.SequenceNumber, as: SequenceNumberXDR | ||
alias StellarBase.XDR.OptionalSequenceNumber, as: OptionalSequenceNumberXDR | ||
|
||
setup do | ||
%{sequence_number: SequenceNumber.new(4_130_487_228_432_385)} | ||
end | ||
|
||
test "new/2", %{sequence_number: sequence_number} do | ||
%OptionalSequenceNumber{sequence_number: ^sequence_number} = | ||
OptionalSequenceNumber.new(sequence_number) | ||
end | ||
|
||
test "new/2 without_sequence_number" do | ||
%OptionalSequenceNumber{sequence_number: nil} = OptionalSequenceNumber.new() | ||
end | ||
|
||
test "to_xdr/1", %{sequence_number: sequence_number} do | ||
%OptionalSequenceNumberXDR{ | ||
sequence_number: %SequenceNumberXDR{sequence_number: 4_130_487_228_432_385} | ||
} = | ||
sequence_number | ||
|> OptionalSequenceNumber.new() | ||
|> OptionalSequenceNumber.to_xdr() | ||
end | ||
|
||
test "to_xdr/1 without_sequence_number" do | ||
%OptionalSequenceNumberXDR{sequence_number: nil} = | ||
nil | ||
|> OptionalSequenceNumber.new() | ||
|> OptionalSequenceNumber.to_xdr() | ||
end | ||
end |
Oops, something went wrong.