lib/xdr/transactions/create_contract_args.ex

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

  @behaviour XDR.Declaration

  alias StellarBase.XDR.{
    ContractID,
    SCContractExecutable
  }

  @struct_spec XDR.Struct.new(
                 contract_id: ContractID,
                 executable: SCContractExecutable
               )

  @type contract_id_type :: ContractID.t()
  @type executable_type :: SCContractExecutable.t()

  @type t :: %__MODULE__{contract_id: contract_id_type(), executable: executable_type()}

  defstruct [:contract_id, :executable]

  @spec new(contract_id :: contract_id_type(), executable :: executable_type()) :: t()
  def new(
        %ContractID{} = contract_id,
        %SCContractExecutable{} = executable
      ),
      do: %__MODULE__{contract_id: contract_id, executable: executable}

  @impl true
  def encode_xdr(%__MODULE__{contract_id: contract_id, executable: executable}) do
    [contract_id: contract_id, executable: executable]
    |> XDR.Struct.new()
    |> XDR.Struct.encode_xdr()
  end

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

      error ->
        error
    end
  end

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

  def decode_xdr!(bytes, struct) do
    {%XDR.Struct{components: [contract_id: contract_id, executable: executable]}, rest} =
      XDR.Struct.decode_xdr!(bytes, struct)

    {new(contract_id, executable), rest}
  end
end