lib/xdr/ledger_entries/contract_event_v0.ex

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

  @behaviour XDR.Declaration

  alias StellarBase.XDR.{
    SCValList,
    SCVal
  }

  @struct_spec XDR.Struct.new(
                 topics: SCValList,
                 data: SCVal
               )

  @type topics_type :: SCValList.t()
  @type data_type :: SCVal.t()

  @type t :: %__MODULE__{topics: topics_type(), data: data_type()}

  defstruct [:topics, :data]

  @spec new(topics :: topics_type(), data :: data_type()) :: t()
  def new(
        %SCValList{} = topics,
        %SCVal{} = data
      ),
      do: %__MODULE__{topics: topics, data: data}

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

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

      error ->
        error
    end
  end

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

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

    {new(topics, data), rest}
  end
end