21
21
)
22
22
from eth .utils .blake import blake
23
23
24
- from .attestation_records import AttestationRecord
25
- from .special_records import SpecialRecord
24
+ from .attestations import Attestation
25
+ from .proposer_slashings import ProposerSlashing
26
+ from .casper_slashings import CasperSlashing
27
+ from .deposits import Deposit
28
+ from .exits import Exit
29
+
30
+
31
+ class BeaconBlockBody (rlp .Serializable ):
32
+ fields = [
33
+ ('proposer_slashings' , CountableList (ProposerSlashing )),
34
+ ('casper_slashings' , CountableList (CasperSlashing )),
35
+ ('attestations' , CountableList (Attestation )),
36
+ ('deposits' , CountableList (Deposit )),
37
+ ('exits' , CountableList (Exit )),
38
+ ]
39
+
40
+ def __init__ (self ,
41
+ proposer_slashings : Sequence [int ],
42
+ casper_slashings : Sequence [int ],
43
+ attestations : Sequence [int ],
44
+ deposits : Sequence [int ],
45
+ exits : Sequence [int ])-> None :
46
+ super ().__init__ (
47
+ proposer_slashings = proposer_slashings ,
48
+ casper_slashings = casper_slashings ,
49
+ attestations = attestations ,
50
+ deposits = deposits ,
51
+ exits = exits ,
52
+ )
26
53
27
54
28
55
class BaseBeaconBlock (rlp .Serializable ):
29
56
fields = [
30
- # Slot number
57
+ #
58
+ # Header
59
+ #
31
60
('slot' , uint64 ),
32
- # Proposer RANDAO reveal
33
- ('randao_reveal' , hash32 ),
34
- # Recent PoW receipt root
35
- ('candidate_pow_receipt_root' , hash32 ),
36
61
# Skip list of previous beacon block hashes
37
62
# i'th item is the most recent ancestor whose slot is a multiple of 2**i for i = 0, ..., 31
38
- ('ancestor_hashes' , CountableList (hash32 )),
39
- # State root
63
+ ('parent_root' , hash32 ),
40
64
('state_root' , hash32 ),
41
- # Attestations
42
- ('attestations' , CountableList (AttestationRecord )),
43
- # Specials (e.g. logouts, penalties)
44
- ('specials' , CountableList (SpecialRecord )),
45
- # Proposer signature
46
- ('proposer_signature' , CountableList (uint256 )),
65
+ ('randao_reveal' , hash32 ),
66
+ ('candidate_pow_receipt_root' , hash32 ),
67
+ ('signature' , CountableList (uint256 )),
68
+
69
+ #
70
+ # Body
71
+ #
72
+ ('body' , BeaconBlockBody )
47
73
]
48
74
49
75
def __init__ (self ,
50
76
slot : int ,
77
+ parent_root : Hash32 ,
78
+ state_root : Hash32 ,
51
79
randao_reveal : Hash32 ,
52
80
candidate_pow_receipt_root : Hash32 ,
53
- ancestor_hashes : Sequence [Hash32 ],
54
- state_root : Hash32 ,
55
- attestations : Sequence [AttestationRecord ],
56
- specials : Sequence [SpecialRecord ],
57
- proposer_signature : Sequence [int ]= None ) -> None :
58
- if proposer_signature is None :
59
- proposer_signature = (0 , 0 )
81
+ body : BeaconBlockBody ,
82
+ signature : Sequence [int ]= (0 , 0 )) -> None :
60
83
super ().__init__ (
61
- slot = slot ,
62
- randao_reveal = randao_reveal ,
63
- candidate_pow_receipt_root = candidate_pow_receipt_root ,
64
- ancestor_hashes = ancestor_hashes ,
65
- state_root = state_root ,
66
- attestations = attestations ,
67
- specials = specials ,
68
- proposer_signature = proposer_signature ,
84
+ slot ,
85
+ parent_root ,
86
+ state_root ,
87
+ randao_reveal ,
88
+ candidate_pow_receipt_root ,
89
+ signature ,
90
+ body
69
91
)
70
92
71
93
def __repr__ (self ) -> str :
@@ -84,11 +106,4 @@ def hash(self) -> Hash32:
84
106
85
107
@property
86
108
def num_attestations (self ) -> int :
87
- return len (self .attestations )
88
-
89
- @property
90
- def parent_hash (self ) -> Hash32 :
91
- if not self .ancestor_hashes :
92
- return None
93
- else :
94
- return self .ancestor_hashes [0 ]
109
+ return len (self .body .attestations )
0 commit comments