-
Notifications
You must be signed in to change notification settings - Fork 220
/
fork_types.py
67 lines (52 loc) · 1.13 KB
/
fork_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Ethereum Types
^^^^^^^^^^^^^^
.. contents:: Table of Contents
:backlinks: none
:local:
Introduction
------------
Types re-used throughout the specification, which are specific to Ethereum.
"""
from dataclasses import dataclass
from .. import rlp
from ..base_types import (
U256,
Bytes,
Bytes20,
Bytes256,
Uint,
slotted_freezable,
)
from ..crypto.hash import Hash32, keccak256
Address = Bytes20
Root = Hash32
Bloom = Bytes256
@slotted_freezable
@dataclass
class Account:
"""
State associated with an address.
"""
nonce: Uint
balance: U256
code: bytes
EMPTY_ACCOUNT = Account(
nonce=Uint(0),
balance=U256(0),
code=bytearray(),
)
def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes:
"""
Encode `Account` dataclass.
Storage is not stored in the `Account` dataclass, so `Accounts` cannot be
encoded with providing a storage root.
"""
return rlp.encode(
(
raw_account_data.nonce,
raw_account_data.balance,
storage_root,
keccak256(raw_account_data.code),
)
)