ethereum.muir_glacier.transactionsethereum.berlin.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
22 | TX_BASE_COST = 21000 |
---|
TX_DATA_COST_PER_NON_ZERO
23 | TX_DATA_COST_PER_NON_ZERO = 16 |
---|
TX_DATA_COST_PER_ZERO
24 | TX_DATA_COST_PER_ZERO = 4 |
---|
TX_CREATE_COST
25 | TX_CREATE_COST = 32000 |
---|
TX_ACCESS_LIST_ADDRESS_COST
26 | TX_ACCESS_LIST_ADDRESS_COST = 2400 |
---|
TX_ACCESS_LIST_STORAGE_KEY_COST
27 | TX_ACCESS_LIST_STORAGE_KEY_COST = 1900 |
---|
LegacyTransaction
Atomic operation performed on the block chain.
30 | @slotted_freezable |
---|
31 | @dataclass |
---|
class LegacyTransaction:
nonce
37 | nonce: U256 |
---|
gas_price
38 | gas_price: Uint |
---|
gas
39 | gas: Uint |
---|
to
40 | to: Union[Bytes0, Address] |
---|
value
41 | value: U256 |
---|
data
42 | data: Bytes |
---|
v
43 | v: U256 |
---|
r
44 | r: U256 |
---|
s
45 | s: U256 |
---|
AccessListTransaction
The transaction type added in EIP-2930 to support access lists.
48 | @slotted_freezable |
---|
49 | @dataclass |
---|
class AccessListTransaction:
chain_id
55 | chain_id: U64 |
---|
nonce
56 | nonce: U256 |
---|
gas_price
57 | gas_price: Uint |
---|
gas
58 | gas: Uint |
---|
to
59 | to: Union[Bytes0, Address] |
---|
value
60 | value: U256 |
---|
data
61 | data: Bytes |
---|
access_list
62 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
y_parity
63 | y_parity: U256 |
---|
r
64 | r: U256 |
---|
s
65 | s: U256 |
---|
Transaction
Atomic operation performed on the block chain.
18 | @slotted_freezable |
---|
19 | @dataclass |
---|
class Transaction:
nonce
25 | nonce: U256 |
---|
gas_price
26 | gas_price: Uint |
---|
gas
27 | gas: Uint |
---|
to
28 | to: Union[Bytes0, Address] |
---|
value
29 | value: U256 |
---|
data
30 | data: Bytes |
---|
v
31 | v: U256 |
---|
r
32 | r: U256 |
---|
s
33 | s: U256 |
---|
Transaction
68 | Transaction = Union[LegacyTransaction, AccessListTransaction] |
---|
encode_transaction
Encode a transaction. Needed because non-legacy transactions aren't RLP.
def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
72 | """ |
---|---|
73 | Encode a transaction. Needed because non-legacy transactions aren't RLP. |
74 | """ |
75 | if isinstance(tx, LegacyTransaction): |
76 | return tx |
77 | elif isinstance(tx, AccessListTransaction): |
78 | return b"\x01" + rlp.encode(tx) |
79 | else: |
80 | 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:
84 | """ |
---|---|
85 | Decode a transaction. Needed because non-legacy transactions aren't RLP. |
86 | """ |
87 | if isinstance(tx, Bytes): |
88 | if tx[0] != 1: |
89 | raise InvalidBlock |
90 | return rlp.decode_to(AccessListTransaction, tx[1:]) |
91 | else: |
92 | return tx |