19
19
Type ,
20
20
TypeVar ,
21
21
Union ,
22
+ Hashable ,
22
23
)
23
24
24
- import rlp
25
-
26
25
from eth_bloom import BloomFilter
27
26
28
27
from eth_typing import (
53
52
T = TypeVar ('T' )
54
53
55
54
56
- class MiningHeaderAPI (rlp . Serializable , ABC ):
55
+ class MiningHeaderAPI (ABC ):
57
56
"""
58
57
A class to define a block header without ``mix_hash`` and ``nonce`` which can act as a
59
58
temporary representation during mining before the block header is sealed.
@@ -72,6 +71,53 @@ class MiningHeaderAPI(rlp.Serializable, ABC):
72
71
timestamp : int
73
72
extra_data : bytes
74
73
74
+ @property
75
+ @abstractmethod
76
+ def hash (self ) -> Hash32 :
77
+ """
78
+ Return the hash of the block header.
79
+ """
80
+ ...
81
+
82
+ @property
83
+ @abstractmethod
84
+ def mining_hash (self ) -> Hash32 :
85
+ """
86
+ Return the mining hash of the block header.
87
+ """
88
+
89
+ @property
90
+ def hex_hash (self ) -> str :
91
+ """
92
+ Return the hash as a hex string.
93
+ """
94
+ ...
95
+
96
+ @property
97
+ @abstractmethod
98
+ def is_genesis (self ) -> bool :
99
+ """
100
+ Return ``True`` if this header represents the genesis block of the chain,
101
+ otherwise ``False``.
102
+ """
103
+ ...
104
+
105
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
106
+ @abstractmethod
107
+ def build_changeset (self , * args : Any , ** kwargs : Any ) -> Any :
108
+ """
109
+ Open a changeset to modify the header.
110
+ """
111
+ ...
112
+
113
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
114
+ @abstractmethod
115
+ def as_dict (self ) -> Dict [Hashable , Any ]:
116
+ """
117
+ Return a dictionary representation of the header.
118
+ """
119
+ ...
120
+
75
121
76
122
class BlockHeaderAPI (MiningHeaderAPI ):
77
123
"""
@@ -81,8 +127,16 @@ class BlockHeaderAPI(MiningHeaderAPI):
81
127
mix_hash : Hash32
82
128
nonce : bytes
83
129
130
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
131
+ @abstractmethod
132
+ def copy (self , * args : Any , ** kwargs : Any ) -> 'BlockHeaderAPI' :
133
+ """
134
+ Return a copy of the header, optionally overwriting any of its properties.
135
+ """
136
+ ...
137
+
84
138
85
- class LogAPI (rlp . Serializable , ABC ):
139
+ class LogAPI (ABC ):
86
140
"""
87
141
A class to define a written log.
88
142
"""
@@ -96,7 +150,7 @@ def bloomables(self) -> Tuple[bytes, ...]:
96
150
...
97
151
98
152
99
- class ReceiptAPI (rlp . Serializable , ABC ):
153
+ class ReceiptAPI (ABC ):
100
154
"""
101
155
A class to define a receipt to capture the outcome of a transaction.
102
156
"""
@@ -110,6 +164,15 @@ class ReceiptAPI(rlp.Serializable, ABC):
110
164
def bloom_filter (self ) -> BloomFilter :
111
165
...
112
166
167
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
168
+ def copy (self , * args : Any , ** kwargs : Any ) -> 'ReceiptAPI' :
169
+ """
170
+ Return a copy of the receipt, optionally overwriting any of its properties.
171
+ """
172
+ # This method isn't marked abstract because derived classes implement it by deriving from
173
+ # rlp.Serializable but mypy won't recognize it as implemented.
174
+ ...
175
+
113
176
114
177
class BaseTransactionAPI (ABC ):
115
178
"""
@@ -148,6 +211,7 @@ def gas_used_by(self, computation: 'ComputationAPI') -> int:
148
211
"""
149
212
...
150
213
214
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
151
215
@abstractmethod
152
216
def copy (self : T , ** overrides : Any ) -> T :
153
217
"""
@@ -172,11 +236,15 @@ class TransactionFieldsAPI(ABC):
172
236
173
237
@property
174
238
@abstractmethod
175
- def hash (self ) -> bytes :
239
+ def hash (self ) -> Hash32 :
240
+ """
241
+ Return the hash of the transaction.
242
+ """
176
243
...
177
244
178
245
179
- class UnsignedTransactionAPI (rlp .Serializable , BaseTransactionAPI ):
246
+ class UnsignedTransactionAPI (BaseTransactionAPI ):
247
+
180
248
"""
181
249
A class representing a transaction before it is signed.
182
250
"""
@@ -199,7 +267,11 @@ def as_signed_transaction(self, private_key: PrivateKey) -> 'SignedTransactionAP
199
267
...
200
268
201
269
202
- class SignedTransactionAPI (rlp .Serializable , BaseTransactionAPI , TransactionFieldsAPI ):
270
+ class SignedTransactionAPI (BaseTransactionAPI , TransactionFieldsAPI ):
271
+
272
+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
273
+ ...
274
+
203
275
"""
204
276
A class representing a transaction that was signed with a private key.
205
277
"""
@@ -288,12 +360,29 @@ def create_unsigned_transaction(cls,
288
360
"""
289
361
...
290
362
363
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
364
+ def as_dict (self ) -> Dict [Hashable , Any ]:
365
+ """
366
+ Return a dictionary representation of the transaction.
367
+ """
368
+ ...
291
369
292
- class BlockAPI (rlp .Serializable , ABC ):
370
+
371
+ class BlockAPI (ABC ):
293
372
"""
294
373
A class to define a block.
295
374
"""
375
+ header : BlockHeaderAPI
376
+ transactions : Tuple [SignedTransactionAPI , ...]
296
377
transaction_class : Type [SignedTransactionAPI ] = None
378
+ uncles : Tuple [BlockHeaderAPI , ...]
379
+
380
+ @abstractmethod
381
+ def __init__ (self ,
382
+ header : BlockHeaderAPI ,
383
+ transactions : Sequence [SignedTransactionAPI ],
384
+ uncles : Sequence [BlockHeaderAPI ]):
385
+ ...
297
386
298
387
@classmethod
299
388
@abstractmethod
@@ -311,6 +400,13 @@ def from_header(cls, header: BlockHeaderAPI, chaindb: 'ChainDatabaseAPI') -> 'Bl
311
400
"""
312
401
...
313
402
403
+ @abstractmethod
404
+ def get_receipts (self , chaindb : 'ChainDatabaseAPI' ) -> Tuple [ReceiptAPI , ...]:
405
+ """
406
+ Fetch the receipts for this block from the given ``chaindb``.
407
+ """
408
+ ...
409
+
314
410
@property
315
411
@abstractmethod
316
412
def hash (self ) -> Hash32 :
@@ -336,6 +432,15 @@ def is_genesis(self) -> bool:
336
432
"""
337
433
...
338
434
435
+ # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
436
+ def copy (self , * args : Any , ** kwargs : Any ) -> 'BlockAPI' :
437
+ """
438
+ Return a copy of the block, optionally overwriting any of its properties.
439
+ """
440
+ # This method isn't marked abstract because derived classes implement it by deriving from
441
+ # rlp.Serializable but mypy won't recognize it as implemented.
442
+ ...
443
+
339
444
340
445
class MetaWitnessAPI (ABC ):
341
446
@property
@@ -1749,6 +1854,16 @@ def get_accessed_slots(self) -> FrozenSet[int]:
1749
1854
...
1750
1855
1751
1856
1857
+ class AccountAPI (ABC ):
1858
+ """
1859
+ A class representing an Ethereum account.
1860
+ """
1861
+ nonce : int
1862
+ balance : int
1863
+ storage_root : Hash32
1864
+ code_hash : Hash32
1865
+
1866
+
1752
1867
class AccountDatabaseAPI (ABC ):
1753
1868
"""
1754
1869
A class representing a database for accounts.
@@ -2807,7 +2922,7 @@ def previous_hashes(self) -> Optional[Iterable[Hash32]]:
2807
2922
2808
2923
@staticmethod
2809
2924
@abstractmethod
2810
- def get_uncle_reward (block_number : BlockNumber , uncle : BlockAPI ) -> int :
2925
+ def get_uncle_reward (block_number : BlockNumber , uncle : BlockHeaderAPI ) -> int :
2811
2926
"""
2812
2927
Return the reward which should be given to the miner of the given `uncle`.
2813
2928
0 commit comments