ExPlasma.Output.Position (ExPlasma v0.2.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
position()
Specs
position() :: pos_integer()
Specs
t() :: %{ blknum: non_neg_integer(), txindex: non_neg_integer(), oindex: non_neg_integer() }
validation_responses()
Specs
validation_responses() :: :ok | {:error, ExPlasma.Output.Position.Validator.blknum_validation_errors() | ExPlasma.Output.Position.Validator.oindex_validation_errors() | ExPlasma.Output.Position.Validator.txindex_validation_errors()}
with_position()
Specs
with_position() :: %{ position: position(), blknum: non_neg_integer(), txindex: non_neg_integer(), oindex: non_neg_integer() }
Link to this section Functions
block_offset()
decode(encoded_pos)
Specs
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}
encode(position)
Specs
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>>
new(blknum, txindex, oindex)
Specs
new(non_neg_integer(), non_neg_integer(), non_neg_integer()) :: with_position()
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}
pos(map)
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
to_map(pos)
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}}
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>>
transaction_offset()
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