defmodule StellarBase.XDR.LedgerKeyContractCode 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 `LedgerKeyContractCode` type.
"""
@behaviour XDR.Declaration
alias StellarBase.XDR.{
Hash,
ContractEntryBodyType
}
@struct_spec XDR.Struct.new(
hash: Hash,
body_type: ContractEntryBodyType
)
@type hash_type :: Hash.t()
@type body_type_type :: ContractEntryBodyType.t()
@type t :: %__MODULE__{hash: hash_type(), body_type: body_type_type()}
defstruct [:hash, :body_type]
@spec new(hash :: hash_type(), body_type :: body_type_type()) :: t()
def new(
%Hash{} = hash,
%ContractEntryBodyType{} = body_type
),
do: %__MODULE__{hash: hash, body_type: body_type}
@impl true
def encode_xdr(%__MODULE__{hash: hash, body_type: body_type}) do
[hash: hash, body_type: body_type]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr()
end
@impl true
def encode_xdr!(%__MODULE__{hash: hash, body_type: body_type}) do
[hash: hash, body_type: body_type]
|> XDR.Struct.new()
|> XDR.Struct.encode_xdr!()
end
@impl true
def decode_xdr(bytes, struct \\ @struct_spec)
def decode_xdr(bytes, struct) do
case XDR.Struct.decode_xdr(bytes, struct) do
{:ok, {%XDR.Struct{components: [hash: hash, body_type: body_type]}, rest}} ->
{:ok, {new(hash, body_type), rest}}
error ->
error
end
end
@impl true
def decode_xdr!(bytes, struct \\ @struct_spec)
def decode_xdr!(bytes, struct) do
{%XDR.Struct{components: [hash: hash, body_type: body_type]}, rest} =
XDR.Struct.decode_xdr!(bytes, struct)
{new(hash, body_type), rest}
end
end