ExPlasma (ExPlasma v0.2.0)
Documentation for ExPlasma.
Link to this section Summary
Functions
Attempt to decode the given RLP list into a Transaction.
Encode the given Transaction into an RLP encodable list.
Throwing version of encode/2
Transaction fee claim V1
Keccak hash the Transaction. This is used in the contracts and events to to reference transactions.
Simple payment type V1
Transaction types
Statelessly validate a transation.
Link to this section Types
transaction_type()
Specs
transaction_type() :: non_neg_integer()
Link to this section Functions
decode(tx_bytes, opts \\ [])
Attempt to decode the given RLP list into a Transaction.
If signed: false
is given in the list of opts, expects the underlying RLP to not contain signatures.
Only validates that the RLP is structurally correct and that the tx type is supported. Does not perform any other kind of validation, use validate/1 for that.
Example
iex> rlp = <<248, 116, 1, 225, 160, 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, 0, 0, 0, 0, 238, 237, 1, 235, 148,
...> 29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241,
...> 55, 0, 110, 148, 46, 38, 45, 41, 28, 46, 150, 159, 176, 132, 157, 153, 217,
...> 206, 65, 226, 241, 55, 0, 110, 1, 128, 160, 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, 0, 0, 0, 0>>
iex> ExPlasma.decode(rlp, signed: false)
{:ok,
%ExPlasma.Transaction{
inputs: [
%ExPlasma.Output{
output_data: nil,
output_id: %{blknum: 0, oindex: 0, position: 0, txindex: 0},
output_type: nil
}
],
metadata: <<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, 0, 0, 0, 0>>,
outputs: [
%ExPlasma.Output{
output_data: %{
amount: 1,
output_guard: <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153,
217, 206, 65, 226, 241, 55, 0, 110>>,
token: <<46, 38, 45, 41, 28, 46, 150, 159, 176, 132, 157, 153, 217, 206,
65, 226, 241, 55, 0, 110>>
},
output_id: nil,
output_type: 1
}
],
witnesses: [],
sigs: [],
tx_data: 0,
tx_type: 1
}
}
encode(transaction, opts \\ [])
Encode the given Transaction into an RLP encodable list.
If signed: false
is given in the list of opts, will encode the transaction without its signatures.
Example
iex> txn =
...> %ExPlasma.Transaction{
...> inputs: [
...> %ExPlasma.Output{
...> output_data: nil,
...> output_id: %{blknum: 0, oindex: 0, position: 0, txindex: 0},
...> output_type: nil
...> }
...> ],
...> metadata: <<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, 0, 0, 0, 0>>,
...> outputs: [
...> %ExPlasma.Output{
...> output_data: %{
...> amount: 1,
...> output_guard: <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153,
...> 217, 206, 65, 226, 241, 55, 0, 110>>,
...> token: <<46, 38, 45, 41, 28, 46, 150, 159, 176, 132, 157, 153, 217, 206,
...> 65, 226, 241, 55, 0, 110>>
...> },
...> output_id: nil,
...> output_type: 1
...> }
...> ],
...> sigs: [],
...> tx_data: 0,
...> tx_type: 1
...> }
iex> ExPlasma.encode(txn, signed: false)
{:ok, <<248, 116, 1, 225, 160, 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, 0, 0, 0, 0, 238, 237, 1, 235, 148, 29, 246, 47,
41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241, 55, 0, 110,
148, 46, 38, 45, 41, 28, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226,
241, 55, 0, 110, 1, 128, 160, 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, 0, 0, 0, 0>>}
encode!(transaction, opts \\ [])
Throwing version of encode/2
fee()
Specs
fee() :: 3
Transaction fee claim V1
Example
iex> ExPlasma.fee()
3
hash(transaction)
Keccak hash the Transaction. This is used in the contracts and events to to reference transactions.
Example
iex> rlp = <<248, 74, 192, 1, 193, 128, 239, 174, 237, 1, 235, 148, 29, 246, 47, 41, 27,
...> 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241, 55, 0, 110, 148, 46,
...> 38, 45, 41, 28, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241, 55,
...> 0, 110, 1, 128, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...> 0>>
iex> ExPlasma.hash(rlp)
{:ok, <<87, 132, 239, 36, 144, 239, 129, 88, 63, 88, 116, 147, 164, 200, 113, 191,
124, 14, 55, 131, 119, 96, 112, 13, 28, 178, 251, 49, 16, 127, 58, 96>>}
payment_v1()
Specs
payment_v1() :: 1
Simple payment type V1
Example
iex> ExPlasma.payment_v1()
1
transaction_types()
Specs
transaction_types() :: [1 | 3, ...]
Transaction types
Example
iex> ExPlasma.transaction_types()
[1, 3]
validate(transaction)
Statelessly validate a transation.
Returns :ok if valid or {:error, {atom, atom}} otherwise