ethereum.frontier.fork_types
Ethereum Types ^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Types re-used throughout the specification, which are specific to Ethereum.
1""" 2Ethereum Types 3^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12Types re-used throughout the specification, which are specific to Ethereum. 13""" 14 15from dataclasses import dataclass 16from typing import Tuple, Union 17 18from .. import rlp 19from ..base_types import ( 20 U256, 21 Bytes, 22 Bytes0, 23 Bytes8, 24 Bytes20, 25 Bytes32, 26 Bytes256, 27 Uint, 28 slotted_freezable, 29) 30from ..crypto.hash import Hash32, keccak256 31 32Address = Bytes20 33Root = Hash32 34 35Bloom = Bytes256 36 37TX_BASE_COST = 21000 38TX_DATA_COST_PER_NON_ZERO = 68 39TX_DATA_COST_PER_ZERO = 4 40 41 42@slotted_freezable 43@dataclass 44class Transaction: 45 """ 46 Atomic operation performed on the block chain. 47 """ 48 49 nonce: U256 50 gas_price: Uint 51 gas: Uint 52 to: Union[Bytes0, Address] 53 value: U256 54 data: Bytes 55 v: U256 56 r: U256 57 s: U256 58 59 60@slotted_freezable 61@dataclass 62class Account: 63 """ 64 State associated with an address. 65 """ 66 67 nonce: Uint 68 balance: U256 69 code: bytes 70 71 72EMPTY_ACCOUNT = Account( 73 nonce=Uint(0), 74 balance=U256(0), 75 code=bytearray(), 76) 77 78 79def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes: 80 """ 81 Encode `Account` dataclass. 82 83 Storage is not stored in the `Account` dataclass, so `Accounts` cannot be 84 encoded with providing a storage root. 85 """ 86 return rlp.encode( 87 ( 88 raw_account_data.nonce, 89 raw_account_data.balance, 90 storage_root, 91 keccak256(raw_account_data.code), 92 ) 93 ) 94 95 96@slotted_freezable 97@dataclass 98class Header: 99 """ 100 Header portion of a block on the chain. 101 """ 102 103 parent_hash: Hash32 104 ommers_hash: Hash32 105 coinbase: Address 106 state_root: Root 107 transactions_root: Root 108 receipt_root: Root 109 bloom: Bloom 110 difficulty: Uint 111 number: Uint 112 gas_limit: Uint 113 gas_used: Uint 114 timestamp: U256 115 extra_data: Bytes 116 mix_digest: Bytes32 117 nonce: Bytes8 118 119 120@slotted_freezable 121@dataclass 122class Block: 123 """ 124 A complete block. 125 """ 126 127 header: Header 128 transactions: Tuple[Transaction, ...] 129 ommers: Tuple[Header, ...] 130 131 132@slotted_freezable 133@dataclass 134class Log: 135 """ 136 Data record produced during the execution of a transaction. 137 """ 138 139 address: Address 140 topics: Tuple[Hash32, ...] 141 data: bytes 142 143 144@slotted_freezable 145@dataclass 146class Receipt: 147 """ 148 Result of a transaction. 149 """ 150 151 post_state: Root 152 cumulative_gas_used: Uint 153 bloom: Bloom 154 logs: Tuple[Log, ...]
@slotted_freezable
@dataclass
class
Transaction:
43@slotted_freezable 44@dataclass 45class Transaction: 46 """ 47 Atomic operation performed on the block chain. 48 """ 49 50 nonce: U256 51 gas_price: Uint 52 gas: Uint 53 to: Union[Bytes0, Address] 54 value: U256 55 data: Bytes 56 v: U256 57 r: U256 58 s: U256
Atomic operation performed on the block chain.
@slotted_freezable
@dataclass
class
Account:
61@slotted_freezable 62@dataclass 63class Account: 64 """ 65 State associated with an address. 66 """ 67 68 nonce: Uint 69 balance: U256 70 code: bytes
State associated with an address.
80def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes: 81 """ 82 Encode `Account` dataclass. 83 84 Storage is not stored in the `Account` dataclass, so `Accounts` cannot be 85 encoded with providing a storage root. 86 """ 87 return rlp.encode( 88 ( 89 raw_account_data.nonce, 90 raw_account_data.balance, 91 storage_root, 92 keccak256(raw_account_data.code), 93 ) 94 )
@slotted_freezable
@dataclass
class
Header:
97@slotted_freezable 98@dataclass 99class Header: 100 """ 101 Header portion of a block on the chain. 102 """ 103 104 parent_hash: Hash32 105 ommers_hash: Hash32 106 coinbase: Address 107 state_root: Root 108 transactions_root: Root 109 receipt_root: Root 110 bloom: Bloom 111 difficulty: Uint 112 number: Uint 113 gas_limit: Uint 114 gas_used: Uint 115 timestamp: U256 116 extra_data: Bytes 117 mix_digest: Bytes32 118 nonce: Bytes8
Header portion of a block on the chain.
@slotted_freezable
@dataclass
class
Block:
121@slotted_freezable 122@dataclass 123class Block: 124 """ 125 A complete block. 126 """ 127 128 header: Header 129 transactions: Tuple[Transaction, ...] 130 ommers: Tuple[Header, ...]
A complete block.
@slotted_freezable
@dataclass
class
Log:
133@slotted_freezable 134@dataclass 135class Log: 136 """ 137 Data record produced during the execution of a transaction. 138 """ 139 140 address: Address 141 topics: Tuple[Hash32, ...] 142 data: bytes
Data record produced during the execution of a transaction.
@slotted_freezable
@dataclass
class
Receipt:
145@slotted_freezable 146@dataclass 147class Receipt: 148 """ 149 Result of a transaction. 150 """ 151 152 post_state: Root 153 cumulative_gas_used: Uint 154 bloom: Bloom 155 logs: Tuple[Log, ...]
Result of a transaction.