Skip to content

Commit

Permalink
Add enums
Browse files Browse the repository at this point in the history
Co-authored-by: norn <keliumJU@users.noreply.github.com>
  • Loading branch information
juanmagiraldor and keliumJU committed Mar 15, 2023
1 parent 16b1ad1 commit 11ef347
Show file tree
Hide file tree
Showing 25 changed files with 1,302 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ stellar_sdk-*.tar

# DS_Store
.DS_Store

.elixir_ls
56 changes: 56 additions & 0 deletions lib/xdr/contract/sc_host_auth_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
defmodule StellarBase.XDR.SCHostAuthErrorCode do
@moduledoc """
Representation of Stellar `SCHostAuthErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_AUTH_UNKNOWN_ERROR: 0,
HOST_AUTH_NONCE_ERROR: 1,
HOST_AUTH_DUPLICATE_AUTHORIZATION: 2,
HOST_AUTH_NOT_AUTHORIZED: 3
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_AUTH_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
54 changes: 54 additions & 0 deletions lib/xdr/contract/sc_host_context_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule StellarBase.XDR.SCHostContextErrorCode do
@moduledoc """
Representation of Stellar `SCHostContextErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_CONTEXT_UNKNOWN_ERROR: 0,
HOST_CONTEXT_NO_CONTRACT_RUNNING: 1
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_CONTEXT_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
57 changes: 57 additions & 0 deletions lib/xdr/contract/sc_host_fn_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
defmodule StellarBase.XDR.SCHostFnErrorCode do
@moduledoc """
Representation of Stellar `SCHostFnErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_FN_UNKNOWN_ERROR: 0,
HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION: 1,
HOST_FN_INPUT_ARGS_WRONG_LENGTH: 2,
HOST_FN_INPUT_ARGS_WRONG_TYPE: 3,
HOST_FN_INPUT_ARGS_INVALID: 4
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_FN_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
59 changes: 59 additions & 0 deletions lib/xdr/contract/sc_host_obj_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
defmodule StellarBase.XDR.SCHostObjErrorCode do
@moduledoc """
Representation of Stellar `SCHostObjErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_OBJECT_UNKNOWN_ERROR: 0,
HOST_OBJECT_UNKNOWN_REFERENCE: 1,
HOST_OBJECT_UNEXPECTED_TYPE: 2,
HOST_OBJECT_OBJECT_COUNT_EXCEEDS_U32_MAX: 3,
HOST_OBJECT_OBJECT_NOT_EXIST: 4,
HOST_OBJECT_VEC_INDEX_OUT_OF_BOUND: 5,
HOST_OBJECT_CONTRACT_HASH_WRONG_LENGTH: 6
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_OBJECT_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
58 changes: 58 additions & 0 deletions lib/xdr/contract/sc_host_storage_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
defmodule StellarBase.XDR.SCHostStorageErrorCode do
@moduledoc """
Representation of Stellar `SCHostStorageErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_STORAGE_UNKNOWN_ERROR: 0,
HOST_STORAGE_EXPECT_CONTRACT_DATA: 1,
HOST_STORAGE_READWRITE_ACCESS_TO_READONLY_ENTRY: 2,
HOST_STORAGE_ACCESS_TO_UNKNOWN_ENTRY: 3,
HOST_STORAGE_MISSING_KEY_IN_GET: 4,
HOST_STORAGE_GET_ON_DELETED_KEY: 5
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_STORAGE_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
64 changes: 64 additions & 0 deletions lib/xdr/contract/sc_host_val_error_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
defmodule StellarBase.XDR.SCHostValErrorCode do
@moduledoc """
Representation of Stellar `SCHostValErrorCode` type.
"""

@behaviour XDR.Declaration

@declarations [
HOST_VALUE_UNKNOWN_ERROR: 0,
HOST_VALUE_RESERVED_TAG_VALUE: 1,
HOST_VALUE_UNEXPECTED_VAL_TYPE: 2,
HOST_VALUE_U63_OUT_OF_RANGE: 3,
HOST_VALUE_U32_OUT_OF_RANGE: 4,
HOST_VALUE_STATIC_UNKNOWN: 5,
HOST_VALUE_MISSING_OBJECT: 6,
HOST_VALUE_SYMBOL_TOO_LONG: 7,
HOST_VALUE_SYMBOL_BAD_CHAR: 8,
HOST_VALUE_SYMBOL_CONTAINS_NON_UTF8: 9,
HOST_VALUE_BITSET_TOO_MANY_BITS: 10,
HOST_VALUE_STATUS_UNKNOWN: 11
]

@enum_spec %XDR.Enum{declarations: @declarations, identifier: nil}

@type t :: %__MODULE__{identifier: atom()}

defstruct [:identifier]

@spec new(type :: atom()) :: t()
def new(type \\ :HOST_VALUE_UNKNOWN_ERROR),
do: %__MODULE__{identifier: type}

@impl true
def encode_xdr(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr()
end

@impl true
def encode_xdr!(%__MODULE__{identifier: type}) do
@declarations
|> XDR.Enum.new(type)
|> XDR.Enum.encode_xdr!()
end

@impl true
def decode_xdr(bytes, spec \\ @enum_spec)

def decode_xdr(bytes, spec) do
case XDR.Enum.decode_xdr(bytes, spec) do
{:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}}
error -> error
end
end

@impl true
def decode_xdr!(bytes, spec \\ @enum_spec)

def decode_xdr!(bytes, spec) do
{%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec)
{new(type), rest}
end
end
Loading

0 comments on commit 11ef347

Please sign in to comment.