1
1
import asyncio
2
+ import inspect
2
3
from typing import ( # noqa: F401
3
4
Any ,
4
5
Optional ,
21
22
)
22
23
23
24
from evm .chains .base import (
24
- Chain ,
25
+ AccountState ,
26
+ BaseChain ,
27
+ )
28
+ from evm .db .backends .base import BaseDB
29
+ from evm .db .chain import (
30
+ BaseChainDB ,
25
31
)
26
32
from evm .db .header import (
27
33
BaseHeaderDB ,
31
37
)
32
38
from evm .rlp .headers import (
33
39
BlockHeader ,
40
+ HeaderParams ,
41
+ )
42
+ from evm .rlp .receipts import (
43
+ Receipt
44
+ )
45
+ from evm .rlp .transactions import (
46
+ BaseTransaction ,
47
+ BaseUnsignedTransaction ,
48
+ )
49
+ from evm .vm .computation import (
50
+ BaseComputation
34
51
)
35
52
36
53
from p2p .lightchain import (
41
58
from evm .vm .base import BaseVM # noqa: F401
42
59
43
60
44
- class LightDispatchChain (Chain ):
61
+ class LightDispatchChain (BaseChain ):
45
62
"""
46
63
Provide the :class:`BaseChain` API, even though only a
47
64
:class:`LightPeerChain` is syncing. Store results locally so that not
@@ -56,6 +73,46 @@ def __init__(self, headerdb: BaseHeaderDB, peer_chain: LightPeerChain) -> None:
56
73
self ._peer_chain = peer_chain
57
74
self ._peer_chain_loop = asyncio .get_event_loop ()
58
75
76
+ #
77
+ # Helpers
78
+ #
79
+ @classmethod
80
+ def get_chaindb_class (cls ) -> Type [BaseChainDB ]:
81
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
82
+
83
+ #
84
+ # Chain API
85
+ #
86
+ @classmethod
87
+ def from_genesis (cls ,
88
+ base_db : BaseDB ,
89
+ genesis_params : Dict [str , HeaderParams ],
90
+ genesis_state : AccountState = None ) -> 'BaseChain' :
91
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
92
+
93
+ @classmethod
94
+ def from_genesis_header (cls ,
95
+ base_db : BaseDB ,
96
+ genesis_header : BlockHeader ) -> 'BaseChain' :
97
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
98
+
99
+ def get_chain_at_block_parent (self , block : BaseBlock ) -> 'BaseChain' :
100
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
101
+
102
+ #
103
+ # VM API
104
+ #
105
+ def get_vm (self , header : BlockHeader = None ) -> 'BaseVM' :
106
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
107
+
108
+ #
109
+ # Header API
110
+ #
111
+ def create_header_from_parent (self ,
112
+ parent_header : BlockHeader ,
113
+ ** header_params : HeaderParams ) -> BlockHeader :
114
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
115
+
59
116
def get_block_header_by_hash (self , block_hash : Hash32 ) -> BlockHeader :
60
117
return self ._headerdb .get_block_header_by_hash (block_hash )
61
118
@@ -65,6 +122,15 @@ def get_canonical_head(self) -> BlockHeader:
65
122
def get_score (self , block_hash : Hash32 ) -> int :
66
123
return self ._headerdb .get_score (block_hash )
67
124
125
+ #
126
+ # Block API
127
+ #
128
+ def get_ancestors (self , limit : int , header : BlockHeader = None ) -> Iterator [BaseBlock ]:
129
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
130
+
131
+ def get_block (self ) -> BaseBlock :
132
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
133
+
68
134
def get_block_by_hash (self , block_hash : Hash32 ) -> BaseBlock :
69
135
header = self ._headerdb .get_block_header_by_hash (block_hash )
70
136
return self .get_block_by_header (header )
@@ -97,6 +163,59 @@ def get_canonical_block_by_number(self, block_number: BlockNumber) -> BaseBlock:
97
163
def get_canonical_block_hash (self , block_number : int ) -> Hash32 :
98
164
return self ._headerdb .get_canonical_block_hash (block_number )
99
165
166
+ def build_block_with_transactions (
167
+ self , transactions : Tuple [BaseTransaction , ...], parent_header : BlockHeader ) -> None :
168
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
169
+
170
+ #
171
+ # Transaction API
172
+ #
173
+ def create_transaction (self , * args : Any , ** kwargs : Any ) -> BaseTransaction :
174
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
175
+
176
+ def create_unsigned_transaction (self ,
177
+ * args : Any ,
178
+ ** kwargs : Any ) -> BaseUnsignedTransaction :
179
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
180
+
181
+ def get_canonical_transaction (self , transaction_hash : Hash32 ) -> BaseTransaction :
182
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
183
+
184
+ #
185
+ # Execution API
186
+ #
187
+ def apply_transaction (
188
+ self ,
189
+ transaction : BaseTransaction ) -> Tuple [BaseBlock , Receipt , BaseComputation ]:
190
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
191
+
192
+ def estimate_gas (self , transaction : BaseTransaction , at_header : BlockHeader = None ) -> int :
193
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
194
+
195
+ def import_block (self , block : BaseBlock , perform_validation : bool = True ) -> BaseBlock :
196
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
197
+
198
+ def mine_block (self , * args : Any , ** kwargs : Any ) -> BaseBlock :
199
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
200
+
201
+ #
202
+ # Validation API
203
+ #
204
+ def validate_block (self , block : BaseBlock ) -> None :
205
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
206
+
207
+ def validate_gaslimit (self , header : BlockHeader ) -> None :
208
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
209
+
210
+ def validate_seal (self , header : BlockHeader ) -> None :
211
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
212
+
213
+ def validate_uncles (self , block : BaseBlock ) -> None :
214
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
215
+
216
+ def validate_chain (self , chain : Tuple [BlockHeader , ...]) -> None :
217
+ raise NotImplementedError ("Chain classes must implement " + inspect .stack ()[0 ][3 ])
218
+
100
219
#
101
220
# Async utils
102
221
#
0 commit comments