Packages
Low-level elixir library to read, write, hash, and sign XDR primitive constructs used in the Stellar network.
Current section
Files
Jump to
Current section
Files
lib/xdr/contract/optional_sc_val.ex
defmodule StellarBase.XDR.OptionalSCVal do
@moduledoc """
Automatically generated by xdrgen
DO NOT EDIT or your changes may be overwritten
Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr
Representation of Stellar `OptionalSCVal` type.
"""
@behaviour XDR.Declaration
alias StellarBase.XDR.SCVal
@optional_spec XDR.Optional.new(SCVal)
@type sc_val :: SCVal.t() | nil
@type t :: %__MODULE__{sc_val: sc_val()}
defstruct [:sc_val]
@spec new(sc_val :: sc_val()) :: t()
def new(sc_val \\ nil), do: %__MODULE__{sc_val: sc_val}
@impl true
def encode_xdr(%__MODULE__{sc_val: sc_val}) do
sc_val
|> XDR.Optional.new()
|> XDR.Optional.encode_xdr()
end
@impl true
def encode_xdr!(%__MODULE__{sc_val: sc_val}) do
sc_val
|> 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_val}, rest}} -> {:ok, {new(sc_val), 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_val}, rest} -> {new(sc_val), rest}
{nil, rest} -> {new(), rest}
end
end
end