-
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #256 from kommitters/v0.10
Release v0.10.0
- Loading branch information
Showing
63 changed files
with
1,257 additions
and
862 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
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,60 @@ | ||
defmodule StellarBase.XDR.OptionalSCVec do | ||
@moduledoc """ | ||
Representation of Stellar `OptionalSCVec` type. | ||
""" | ||
|
||
alias StellarBase.XDR.SCVec | ||
|
||
@behaviour XDR.Declaration | ||
|
||
@optional_spec XDR.Optional.new(SCVec) | ||
|
||
@type sc_vec :: SCVec.t() | nil | ||
|
||
@type t :: %__MODULE__{sc_vec: sc_vec()} | ||
|
||
defstruct [:sc_vec] | ||
|
||
@spec new(sc_vec :: sc_vec()) :: t() | ||
def new(sc_vec \\ nil), do: %__MODULE__{sc_vec: sc_vec} | ||
|
||
@impl true | ||
def encode_xdr(%__MODULE__{sc_vec: sc_vec}) do | ||
sc_vec | ||
|> XDR.Optional.new() | ||
|> XDR.Optional.encode_xdr() | ||
end | ||
|
||
@impl true | ||
def encode_xdr!(%__MODULE__{sc_vec: sc_vec}) do | ||
sc_vec | ||
|> XDR.Optional.new() | ||
|> XDR.Optional.encode_xdr!() | ||
end | ||
|
||
@impl true | ||
def decode_xdr(bytes, optional_spec \\ @optional_spec) | ||
|
||
def decode_xdr(bytes, optional_spec) do | ||
case XDR.Optional.decode_xdr(bytes, optional_spec) do | ||
{:ok, {%XDR.Optional{type: sc_vec}, rest}} -> | ||
{:ok, {new(sc_vec), rest}} | ||
|
||
{:ok, {nil, rest}} -> | ||
{:ok, {new(), rest}} | ||
|
||
error -> | ||
error | ||
end | ||
end | ||
|
||
@impl true | ||
def decode_xdr!(bytes, optional_spec \\ @optional_spec) | ||
|
||
def decode_xdr!(bytes, optional_spec) do | ||
case XDR.Optional.decode_xdr!(bytes, optional_spec) do | ||
{%XDR.Optional{type: sc_vec}, rest} -> {new(sc_vec), rest} | ||
{nil, rest} -> {new(), rest} | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule StellarBase.XDR.SCBytes do | ||
@moduledoc """ | ||
Representation of Stellar `SCBytes` type. | ||
""" | ||
alias StellarBase.XDR.VariableOpaque256000 | ||
|
||
@behaviour XDR.Declaration | ||
|
||
@type t :: %__MODULE__{value: binary()} | ||
|
||
defstruct [:value] | ||
|
||
@spec new(value :: binary()) :: t() | ||
def new(value), do: %__MODULE__{value: value} | ||
|
||
@impl true | ||
def encode_xdr(%__MODULE__{value: value}) do | ||
value | ||
|> VariableOpaque256000.new() | ||
|> VariableOpaque256000.encode_xdr() | ||
end | ||
|
||
@impl true | ||
def encode_xdr!(%__MODULE__{value: value}) do | ||
value | ||
|> VariableOpaque256000.new() | ||
|> VariableOpaque256000.encode_xdr!() | ||
end | ||
|
||
@impl true | ||
def decode_xdr(bytes, term \\ nil) | ||
|
||
def decode_xdr(bytes, _term) do | ||
case VariableOpaque256000.decode_xdr(bytes) do | ||
{:ok, {%VariableOpaque256000{opaque: value}, rest}} -> {:ok, {new(value), rest}} | ||
error -> error | ||
end | ||
end | ||
|
||
@impl true | ||
def decode_xdr!(bytes, term \\ nil) | ||
|
||
def decode_xdr!(bytes, _term) do | ||
{%VariableOpaque256000{opaque: value}, rest} = VariableOpaque256000.decode_xdr!(bytes) | ||
{new(value), rest} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
defmodule StellarBase.XDR.SCContractExecutable do | ||
@moduledoc """ | ||
Representation of Stellar `SCContractExecutable` type. | ||
""" | ||
|
||
alias StellarBase.XDR.{Hash, SCContractExecutableType, Void} | ||
|
||
@behaviour XDR.Declaration | ||
|
||
@arms [ | ||
SCCONTRACT_EXECUTABLE_WASM_REF: Hash, | ||
SCCONTRACT_EXECUTABLE_TOKEN: Void | ||
] | ||
|
||
@type contract_executable :: Hash.t() | Void.t() | ||
|
||
@type t :: %__MODULE__{ | ||
contract_executable: contract_executable(), | ||
type: SCContractExecutableType.t() | ||
} | ||
|
||
defstruct [:contract_executable, :type] | ||
|
||
@spec new(contract_executable :: contract_executable(), type :: SCContractExecutableType.t()) :: | ||
t() | ||
def new(contract_executable, %SCContractExecutableType{} = type), | ||
do: %__MODULE__{contract_executable: contract_executable, type: type} | ||
|
||
@impl true | ||
def encode_xdr(%__MODULE__{contract_executable: contract_executable, type: type}) do | ||
type | ||
|> XDR.Union.new(@arms, contract_executable) | ||
|> XDR.Union.encode_xdr() | ||
end | ||
|
||
@impl true | ||
def encode_xdr!(%__MODULE__{contract_executable: contract_executable, type: type}) do | ||
type | ||
|> XDR.Union.new(@arms, contract_executable) | ||
|> XDR.Union.encode_xdr!() | ||
end | ||
|
||
@impl true | ||
def decode_xdr(bytes, spec \\ union_spec()) | ||
|
||
def decode_xdr(bytes, spec) do | ||
case XDR.Union.decode_xdr(bytes, spec) do | ||
{:ok, {{type, contract_executable}, rest}} -> {:ok, {new(contract_executable, type), rest}} | ||
error -> error | ||
end | ||
end | ||
|
||
@impl true | ||
def decode_xdr!(bytes, spec \\ union_spec()) | ||
|
||
def decode_xdr!(bytes, spec) do | ||
{{type, contract_executable}, rest} = XDR.Union.decode_xdr!(bytes, spec) | ||
{new(contract_executable, type), rest} | ||
end | ||
|
||
@spec union_spec() :: XDR.Union.t() | ||
defp union_spec do | ||
nil | ||
|> SCContractExecutableType.new() | ||
|> XDR.Union.new(@arms) | ||
end | ||
end |
8 changes: 4 additions & 4 deletions
8
lib/xdr/contract/sc_contract_code_type.ex → ...r/contract/sc_contract_executable_type.ex
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
Oops, something went wrong.