forked from ethereum/web3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth.py
806 lines (687 loc) · 26.9 KB
/
eth.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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
from typing import (
Any,
Callable,
List,
NoReturn,
Optional,
Sequence,
Tuple,
Type,
Union,
cast,
overload,
)
import warnings
from eth_account import (
Account,
)
from eth_typing import (
Address,
BlockNumber,
ChecksumAddress,
HexStr,
)
from eth_utils import (
is_checksum_address,
is_string,
)
from eth_utils.toolz import (
assoc,
merge,
)
from hexbytes import (
HexBytes,
)
from web3._utils.blocks import (
select_method_for_block_identifier,
)
from web3._utils.decorators import (
deprecated_for,
)
from web3._utils.empty import (
Empty,
empty,
)
from web3._utils.encoding import (
to_hex,
)
from web3._utils.filters import (
select_filter_method,
)
from web3._utils.rpc_abi import (
RPC,
)
from web3._utils.threads import (
Timeout,
)
from web3._utils.transactions import (
assert_valid_transaction_params,
extract_valid_transaction_params,
get_required_transaction,
replace_transaction,
wait_for_transaction_receipt,
)
from web3.contract import (
ConciseContract,
Contract,
ContractCaller,
)
from web3.exceptions import (
TimeExhausted,
)
from web3.iban import (
Iban,
)
from web3.method import (
DeprecatedMethod,
Method,
default_root_munger,
)
from web3.module import (
Module,
)
from web3.types import (
ENS,
BlockData,
BlockIdentifier,
CallOverrideParams,
FilterParams,
GasPriceStrategy,
LogReceipt,
MerkleProof,
Nonce,
SignedTx,
SyncStatus,
TxData,
TxParams,
TxReceipt,
Uncle,
Wei,
_Hash32,
)
class BaseEth(Module):
_default_account: Union[ChecksumAddress, Empty] = empty
gasPriceStrategy = None
_gas_price: Method[Callable[[], Wei]] = Method(
RPC.eth_gasPrice,
mungers=None,
)
@property
def default_account(self) -> Union[ChecksumAddress, Empty]:
return self._default_account
def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
if 'from' not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, 'from', self.default_account)
return (transaction,)
_send_transaction: Method[Callable[[TxParams], HexBytes]] = Method(
RPC.eth_sendTransaction,
mungers=[send_transaction_munger]
)
_get_transaction: Method[Callable[[_Hash32], TxData]] = Method(
RPC.eth_getTransactionByHash,
mungers=[default_root_munger]
)
_get_raw_transaction: Method[Callable[[_Hash32], HexBytes]] = Method(
RPC.eth_getRawTransactionByHash,
mungers=[default_root_munger]
)
def _generate_gas_price(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
if self.gasPriceStrategy:
return self.gasPriceStrategy(self.web3, transaction_params)
return None
def set_gas_price_strategy(self, gas_price_strategy: GasPriceStrategy) -> None:
self.gasPriceStrategy = gas_price_strategy
def estimate_gas_munger(
self,
transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None
) -> Sequence[Union[TxParams, BlockIdentifier]]:
if 'from' not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, 'from', self.default_account)
if block_identifier is None:
params: Sequence[Union[TxParams, BlockIdentifier]] = [transaction]
else:
params = [transaction, block_identifier]
return params
_estimate_gas: Method[Callable[..., Wei]] = Method(
RPC.eth_estimateGas,
mungers=[estimate_gas_munger]
)
def get_block_munger(
self, block_identifier: BlockIdentifier, full_transactions: bool = False
) -> Tuple[BlockIdentifier, bool]:
return (block_identifier, full_transactions)
"""
`eth_getBlockByHash`
`eth_getBlockByNumber`
"""
_get_block: Method[Callable[..., BlockData]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getBlockByNumber,
if_hash=RPC.eth_getBlockByHash,
if_number=RPC.eth_getBlockByNumber,
),
mungers=[get_block_munger],
)
get_block_number: Method[Callable[[], BlockNumber]] = Method(
RPC.eth_blockNumber,
mungers=None,
)
get_coinbase: Method[Callable[[], ChecksumAddress]] = Method(
RPC.eth_coinbase,
mungers=None,
)
class AsyncEth(BaseEth):
is_async = True
@property
async def gas_price(self) -> Wei:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._gas_price() # type: ignore
async def send_transaction(self, transaction: TxParams) -> HexBytes:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._send_transaction(transaction) # type: ignore
async def get_transaction(self, transaction_hash: _Hash32) -> TxData:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._get_transaction(transaction_hash) # type: ignore
async def get_raw_transaction(self, transaction_hash: _Hash32) -> TxData:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._get_raw_transaction(transaction_hash) # type: ignore
async def generate_gas_price(
self, transaction_params: Optional[TxParams] = None
) -> Optional[Wei]:
return self._generate_gas_price(transaction_params)
async def estimate_gas(
self,
transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None
) -> Wei:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._estimate_gas(transaction, block_identifier) # type: ignore
async def get_block(
self, block_identifier: BlockIdentifier, full_transactions: bool = False
) -> BlockData:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._get_block(block_identifier, full_transactions) # type: ignore
@property
async def block_number(self) -> BlockNumber:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_block_number() # type: ignore
@property
async def coinbase(self) -> ChecksumAddress:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_coinbase() # type: ignore
class Eth(BaseEth, Module):
account = Account()
_default_block: BlockIdentifier = "latest"
defaultContractFactory: Type[Union[Contract, ConciseContract, ContractCaller]] = Contract # noqa: E704,E501
iban = Iban
def namereg(self) -> NoReturn:
raise NotImplementedError()
def icapNamereg(self) -> NoReturn:
raise NotImplementedError()
_protocol_version: Method[Callable[[], str]] = Method(
RPC.eth_protocolVersion,
mungers=None,
)
@property
def protocol_version(self) -> str:
warnings.warn(
"This method has been deprecated in some clients.",
category=DeprecationWarning,
)
return self._protocol_version()
@property
def protocolVersion(self) -> str:
warnings.warn(
'protocolVersion is deprecated in favor of protocol_version',
category=DeprecationWarning,
)
return self.protocol_version
is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
RPC.eth_syncing,
mungers=None,
)
@property
def syncing(self) -> Union[SyncStatus, bool]:
return self.is_syncing()
@property
def coinbase(self) -> ChecksumAddress:
return self.get_coinbase()
is_mining: Method[Callable[[], bool]] = Method(
RPC.eth_mining,
mungers=None,
)
@property
def mining(self) -> bool:
return self.is_mining()
get_hashrate: Method[Callable[[], int]] = Method(
RPC.eth_hashrate,
mungers=None,
)
@property
def hashrate(self) -> int:
return self.get_hashrate()
@property
def gas_price(self) -> Wei:
return self._gas_price()
@property
def gasPrice(self) -> Wei:
warnings.warn(
'gasPrice is deprecated in favor of gas_price',
category=DeprecationWarning,
)
return self.gas_price
get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
RPC.eth_accounts,
mungers=None,
)
@property
def accounts(self) -> Tuple[ChecksumAddress]:
return self.get_accounts()
@property
def block_number(self) -> BlockNumber:
return self.get_block_number()
@property
def blockNumber(self) -> BlockNumber:
warnings.warn(
'blockNumber is deprecated in favor of block_number',
category=DeprecationWarning,
)
return self.block_number
_chain_id: Method[Callable[[], int]] = Method(
RPC.eth_chainId,
mungers=None,
)
@property
def chain_id(self) -> int:
return self._chain_id()
@property
def chainId(self) -> int:
warnings.warn(
'chainId is deprecated in favor of chain_id',
category=DeprecationWarning,
)
return self.chain_id
""" property default_account """
@property
def default_account(self) -> Union[ChecksumAddress, Empty]:
return self._default_account
@default_account.setter
def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
self._default_account = account
@property
def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
return self._default_account
@defaultAccount.setter
def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
self._default_account = account
""" property default_block """
@property
def default_block(self) -> BlockIdentifier:
return self._default_block
@default_block.setter
def default_block(self, value: BlockIdentifier) -> None:
self._default_block = value
@property
def defaultBlock(self) -> BlockIdentifier:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
return self._default_block
@defaultBlock.setter
def defaultBlock(self, value: BlockIdentifier) -> None:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
self._default_block = value
def block_id_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], BlockIdentifier]:
if block_identifier is None:
block_identifier = self.default_block
return (account, block_identifier)
get_balance: Method[Callable[..., Wei]] = Method(
RPC.eth_getBalance,
mungers=[block_id_munger],
)
def get_storage_at_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
position: int,
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
if block_identifier is None:
block_identifier = self.default_block
return (account, position, block_identifier)
get_storage_at: Method[Callable[..., HexBytes]] = Method(
RPC.eth_getStorageAt,
mungers=[get_storage_at_munger],
)
def get_proof_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
positions: Sequence[int],
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int], Optional[BlockIdentifier]]:
if block_identifier is None:
block_identifier = self.default_block
return (account, positions, block_identifier)
get_proof: Method[
Callable[
[Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int], Optional[BlockIdentifier]]],
MerkleProof
]
] = Method(
RPC.eth_getProof,
mungers=[get_proof_munger],
)
get_code: Method[Callable[..., HexBytes]] = Method(
RPC.eth_getCode,
mungers=[block_id_munger]
)
def get_block(
self, block_identifier: BlockIdentifier, full_transactions: bool = False
) -> BlockData:
return self._get_block(block_identifier, full_transactions)
"""
`eth_getBlockTransactionCountByHash`
`eth_getBlockTransactionCountByNumber`
"""
get_block_transaction_count: Method[Callable[[BlockIdentifier], int]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getBlockTransactionCountByNumber,
if_hash=RPC.eth_getBlockTransactionCountByHash,
if_number=RPC.eth_getBlockTransactionCountByNumber,
),
mungers=[default_root_munger]
)
"""
`eth_getUncleCountByBlockHash`
`eth_getUncleCountByBlockNumber`
"""
get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getUncleCountByBlockNumber,
if_hash=RPC.eth_getUncleCountByBlockHash,
if_number=RPC.eth_getUncleCountByBlockNumber,
),
mungers=[default_root_munger]
)
"""
`eth_getUncleByBlockHashAndIndex`
`eth_getUncleByBlockNumberAndIndex`
"""
get_uncle_by_block: Method[Callable[[BlockIdentifier, int], Uncle]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getUncleByBlockNumberAndIndex,
if_hash=RPC.eth_getUncleByBlockHashAndIndex,
if_number=RPC.eth_getUncleByBlockNumberAndIndex,
),
mungers=[default_root_munger]
)
def get_transaction(self, transaction_hash: _Hash32) -> TxData:
return self._get_transaction(transaction_hash)
def get_raw_transaction(self, transaction_hash: _Hash32) -> _Hash32:
return self._get_raw_transaction(transaction_hash)
def getTransactionFromBlock(
self, block_identifier: BlockIdentifier, transaction_index: int
) -> NoReturn:
"""
Alias for the method getTransactionByBlock
Deprecated to maintain naming consistency with the json-rpc API
"""
raise DeprecationWarning("This method has been deprecated as of EIP 1474.")
get_transaction_by_block: Method[Callable[[BlockIdentifier, int], TxData]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getTransactionByBlockNumberAndIndex,
if_hash=RPC.eth_getTransactionByBlockHashAndIndex,
if_number=RPC.eth_getTransactionByBlockNumberAndIndex,
),
mungers=[default_root_munger]
)
@deprecated_for("wait_for_transaction_receipt")
def waitForTransactionReceipt(
self, transaction_hash: _Hash32, timeout: int = 120, poll_latency: float = 0.1
) -> TxReceipt:
return self.wait_for_transaction_receipt(transaction_hash, timeout, poll_latency)
def wait_for_transaction_receipt(
self, transaction_hash: _Hash32, timeout: int = 120, poll_latency: float = 0.1
) -> TxReceipt:
try:
return wait_for_transaction_receipt(self.web3, transaction_hash, timeout, poll_latency)
except Timeout:
raise TimeExhausted(
"Transaction {} is not in the chain, after {} seconds".format(
to_hex(transaction_hash),
timeout,
)
)
get_transaction_receipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
RPC.eth_getTransactionReceipt,
mungers=[default_root_munger]
)
get_transaction_count: Method[Callable[..., Nonce]] = Method(
RPC.eth_getTransactionCount,
mungers=[block_id_munger],
)
@deprecated_for("replace_transaction")
def replaceTransaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes:
return self.replace_transaction(transaction_hash, new_transaction)
def replace_transaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes:
current_transaction = get_required_transaction(self.web3, transaction_hash)
return replace_transaction(self.web3, current_transaction, new_transaction)
# todo: Update Any to stricter kwarg checking with TxParams
# https://github.com/python/mypy/issues/4441
@deprecated_for("modify_transaction")
def modifyTransaction(
self, transaction_hash: _Hash32, **transaction_params: Any
) -> HexBytes:
return self.modify_transaction(transaction_hash, **transaction_params)
def modify_transaction(
self, transaction_hash: _Hash32, **transaction_params: Any
) -> HexBytes:
assert_valid_transaction_params(cast(TxParams, transaction_params))
current_transaction = get_required_transaction(self.web3, transaction_hash)
current_transaction_params = extract_valid_transaction_params(current_transaction)
new_transaction = merge(current_transaction_params, transaction_params)
return replace_transaction(self.web3, current_transaction, new_transaction)
def send_transaction(self, transaction: TxParams) -> HexBytes:
return self._send_transaction(transaction)
send_raw_transaction: Method[Callable[[Union[HexStr, bytes]], HexBytes]] = Method(
RPC.eth_sendRawTransaction,
mungers=[default_root_munger],
)
def sign_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
data: Union[int, bytes] = None,
hexstr: HexStr = None,
text: str = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], HexStr]:
message_hex = to_hex(data, hexstr=hexstr, text=text)
return (account, message_hex)
sign: Method[Callable[..., HexStr]] = Method(
RPC.eth_sign,
mungers=[sign_munger],
)
sign_transaction: Method[Callable[[TxParams], SignedTx]] = Method(
RPC.eth_signTransaction,
mungers=[default_root_munger],
)
sign_typed_data: Method[Callable[..., HexStr]] = Method(
RPC.eth_signTypedData,
mungers=[default_root_munger],
)
def call_munger(
self,
transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None,
state_override: Optional[CallOverrideParams] = None,
) -> Union[Tuple[TxParams, BlockIdentifier], Tuple[TxParams, BlockIdentifier, CallOverrideParams]]: # noqa-E501
# TODO: move to middleware
if 'from' not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, 'from', self.default_account)
# TODO: move to middleware
if block_identifier is None:
block_identifier = self.default_block
if state_override is None:
return (transaction, block_identifier)
else:
return (transaction, block_identifier, state_override)
call: Method[Callable[..., Union[bytes, bytearray]]] = Method(
RPC.eth_call,
mungers=[call_munger]
)
def estimate_gas(
self,
transaction: TxParams,
block_identifier: Optional[BlockIdentifier] = None
) -> Wei:
return self._estimate_gas(transaction, block_identifier)
def filter_munger(
self,
filter_params: Optional[Union[str, FilterParams]] = None,
filter_id: Optional[HexStr] = None
) -> Union[List[FilterParams], List[HexStr], List[str]]:
if filter_id and filter_params:
raise TypeError(
"Ambiguous invocation: provide either a `filter_params` or a `filter_id` argument. "
"Both were supplied."
)
if isinstance(filter_params, dict):
return [filter_params]
elif is_string(filter_params):
if filter_params in ['latest', 'pending']:
return [filter_params]
else:
raise ValueError(
"The filter API only accepts the values of `pending` or "
"`latest` for string based filters"
)
elif filter_id and not filter_params:
return [filter_id]
else:
raise TypeError("Must provide either filter_params as a string or "
"a valid filter object, or a filter_id as a string "
"or hex.")
filter: Method[Callable[..., Any]] = Method(
method_choice_depends_on_args=select_filter_method(
if_new_block_filter=RPC.eth_newBlockFilter,
if_new_pending_transaction_filter=RPC.eth_newPendingTransactionFilter,
if_new_filter=RPC.eth_newFilter,
),
mungers=[filter_munger],
)
get_filter_changes: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
RPC.eth_getFilterChanges,
mungers=[default_root_munger]
)
get_filter_logs: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
RPC.eth_getFilterLogs,
mungers=[default_root_munger]
)
get_logs: Method[Callable[[FilterParams], List[LogReceipt]]] = Method(
RPC.eth_getLogs,
mungers=[default_root_munger]
)
submit_hashrate: Method[Callable[[int, _Hash32], bool]] = Method(
RPC.eth_submitHashrate,
mungers=[default_root_munger],
)
submit_work: Method[Callable[[int, _Hash32, _Hash32], bool]] = Method(
RPC.eth_submitWork,
mungers=[default_root_munger],
)
uninstall_filter: Method[Callable[[HexStr], bool]] = Method(
RPC.eth_uninstallFilter,
mungers=[default_root_munger],
)
@overload
def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]: ... # noqa: E704,E501
@overload # noqa: F811
def contract(self, address: Union[Address, ChecksumAddress, ENS], **kwargs: Any) -> Contract: ... # noqa: E704,E501
def contract( # noqa: F811
self, address: Optional[Union[Address, ChecksumAddress, ENS]] = None, **kwargs: Any
) -> Union[Type[Contract], Contract]:
ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)
ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs)
if address:
return ContractFactory(address)
else:
return ContractFactory
@deprecated_for("set_contract_factory")
def setContractFactory(
self, contractFactory: Type[Union[Contract, ConciseContract, ContractCaller]]
) -> None:
return self.set_contract_factory(contractFactory)
def set_contract_factory(
self, contractFactory: Type[Union[Contract, ConciseContract, ContractCaller]]
) -> None:
self.defaultContractFactory = contractFactory
def getCompilers(self) -> NoReturn:
raise DeprecationWarning("This method has been deprecated as of EIP 1474.")
get_work: Method[Callable[[], List[HexBytes]]] = Method(
RPC.eth_getWork,
mungers=None,
)
@deprecated_for("generate_gas_price")
def generateGasPrice(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
return self._generate_gas_price(transaction_params)
def generate_gas_price(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]:
return self._generate_gas_price(transaction_params)
@deprecated_for("set_gas_price_strategy")
def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
return self.set_gas_price_strategy(gas_price_strategy)
# Deprecated Methods
getBalance = DeprecatedMethod(get_balance, 'getBalance', 'get_balance')
getStorageAt = DeprecatedMethod(get_storage_at, 'getStorageAt', 'get_storage_at')
getBlock = DeprecatedMethod(get_block, 'getBlock', 'get_block') # type: ignore
getBlockTransactionCount = DeprecatedMethod(get_block_transaction_count,
'getBlockTransactionCount',
'get_block_transaction_count')
getCode = DeprecatedMethod(get_code, 'getCode', 'get_code')
getProof = DeprecatedMethod(get_proof, 'getProof', 'get_proof')
getTransaction = DeprecatedMethod(get_transaction, # type: ignore
'getTransaction',
'get_transaction')
getTransactionByBlock = DeprecatedMethod(get_transaction_by_block,
'getTransactionByBlock',
'get_transaction_by_block')
getTransactionCount = DeprecatedMethod(get_transaction_count,
'getTransactionCount',
'get_transaction_count')
getUncleByBlock = DeprecatedMethod(get_uncle_by_block, 'getUncleByBlock', 'get_uncle_by_block')
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')
sendTransaction = DeprecatedMethod(send_transaction, # type: ignore
'sendTransaction',
'send_transaction')
signTransaction = DeprecatedMethod(sign_transaction, 'signTransaction', 'sign_transaction')
signTypedData = DeprecatedMethod(sign_typed_data, 'signTypedData', 'sign_typed_data')
submitHashrate = DeprecatedMethod(submit_hashrate, 'submitHashrate', 'submit_hashrate')
submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')
estimateGas = DeprecatedMethod(estimate_gas, 'estimateGas', 'estimate_gas') # type: ignore
sendRawTransaction = DeprecatedMethod(send_raw_transaction,
'sendRawTransaction',
'send_raw_transaction')
getTransactionReceipt = DeprecatedMethod(get_transaction_receipt,
'getTransactionReceipt',
'get_transaction_receipt')
uninstallFilter = DeprecatedMethod(uninstall_filter, 'uninstallFilter', 'uninstall_filter')
getFilterLogs = DeprecatedMethod(get_filter_logs, 'getFilterLogs', 'get_filter_logs')
getFilterChanges = DeprecatedMethod(get_filter_changes,
'getFilterChanges',
'get_filter_changes')
getWork = DeprecatedMethod(get_work, 'getWork', 'get_work')