Cartouche.Transaction.V_2930 (Cartouche v0.8.0)

Copy Markdown View Source

Represents a type-1 EIP-2930 access-list transaction.

Examples

iex> tx =
...>   Cartouche.Transaction.V_2930.new(
...>     1,
...>     {1, :gwei},
...>     100_000,
...>     <<1::160>>,
...>     {2, :wei},
...>     <<1, 2, 3>>,
...>     [],
...>     :goerli
...>   )
...> tx = Cartouche.Transaction.V_2930.add_signature(tx, true, <<0x01::256>>, <<0x02::256>>)
iex> {:ok, decoded} = tx |> Cartouche.Transaction.V_2930.encode() |> Cartouche.Transaction.V_2930.decode()
iex> decoded == tx
true

Summary

Functions

Adds a signature to a transaction from a packed binary (r <> s <> v).

Adds explicit signature fields to a transaction.

Decodes an EIP-2930 typed RLP transaction.

Build an EIP-2718 typed RLP-encoded access-list transaction.

Decodes an EIP-2930 (type 1) transaction object from block JSON-RPC.

Recovers a signature from a transaction, if it has been signed.

Hashes the typed transaction bytes.

Recovers the signer from a signed type-1 transaction.

Signs a type-1 transaction with the given signer process.

Types

access_list()

@type access_list() :: [{<<_::160>>, [<<_::256>>]}]

t()

@type t() :: %Cartouche.Transaction.V_2930{
  access_list: access_list(),
  amount: non_neg_integer(),
  chain_id: non_neg_integer(),
  data: binary(),
  destination: <<_::160>> | nil,
  gas_limit: non_neg_integer(),
  gas_price: non_neg_integer(),
  nonce: non_neg_integer(),
  signature_r: <<_::256>> | nil,
  signature_s: <<_::256>> | nil,
  signature_y_parity: boolean() | nil
}

Functions

add_signature(transaction, signature)

@spec add_signature(t(), <<_::512, _::_*8>>) :: t()

Adds a signature to a transaction from a packed binary (r <> s <> v).

add_signature(transaction, v, r, s)

@spec add_signature(t(), boolean(), <<_::256>>, <<_::256>>) :: t()

Adds explicit signature fields to a transaction.

decode(input)

@spec decode(binary()) :: {:ok, t()} | {:error, String.t()}

Decodes an EIP-2930 typed RLP transaction.

encode(transaction)

@spec encode(t()) :: binary()

Build an EIP-2718 typed RLP-encoded access-list transaction.

Signed payloads are 0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, yParity, r, s]) per EIP-2930. If any signature field is nil, the encoded payload omits yParity, r, and s and is the signing preimage 0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList]).

from_json(params)

@spec from_json(map()) :: t() | no_return()

Decodes an EIP-2930 (type 1) transaction object from block JSON-RPC.

get_signature(transaction)

@spec get_signature(t()) :: {:ok, binary()} | {:error, String.t()}

Recovers a signature from a transaction, if it has been signed.

hash(transaction)

@spec hash(t()) :: <<_::256>>

Hashes the typed transaction bytes.

new(nonce, gas_price, gas_limit, destination, amount, data, access_list, chain_id \\ nil)

@spec new(
  non_neg_integer(),
  non_neg_integer() | {non_neg_integer(), :wei | :gwei},
  non_neg_integer(),
  <<_::160>>,
  non_neg_integer() | {non_neg_integer(), :wei | :gwei},
  binary(),
  access_list(),
  atom() | integer() | nil
) :: t()

Constructs an unsigned EIP-2930 access-list transaction.

recover_signer(transaction)

@spec recover_signer(t()) :: {:ok, <<_::160>>} | {:error, String.t()}

Recovers the signer from a signed type-1 transaction.

sign(transaction, signer \\ Default)

@spec sign(t(), GenServer.server()) :: {:ok, t()} | {:error, String.t()}

Signs a type-1 transaction with the given signer process.