ethereum.gray_glacier.transactions
Transactions are atomic units of work created externally to Ethereum and submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states.
TX_BASE_COST
17 | TX_BASE_COST = 21000 |
---|
TX_DATA_COST_PER_NON_ZERO
18 | TX_DATA_COST_PER_NON_ZERO = 16 |
---|
TX_DATA_COST_PER_ZERO
19 | TX_DATA_COST_PER_ZERO = 4 |
---|
TX_CREATE_COST
20 | TX_CREATE_COST = 32000 |
---|
TX_ACCESS_LIST_ADDRESS_COST
21 | TX_ACCESS_LIST_ADDRESS_COST = 2400 |
---|
TX_ACCESS_LIST_STORAGE_KEY_COST
22 | TX_ACCESS_LIST_STORAGE_KEY_COST = 1900 |
---|
LegacyTransaction
Atomic operation performed on the block chain.
25 | @slotted_freezable |
---|
26 | @dataclass |
---|
class LegacyTransaction:
nonce
32 | nonce: U256 |
---|
gas_price
33 | gas_price: Uint |
---|
gas
34 | gas: Uint |
---|
to
35 | to: Union[Bytes0, Address] |
---|
value
36 | value: U256 |
---|
data
37 | data: Bytes |
---|
v
38 | v: U256 |
---|
r
39 | r: U256 |
---|
s
40 | s: U256 |
---|
AccessListTransaction
The transaction type added in EIP-2930 to support access lists.
43 | @slotted_freezable |
---|
44 | @dataclass |
---|
class AccessListTransaction:
chain_id
50 | chain_id: U64 |
---|
nonce
51 | nonce: U256 |
---|
gas_price
52 | gas_price: Uint |
---|
gas
53 | gas: Uint |
---|
to
54 | to: Union[Bytes0, Address] |
---|
value
55 | value: U256 |
---|
data
56 | data: Bytes |
---|
access_list
57 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
y_parity
58 | y_parity: U256 |
---|
r
59 | r: U256 |
---|
s
60 | s: U256 |
---|
FeeMarketTransaction
The transaction type added in EIP-1559.
63 | @slotted_freezable |
---|
64 | @dataclass |
---|
class FeeMarketTransaction:
chain_id
70 | chain_id: U64 |
---|
nonce
71 | nonce: U256 |
---|
max_priority_fee_per_gas
72 | max_priority_fee_per_gas: Uint |
---|
max_fee_per_gas
73 | max_fee_per_gas: Uint |
---|
gas
74 | gas: Uint |
---|
to
75 | to: Union[Bytes0, Address] |
---|
value
76 | value: U256 |
---|
data
77 | data: Bytes |
---|
access_list
78 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
y_parity
79 | y_parity: U256 |
---|
r
80 | r: U256 |
---|
s
81 | s: U256 |
---|
Transaction
84 | Transaction = Union[ |
---|---|
85 | LegacyTransaction, AccessListTransaction, FeeMarketTransaction |
86 | ] |
encode_transaction
Encode a transaction. Needed because non-legacy transactions aren't RLP.
def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
90 | """ |
---|---|
91 | Encode a transaction. Needed because non-legacy transactions aren't RLP. |
92 | """ |
93 | if isinstance(tx, LegacyTransaction): |
94 | return tx |
95 | elif isinstance(tx, AccessListTransaction): |
96 | return b"\x01" + rlp.encode(tx) |
97 | elif isinstance(tx, FeeMarketTransaction): |
98 | return b"\x02" + rlp.encode(tx) |
99 | else: |
100 | raise Exception(f"Unable to encode transaction of type {type(tx)}") |
decode_transaction
Decode a transaction. Needed because non-legacy transactions aren't RLP.
def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
104 | """ |
---|---|
105 | Decode a transaction. Needed because non-legacy transactions aren't RLP. |
106 | """ |
107 | if isinstance(tx, Bytes): |
108 | if tx[0] == 1: |
109 | return rlp.decode_to(AccessListTransaction, tx[1:]) |
110 | elif tx[0] == 2: |
111 | return rlp.decode_to(FeeMarketTransaction, tx[1:]) |
112 | else: |
113 | raise TransactionTypeError(tx[0]) |
114 | else: |
115 | return tx |