-
-
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.
Updated contract code struct names and created bool struct
- Loading branch information
1 parent
91fc9b4
commit df2dd70
Showing
15 changed files
with
299 additions
and
182 deletions.
There are no files selected for viewing
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
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,42 @@ | ||
defmodule StellarBase.XDR.Bool do | ||
@moduledoc """ | ||
Representation of Stellar `Bool` type. | ||
""" | ||
|
||
@behaviour XDR.Declaration | ||
|
||
@type t :: %__MODULE__{value: boolean()} | ||
|
||
defstruct [:value] | ||
|
||
@spec new(value :: boolean()) :: t() | ||
def new(val), do: %__MODULE__{value: val} | ||
|
||
@impl true | ||
def encode_xdr(%__MODULE__{value: value}) do | ||
XDR.Bool.encode_xdr(%XDR.Bool{identifier: value}) | ||
end | ||
|
||
@impl true | ||
def encode_xdr!(%__MODULE__{value: value}) do | ||
XDR.Bool.encode_xdr!(%XDR.Bool{identifier: value}) | ||
end | ||
|
||
@impl true | ||
def decode_xdr(bytes, term \\ nil) | ||
|
||
def decode_xdr(bytes, _term) do | ||
case XDR.Bool.decode_xdr(bytes) do | ||
{:ok, {%XDR.Bool{identifier: val}, rest}} -> {:ok, {new(val), rest}} | ||
error -> error | ||
end | ||
end | ||
|
||
@impl true | ||
def decode_xdr!(bytes, term \\ nil) | ||
|
||
def decode_xdr!(bytes, _term) do | ||
{%XDR.Bool{identifier: val}, rest} = XDR.Bool.decode_xdr!(bytes) | ||
{new(val), rest} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.