ExPlasma.Output.Position (ExPlasma v0.3.0)

Generates an Output position if given the:

blknum - The block number for this output txindex - The index of the Transaction in the block. oindex - The index of the Output in the Transaction.

Link to this section Summary

Functions

Decodes and returns the integer position.

Encodes the output position into an RLP encodable object.

Creates an output_id from a block number, a tx index and an output index.

Encodes the blknum, txindex, and oindex into a single integer.

Returns a map of the decoded position.

Transforms the output position into a positive integer representing the position.

Validates that values can give a valid position.

Link to this section Types

Specs

position() :: pos_integer()

Specs

t() :: %{
  blknum: non_neg_integer(),
  txindex: non_neg_integer(),
  oindex: non_neg_integer()
}
Link to this type

validation_responses()

Specs

Link to this type

with_position()

Specs

with_position() :: %{
  position: position(),
  blknum: non_neg_integer(),
  txindex: non_neg_integer(),
  oindex: non_neg_integer()
}

Link to this section Functions

Link to this function

decode(encoded_pos)

Specs

decode(binary()) :: {:ok, position()} | {:error, :malformed_input_position_rlp}

Decodes and returns the integer position.

Example

iex> pos = <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 154, 202, 0>>
iex> ExPlasma.Output.Position.decode(pos)
{:ok, 1_000_000_000}
Link to this function

encode(position)

Specs

encode(position()) :: binary()

Encodes the output position into an RLP encodable object.

Example

iex> pos = ExPlasma.Output.Position.pos(%{blknum: 1, txindex: 0, oindex: 0})
iex> ExPlasma.Output.Position.encode(pos)
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 154, 202, 0>>
Link to this function

new(blknum, txindex, oindex)

Specs

Creates an output_id from a block number, a tx index and an output index.

Example

iex> ExPlasma.Output.Position.new(1, 0, 0)
%{blknum: 1, txindex: 0, oindex: 0, position: 1_000_000_000}

Specs

pos(t() | with_position()) :: position()

Encodes the blknum, txindex, and oindex into a single integer.

Example

iex> pos = %{blknum: 1, txindex: 0, oindex: 0}
iex> ExPlasma.Output.Position.pos(pos)
1_000_000_000

Specs

to_map(position()) ::
  {:ok, with_position()} | {:error, :malformed_output_position}

Returns a map of the decoded position.

Example

iex> pos = 1_000_000_000
iex> ExPlasma.Output.Position.to_map(pos)
{:ok, %{position: 1_000_000_000, blknum: 1, txindex: 0, oindex: 0}}
Link to this function

to_rlp(output_id)

Specs

to_rlp(t() | with_position()) :: binary()

Transforms the output position into a positive integer representing the position.

Example

iex> output_id = %{blknum: 1, txindex: 0, oindex: 0}
iex> ExPlasma.Output.Position.to_rlp(output_id)
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 154, 202, 0>>
Link to this function

transaction_offset()

Link to this function

validate(output_id)

Specs

validate(t() | with_position()) :: validation_responses()

Validates that values can give a valid position.

Example

iex> output_id = %{blknum: 1, txindex: 0, oindex: 0}
iex> ExPlasma.Output.Position.validate(output_id)
:ok