-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathtypes.py
619 lines (485 loc) · 13.5 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
from typing import (
TYPE_CHECKING,
Any,
Callable,
Coroutine,
Dict,
List,
Literal,
NewType,
Optional,
Sequence,
Tuple,
Type,
TypedDict,
TypeVar,
Union,
)
from eth_typing import (
Address,
BlockNumber,
ChecksumAddress,
Hash32,
HexStr,
)
from hexbytes import (
HexBytes,
)
from web3._utils.abi_element_identifiers import (
FallbackFn,
ReceiveFn,
)
from web3._utils.compat import (
NotRequired,
)
if TYPE_CHECKING:
from web3.contract.base_contract import (
BaseContractEvent,
BaseContractFunction,
)
from web3.main import ( # noqa: F401
AsyncWeb3,
Web3,
)
TFunc = TypeVar("TFunc", bound=Callable[..., Any])
TParams = TypeVar("TParams")
TReturn = TypeVar("TReturn")
TValue = TypeVar("TValue")
BlockParams = Literal["latest", "earliest", "pending", "safe", "finalized"]
BlockIdentifier = Union[BlockParams, BlockNumber, Hash32, HexStr, HexBytes, int]
LatestBlockParam = Literal["latest"]
ABIElementIdentifier = Union[str, Type[FallbackFn], Type[ReceiveFn]]
# bytes, hexbytes, or hexstr representing a 32 byte hash
_Hash32 = Union[Hash32, HexBytes, HexStr]
EnodeURI = NewType("EnodeURI", str)
ENS = NewType("ENS", str)
Nonce = NewType("Nonce", int)
RPCEndpoint = NewType("RPCEndpoint", str)
Timestamp = NewType("Timestamp", int)
Wei = NewType("Wei", int)
Gwei = NewType("Gwei", int)
Formatters = Dict[RPCEndpoint, Callable[..., Any]]
class AccessListEntry(TypedDict):
address: HexStr
storageKeys: Sequence[HexStr]
AccessList = NewType("AccessList", Sequence[AccessListEntry])
class EventData(TypedDict):
address: ChecksumAddress
args: Dict[str, Any]
blockHash: HexBytes
blockNumber: int
event: str
logIndex: int
transactionHash: HexBytes
transactionIndex: int
class RPCError(TypedDict):
code: int
message: str
data: NotRequired[str]
# syntax b/c "from" keyword not allowed w/ class construction
TxData = TypedDict(
"TxData",
{
"accessList": AccessList,
"blobVersionedHashes": Sequence[HexBytes],
"blockHash": HexBytes,
"blockNumber": BlockNumber,
"chainId": int,
"data": Union[bytes, HexStr],
"from": ChecksumAddress,
"gas": int,
"gasPrice": Wei,
"maxFeePerBlobGas": Wei,
"maxFeePerGas": Wei,
"maxPriorityFeePerGas": Wei,
"hash": HexBytes,
"input": HexBytes,
"nonce": Nonce,
"r": HexBytes,
"s": HexBytes,
"to": ChecksumAddress,
"transactionIndex": int,
"type": Union[int, HexStr],
"v": int,
"value": Wei,
"yParity": int,
},
total=False,
)
# syntax b/c "from" keyword not allowed w/ class construction
TxParams = TypedDict(
"TxParams",
{
"accessList": AccessList,
"blobVersionedHashes": Sequence[Union[str, HexStr, bytes, HexBytes]],
"chainId": int,
"data": Union[bytes, HexStr],
# addr or ens
"from": Union[Address, ChecksumAddress, str],
"gas": int,
# legacy pricing
"gasPrice": Wei,
"maxFeePerBlobGas": Union[str, Wei],
# dynamic fee pricing
"maxFeePerGas": Union[str, Wei],
"maxPriorityFeePerGas": Union[str, Wei],
"nonce": Nonce,
# addr or ens
"to": Union[Address, ChecksumAddress, str],
"type": Union[int, HexStr],
"value": Wei,
},
total=False,
)
class WithdrawalData(TypedDict):
index: int
validator_index: int
address: ChecksumAddress
amount: Gwei
class BlockData(TypedDict, total=False):
baseFeePerGas: Wei
difficulty: int
extraData: HexBytes
gasLimit: int
gasUsed: int
hash: HexBytes
logsBloom: HexBytes
miner: ChecksumAddress
mixHash: HexBytes
nonce: HexBytes
number: BlockNumber
parentHash: HexBytes
receiptsRoot: HexBytes
sha3Uncles: HexBytes
size: int
stateRoot: HexBytes
timestamp: Timestamp
totalDifficulty: int
transactions: Union[Sequence[HexBytes], Sequence[TxData]]
transactionsRoot: HexBytes
uncles: Sequence[HexBytes]
withdrawals: Sequence[WithdrawalData]
withdrawalsRoot: HexBytes
parentBeaconBlockRoot: HexBytes
blobGasUsed: int
excessBlobGas: int
# ExtraDataToPOAMiddleware replaces extraData w/ proofOfAuthorityData
proofOfAuthorityData: HexBytes
class LogReceipt(TypedDict):
address: ChecksumAddress
blockHash: HexBytes
blockNumber: BlockNumber
data: HexBytes
logIndex: int
topics: Sequence[HexBytes]
transactionHash: HexBytes
transactionIndex: int
removed: bool
class SubscriptionResponse(TypedDict):
subscription: HexBytes
class BlockTypeSubscriptionResponse(SubscriptionResponse):
result: BlockData
class TransactionTypeSubscriptionResponse(SubscriptionResponse):
result: Union[HexBytes, TxData]
class LogsSubscriptionResponse(SubscriptionResponse):
result: LogReceipt
class SyncProgress(TypedDict):
isSyncing: bool
startingBlock: int
currentBlock: int
highestBlock: int
class SyncingSubscriptionResponse(SubscriptionResponse):
result: Union[Literal[False], SyncProgress]
class GethSyncingStatus(TypedDict):
currentBlock: int
highestBlock: int
knownStates: int
pulledStates: int
startingBlock: int
class GethSyncingSubscriptionResult(TypedDict):
syncing: bool
status: GethSyncingStatus
class GethSyncingSubscriptionResponse(SubscriptionResponse):
result: GethSyncingSubscriptionResult
EthSubscriptionParams = Union[
BlockTypeSubscriptionResponse,
TransactionTypeSubscriptionResponse,
LogsSubscriptionResponse,
SyncingSubscriptionResponse,
GethSyncingSubscriptionResponse,
]
RPCId = Optional[Union[int, str]]
class RPCRequest(TypedDict, total=False):
id: RPCId
jsonrpc: Literal["2.0"]
method: RPCEndpoint
params: Any
class RPCResponse(TypedDict, total=False):
error: RPCError
id: RPCId
jsonrpc: Literal["2.0"]
result: Any
# eth_subscribe
method: Literal["eth_subscription"]
params: EthSubscriptionParams
EthSubscriptionResult = Union[
BlockData, # newHeads
TxData, # newPendingTransactions, full_transactions=True
HexBytes, # newPendingTransactions, full_transactions=False
LogReceipt, # logs
SyncProgress, # syncing
GethSyncingSubscriptionResult, # geth syncing
]
class FormattedEthSubscriptionResponse(TypedDict):
subscription: HexStr
result: EthSubscriptionResult
class CreateAccessListResponse(TypedDict):
accessList: AccessList
gasUsed: int
MakeRequestFn = Callable[[RPCEndpoint, Any], RPCResponse]
MakeBatchRequestFn = Callable[
[List[Tuple[RPCEndpoint, Any]]], Union[List[RPCResponse], RPCResponse]
]
AsyncMakeRequestFn = Callable[[RPCEndpoint, Any], Coroutine[Any, Any, RPCResponse]]
AsyncMakeBatchRequestFn = Callable[
[List[Tuple[RPCEndpoint, Any]]],
Coroutine[Any, Any, Union[List[RPCResponse], RPCResponse]],
]
class FormattersDict(TypedDict, total=False):
error_formatters: Optional[Formatters]
request_formatters: Optional[Formatters]
result_formatters: Optional[Formatters]
class FilterParams(TypedDict, total=False):
address: Union[Address, ChecksumAddress, List[Address], List[ChecksumAddress]]
blockHash: HexBytes
fromBlock: BlockIdentifier
toBlock: BlockIdentifier
topics: Sequence[Optional[Union[_Hash32, Sequence[_Hash32]]]]
class FeeHistory(TypedDict):
baseFeePerGas: List[Wei]
gasUsedRatio: List[float]
oldestBlock: BlockNumber
reward: List[List[Wei]]
class StateOverrideParams(TypedDict, total=False):
balance: Optional[Wei]
nonce: Optional[int]
code: Optional[Union[bytes, HexStr]]
state: Optional[Dict[HexStr, HexStr]]
stateDiff: Optional[Dict[HexStr, HexStr]]
StateOverride = Dict[ChecksumAddress, StateOverrideParams]
GasPriceStrategy = Union[
Callable[["Web3", TxParams], Wei], Callable[["AsyncWeb3", TxParams], Wei]
]
# syntax b/c "from" keyword not allowed w/ class construction
TxReceipt = TypedDict(
"TxReceipt",
{
"blockHash": HexBytes,
"blockNumber": BlockNumber,
"contractAddress": Optional[ChecksumAddress],
"cumulativeGasUsed": int,
"effectiveGasPrice": Wei,
"gasUsed": int,
"from": ChecksumAddress,
"logs": List[LogReceipt],
"logsBloom": HexBytes,
"root": HexStr,
"status": int,
"to": ChecksumAddress,
"transactionHash": HexBytes,
"transactionIndex": int,
"type": int,
},
)
BlockReceipts = List[TxReceipt]
class SignedTx(TypedDict, total=False):
raw: bytes
tx: TxParams
class StorageProof(TypedDict):
key: HexStr
proof: Sequence[HexStr]
value: HexBytes
class MerkleProof(TypedDict):
address: ChecksumAddress
accountProof: Sequence[HexStr]
balance: int
codeHash: HexBytes
nonce: Nonce
storageHash: HexBytes
storageProof: Sequence[StorageProof]
class Protocol(TypedDict):
difficulty: int
head: HexStr
network: int
version: int
class NodeInfo(TypedDict):
enode: EnodeURI
id: HexStr
ip: str
listenAddr: str
name: str
ports: Dict[str, int]
protocols: Dict[str, Protocol]
class Peer(TypedDict, total=False):
caps: Sequence[str]
id: HexStr
name: str
network: Dict[str, str]
protocols: Dict[str, Protocol]
class SyncStatus(TypedDict):
currentBlock: int
highestBlock: int
knownStates: int
pulledStates: int
startingBlock: int
class Uncle(TypedDict):
author: ChecksumAddress
difficulty: HexStr
extraData: HexStr
gasLimit: HexStr
gasUsed: HexStr
hash: HexBytes
logsBloom: HexStr
miner: HexBytes
mixHash: HexBytes
nonce: HexStr
number: HexStr
parentHash: HexBytes
receiptsRoot: HexBytes
sealFields: Sequence[HexStr]
sha3Uncles: HexBytes
size: int
stateRoot: HexBytes
timestamp: Timestamp
totalDifficulty: HexStr
transactions: Sequence[HexBytes]
transactionsRoot: HexBytes
uncles: Sequence[HexBytes]
#
# txpool types
#
# syntax b/c "from" keyword not allowed w/ class construction
PendingTx = TypedDict(
"PendingTx",
{
"blockHash": HexBytes,
"blockNumber": None,
"from": ChecksumAddress,
"gas": HexBytes,
"maxFeePerGas": HexBytes,
"maxPriorityFeePerGas": HexBytes,
"gasPrice": HexBytes,
"hash": HexBytes,
"input": HexBytes,
"nonce": HexBytes,
"to": ChecksumAddress,
"transactionIndex": None,
"value": HexBytes,
},
total=False,
)
class TxPoolContent(TypedDict, total=False):
pending: Dict[ChecksumAddress, Dict[Nonce, List[PendingTx]]]
queued: Dict[ChecksumAddress, Dict[Nonce, List[PendingTx]]]
class TxPoolInspect(TypedDict, total=False):
pending: Dict[ChecksumAddress, Dict[Nonce, str]]
queued: Dict[ChecksumAddress, Dict[Nonce, str]]
class TxPoolStatus(TypedDict, total=False):
pending: int
queued: int
#
# debug types
#
class TraceConfig(TypedDict, total=False):
disableStorage: bool
disableStack: bool
enableMemory: bool
enableReturnData: bool
tracer: str
tracerConfig: Dict[str, Any]
timeout: int
class CallTraceLog(TypedDict):
address: ChecksumAddress
data: HexBytes
topics: Sequence[HexBytes]
position: int
# syntax b/c "from" keyword not allowed w/ class construction
CallTrace = TypedDict(
"CallTrace",
{
"type": str,
"from": ChecksumAddress,
"to": ChecksumAddress,
"value": Wei,
"gas": int,
"gasUsed": int,
"input": HexBytes,
"output": HexBytes,
"error": str,
"revertReason": str,
"calls": Sequence["CallTrace"],
"logs": Sequence[CallTraceLog],
},
total=False,
)
class TraceData(TypedDict, total=False):
balance: int
nonce: int
code: str
storage: Dict[str, str]
class DiffModeTrace(TypedDict):
post: Dict[ChecksumAddress, TraceData]
pre: Dict[ChecksumAddress, TraceData]
PrestateTrace = Dict[ChecksumAddress, TraceData]
# 4byte tracer returns something like:
# { '0x27dc297e-128' : 1 }
# which is: { 4byte signature - calldata size : # of occurrences of key }
FourByteTrace = Dict[str, int]
class StructLog(TypedDict):
pc: int
op: str
gas: int
gasCost: int
depth: int
stack: List[HexStr]
class OpcodeTrace(TypedDict, total=False):
gas: int
failed: bool
returnValue: str
structLogs: List[StructLog]
#
# web3.geth types
#
class GethWallet(TypedDict):
accounts: Sequence[Dict[str, str]]
status: str
url: str
# Contract types
TContractFn = TypeVar("TContractFn", bound="BaseContractFunction")
TContractEvent = TypeVar("TContractEvent", bound="BaseContractEvent")
# Tracing types
BlockTrace = NewType("BlockTrace", Dict[str, Any])
FilterTrace = NewType("FilterTrace", Dict[str, Any])
TraceMode = Sequence[Literal["trace", "vmTrace", "stateDiff"]]
class TraceFilterParams(TypedDict, total=False):
after: int
count: int
fromAddress: Sequence[Union[Address, ChecksumAddress, ENS]]
fromBlock: BlockIdentifier
toAddress: Sequence[Union[Address, ChecksumAddress, ENS]]
toBlock: BlockIdentifier
# Subscriptions
SubscriptionType = Literal[
"newHeads",
"logs",
"newPendingTransactions",
"syncing",
]
class LogsSubscriptionArg(TypedDict, total=False):
address: Union[
Address,
ChecksumAddress,
ENS,
Sequence[Union[Address, ChecksumAddress, ENS]],
]
topics: Sequence[Union[HexStr, Sequence[HexStr]]]