lib/xdr/transactions/soroban_address_credentials.ex

defmodule StellarBase.XDR.SorobanAddressCredentials 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 `SorobanAddressCredentials` type.
  """

  @behaviour XDR.Declaration

  alias StellarBase.XDR.{
    SCAddress,
    Int64,
    UInt32,
    SCVal
  }

  @struct_spec XDR.Struct.new(
                 address: SCAddress,
                 nonce: Int64,
                 signature_expiration_ledger: UInt32,
                 signature: SCVal
               )

  @type address_type :: SCAddress.t()
  @type nonce_type :: Int64.t()
  @type signature_expiration_ledger_type :: UInt32.t()
  @type signature_type :: SCVal.t()

  @type t :: %__MODULE__{
          address: address_type(),
          nonce: nonce_type(),
          signature_expiration_ledger: signature_expiration_ledger_type(),
          signature: signature_type()
        }

  defstruct [:address, :nonce, :signature_expiration_ledger, :signature]

  @spec new(
          address :: address_type(),
          nonce :: nonce_type(),
          signature_expiration_ledger :: signature_expiration_ledger_type(),
          signature :: signature_type()
        ) :: t()
  def new(
        %SCAddress{} = address,
        %Int64{} = nonce,
        %UInt32{} = signature_expiration_ledger,
        %SCVal{} = signature
      ),
      do: %__MODULE__{
        address: address,
        nonce: nonce,
        signature_expiration_ledger: signature_expiration_ledger,
        signature: signature
      }

  @impl true
  def encode_xdr(%__MODULE__{
        address: address,
        nonce: nonce,
        signature_expiration_ledger: signature_expiration_ledger,
        signature: signature
      }) do
    [
      address: address,
      nonce: nonce,
      signature_expiration_ledger: signature_expiration_ledger,
      signature: signature
    ]
    |> XDR.Struct.new()
    |> XDR.Struct.encode_xdr()
  end

  @impl true
  def encode_xdr!(%__MODULE__{
        address: address,
        nonce: nonce,
        signature_expiration_ledger: signature_expiration_ledger,
        signature: signature
      }) do
    [
      address: address,
      nonce: nonce,
      signature_expiration_ledger: signature_expiration_ledger,
      signature: signature
    ]
    |> 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: [
            address: address,
            nonce: nonce,
            signature_expiration_ledger: signature_expiration_ledger,
            signature: signature
          ]
        }, rest}} ->
        {:ok, {new(address, nonce, signature_expiration_ledger, signature), rest}}

      error ->
        error
    end
  end

  @impl true
  def decode_xdr!(bytes, struct \\ @struct_spec)

  def decode_xdr!(bytes, struct) do
    {%XDR.Struct{
       components: [
         address: address,
         nonce: nonce,
         signature_expiration_ledger: signature_expiration_ledger,
         signature: signature
       ]
     }, rest} = XDR.Struct.decode_xdr!(bytes, struct)

    {new(address, nonce, signature_expiration_ledger, signature), rest}
  end
end