ethereum.byzantium.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
 40TX_CREATE_COST = 32000
 41
 42
 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
 59
 60
 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
 71
 72
 73EMPTY_ACCOUNT = Account(
 74    nonce=Uint(0),
 75    balance=U256(0),
 76    code=bytearray(),
 77)
 78
 79
 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    )
 95
 96
 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
119
120
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, ...]
131
132
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
143
144
145@slotted_freezable
146@dataclass
147class Receipt:
148    """
149    Result of a transaction.
150    """
151
152    succeeded: bool
153    cumulative_gas_used: Uint
154    bloom: Bloom
155    logs: Tuple[Log, ...]
@slotted_freezable
@dataclass
class Transaction:
44@slotted_freezable
45@dataclass
46class Transaction:
47    """
48    Atomic operation performed on the block chain.
49    """
50
51    nonce: U256
52    gas_price: Uint
53    gas: Uint
54    to: Union[Bytes0, Address]
55    value: U256
56    data: Bytes
57    v: U256
58    r: U256
59    s: U256

Atomic operation performed on the block chain.

@slotted_freezable
@dataclass
class Account:
62@slotted_freezable
63@dataclass
64class Account:
65    """
66    State associated with an address.
67    """
68
69    nonce: Uint
70    balance: U256
71    code: bytes

State associated with an address.

def encode_account( raw_account_data: Account, storage_root: bytes) -> bytes:
81def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes:
82    """
83    Encode `Account` dataclass.
84
85    Storage is not stored in the `Account` dataclass, so `Accounts` cannot be
86    encoded with providing a storage root.
87    """
88    return rlp.encode(
89        (
90            raw_account_data.nonce,
91            raw_account_data.balance,
92            storage_root,
93            keccak256(raw_account_data.code),
94        )
95    )

Encode Account dataclass.

Storage is not stored in the Account dataclass, so Accounts cannot be encoded with providing a storage root.

@slotted_freezable
@dataclass
class Block:
122@slotted_freezable
123@dataclass
124class Block:
125    """
126    A complete block.
127    """
128
129    header: Header
130    transactions: Tuple[Transaction, ...]
131    ommers: Tuple[Header, ...]

A complete block.

@slotted_freezable
@dataclass
class Log:
134@slotted_freezable
135@dataclass
136class Log:
137    """
138    Data record produced during the execution of a transaction.
139    """
140
141    address: Address
142    topics: Tuple[Hash32, ...]
143    data: bytes

Data record produced during the execution of a transaction.

@slotted_freezable
@dataclass
class Receipt:
146@slotted_freezable
147@dataclass
148class Receipt:
149    """
150    Result of a transaction.
151    """
152
153    succeeded: bool
154    cumulative_gas_used: Uint
155    bloom: Bloom
156    logs: Tuple[Log, ...]

Result of a transaction.