View Source Xander.Transaction.Response (Xander v0.2.0)

Parses the response from a transaction. Accepts CBOR encoded responses.

Summary

Functions

Parses the response from a transaction. Accepts CBOR encoded responses.

Types

error_reason()

@type error_reason() ::
  :cannot_decode_non_binary_values
  | :cbor_function_clause_error
  | :cbor_match_error
  | :invalid_format
  | :invalid_input
  | :disconnected

t()

@type t() :: {:ok, :accepted} | {:rejected, any()} | {:error, error_reason()}

Functions

parse_response(cbor_response)

@spec parse_response(binary() | nil) :: t()

Parses the response from a transaction. Accepts CBOR encoded responses.

Examples

# Transaction accepted
iex> binary = Xander.Util.plex_encode(CBOR.encode([1]))
iex> Xander.Transaction.Response.parse_response(binary)
{:ok, :accepted}

# Transaction rejected with reason
iex> tag = %CBOR.Tag{tag: :bytes, value: "invalid tx"}
iex> binary = Xander.Util.plex_encode(CBOR.encode([2, tag]))
iex> Xander.Transaction.Response.parse_response(binary)
{:rejected, %CBOR.Tag{tag: :bytes, value: "invalid tx"}}

# Disconnected from node
iex> binary = Xander.Util.plex_encode(CBOR.encode([3]))
iex> Xander.Transaction.Response.parse_response(binary)
{:error, :disconnected}

# Error handling invalid CBOR
iex> Xander.Transaction.Response.parse_response(<<0, 1, 2, 3>>)
{:error, :invalid_format}

# Error handling nil input
iex> Xander.Transaction.Response.parse_response(nil)
{:error, :invalid_input}