web3 6.20.3__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +2 -17
- ens/async_ens.py +33 -21
- ens/base_ens.py +3 -1
- ens/ens.py +16 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +52 -63
- web3/__init__.py +20 -24
- web3/_utils/abi.py +115 -271
- web3/_utils/async_transactions.py +7 -4
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching.py +128 -5
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +130 -236
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +13 -23
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/ens.py +2 -1
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +66 -69
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +5 -3
- web3/_utils/http_session_manager.py +303 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +34 -36
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +0 -3
- web3/_utils/module_testing/eth_module.py +695 -643
- web3/_utils/module_testing/module_testing_utils.py +61 -34
- web3/_utils/module_testing/persistent_connection_provider.py +56 -25
- web3/_utils/module_testing/utils.py +258 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +5 -32
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +14 -12
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +17 -17
- web3/auto/gethdev.py +7 -2
- web3/beacon/__init__.py +6 -1
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/{main.py → beacon.py} +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +47 -46
- web3/contract/base_contract.py +183 -158
- web3/contract/contract.py +49 -43
- web3/contract/utils.py +203 -59
- web3/datastructures.py +79 -31
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +39 -51
- web3/eth/base_eth.py +17 -10
- web3/eth/eth.py +30 -68
- web3/exceptions.py +108 -82
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +1 -254
- web3/main.py +75 -122
- web3/manager.py +316 -146
- web3/method.py +38 -31
- web3/middleware/__init__.py +67 -89
- web3/middleware/attrdict.py +36 -49
- web3/middleware/base.py +174 -0
- web3/middleware/buffered_gas_estimate.py +20 -21
- web3/middleware/filter.py +157 -117
- web3/middleware/formatting.py +124 -108
- web3/middleware/gas_price_strategy.py +20 -32
- web3/middleware/names.py +29 -26
- web3/middleware/proof_of_authority.py +68 -0
- web3/middleware/pythonic.py +2 -2
- web3/middleware/signing.py +74 -89
- web3/middleware/stalecheck.py +52 -79
- web3/middleware/validation.py +5 -13
- web3/module.py +54 -10
- web3/providers/__init__.py +10 -6
- web3/providers/async_base.py +117 -39
- web3/providers/auto.py +3 -3
- web3/providers/base.py +89 -33
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +1 -64
- web3/providers/eth_tester/main.py +99 -31
- web3/providers/eth_tester/middleware.py +45 -73
- web3/providers/ipc.py +42 -46
- web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
- web3/providers/persistent/__init__.py +22 -0
- web3/providers/persistent/async_ipc.py +153 -0
- web3/providers/{persistent.py → persistent/persistent.py} +106 -25
- web3/providers/persistent/persistent_connection.py +84 -0
- web3/providers/{websocket → persistent}/request_processor.py +94 -32
- web3/providers/persistent/utils.py +43 -0
- web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
- web3/providers/rpc/__init__.py +11 -0
- web3/providers/rpc/async_rpc.py +171 -0
- web3/providers/rpc/rpc.py +179 -0
- web3/providers/rpc/utils.py +92 -0
- web3/testing.py +4 -4
- web3/tools/benchmark/main.py +22 -22
- web3/tools/benchmark/node.py +2 -8
- web3/tools/benchmark/reporting.py +2 -2
- web3/tools/benchmark/utils.py +1 -1
- web3/tracing.py +9 -5
- web3/types.py +30 -107
- web3/utils/__init__.py +58 -5
- web3/utils/abi.py +575 -10
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/caching.py +32 -13
- web3/utils/exception_handling.py +7 -5
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
- web3-7.0.0.dist-info/METADATA +112 -0
- web3-7.0.0.dist-info/RECORD +167 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/miner.py +0 -88
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
- web3/_utils/request.py +0 -265
- web3/middleware/abi.py +0 -11
- web3/middleware/async_cache.py +0 -99
- web3/middleware/cache.py +0 -374
- web3/middleware/exception_handling.py +0 -49
- web3/middleware/exception_retry_request.py +0 -188
- web3/middleware/fixture.py +0 -190
- web3/middleware/geth_poa.py +0 -81
- web3/middleware/normalize_request_parameters.py +0 -11
- web3/middleware/simulate_unmined_transaction.py +0 -43
- web3/pm.py +0 -602
- web3/providers/async_rpc.py +0 -99
- web3/providers/rpc.py +0 -98
- web3/providers/websocket/__init__.py +0 -11
- web3/providers/websocket/websocket_connection.py +0 -42
- web3/tools/__init__.py +0 -4
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-6.20.3.dist-info/METADATA +0 -104
- web3-6.20.3.dist-info/RECORD +0 -283
- web3-6.20.3.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
- {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/WHEEL +0 -0
web3/contract/base_contract.py
CHANGED
|
@@ -4,7 +4,6 @@ from typing import (
|
|
|
4
4
|
Callable,
|
|
5
5
|
Collection,
|
|
6
6
|
Dict,
|
|
7
|
-
Generator,
|
|
8
7
|
Iterable,
|
|
9
8
|
List,
|
|
10
9
|
NoReturn,
|
|
@@ -17,16 +16,27 @@ from typing import (
|
|
|
17
16
|
)
|
|
18
17
|
import warnings
|
|
19
18
|
|
|
19
|
+
from eth_abi.exceptions import (
|
|
20
|
+
InsufficientDataBytes,
|
|
21
|
+
)
|
|
20
22
|
from eth_typing import (
|
|
23
|
+
ABI,
|
|
24
|
+
ABIComponentIndexed,
|
|
25
|
+
ABIElement,
|
|
26
|
+
ABIEvent,
|
|
27
|
+
ABIFunction,
|
|
21
28
|
Address,
|
|
22
29
|
ChecksumAddress,
|
|
23
30
|
HexStr,
|
|
24
31
|
)
|
|
25
32
|
from eth_utils import (
|
|
33
|
+
abi_to_signature,
|
|
26
34
|
add_0x_prefix,
|
|
27
35
|
combomethod,
|
|
28
36
|
encode_hex,
|
|
37
|
+
filter_abi_by_type,
|
|
29
38
|
function_abi_to_4byte_selector,
|
|
39
|
+
get_normalized_abi_inputs,
|
|
30
40
|
is_list_like,
|
|
31
41
|
is_text,
|
|
32
42
|
to_tuple,
|
|
@@ -36,29 +46,23 @@ from hexbytes import (
|
|
|
36
46
|
)
|
|
37
47
|
|
|
38
48
|
from web3._utils.abi import (
|
|
39
|
-
abi_to_signature,
|
|
40
|
-
check_if_arguments_can_be_encoded,
|
|
41
49
|
fallback_func_abi_exists,
|
|
42
|
-
|
|
43
|
-
get_constructor_abi,
|
|
50
|
+
find_constructor_abi_element_by_type,
|
|
44
51
|
is_array_type,
|
|
45
|
-
merge_args_and_kwargs,
|
|
46
52
|
receive_func_abi_exists,
|
|
47
53
|
)
|
|
54
|
+
from web3._utils.abi_element_identifiers import (
|
|
55
|
+
FallbackFn,
|
|
56
|
+
ReceiveFn,
|
|
57
|
+
)
|
|
48
58
|
from web3._utils.contracts import (
|
|
49
59
|
decode_transaction_data,
|
|
50
60
|
encode_abi,
|
|
51
|
-
find_matching_event_abi,
|
|
52
|
-
find_matching_fn_abi,
|
|
53
|
-
get_function_info,
|
|
54
61
|
prepare_transaction,
|
|
55
62
|
)
|
|
56
63
|
from web3._utils.datatypes import (
|
|
57
64
|
PropertyCheckingFactory,
|
|
58
65
|
)
|
|
59
|
-
from web3._utils.decorators import (
|
|
60
|
-
deprecate_method,
|
|
61
|
-
)
|
|
62
66
|
from web3._utils.empty import (
|
|
63
67
|
empty,
|
|
64
68
|
)
|
|
@@ -75,10 +79,6 @@ from web3._utils.events import (
|
|
|
75
79
|
from web3._utils.filters import (
|
|
76
80
|
construct_event_filter_params,
|
|
77
81
|
)
|
|
78
|
-
from web3._utils.function_identifiers import (
|
|
79
|
-
FallbackFn,
|
|
80
|
-
ReceiveFn,
|
|
81
|
-
)
|
|
82
82
|
from web3._utils.normalizers import (
|
|
83
83
|
BASE_RETURN_NORMALIZERS,
|
|
84
84
|
)
|
|
@@ -87,16 +87,20 @@ from web3.datastructures import (
|
|
|
87
87
|
MutableAttributeDict,
|
|
88
88
|
)
|
|
89
89
|
from web3.exceptions import (
|
|
90
|
-
|
|
90
|
+
ABIEventNotFound,
|
|
91
|
+
ABIFallbackNotFound,
|
|
91
92
|
ABIFunctionNotFound,
|
|
92
|
-
|
|
93
|
+
ABIReceiveNotFound,
|
|
93
94
|
InvalidEventABI,
|
|
94
95
|
LogTopicError,
|
|
95
96
|
MismatchedABI,
|
|
96
97
|
NoABIEventsFound,
|
|
97
98
|
NoABIFound,
|
|
98
99
|
NoABIFunctionsFound,
|
|
100
|
+
Web3AttributeError,
|
|
101
|
+
Web3TypeError,
|
|
99
102
|
Web3ValidationError,
|
|
103
|
+
Web3ValueError,
|
|
100
104
|
)
|
|
101
105
|
from web3.logs import (
|
|
102
106
|
DISCARD,
|
|
@@ -106,17 +110,20 @@ from web3.logs import (
|
|
|
106
110
|
EventLogErrorFlags,
|
|
107
111
|
)
|
|
108
112
|
from web3.types import (
|
|
109
|
-
|
|
110
|
-
ABIEvent,
|
|
111
|
-
ABIFunction,
|
|
113
|
+
ABIElementIdentifier,
|
|
112
114
|
BlockIdentifier,
|
|
113
115
|
EventData,
|
|
114
116
|
FilterParams,
|
|
115
|
-
FunctionIdentifier,
|
|
116
117
|
TContractFn,
|
|
117
118
|
TxParams,
|
|
118
119
|
TxReceipt,
|
|
119
120
|
)
|
|
121
|
+
from web3.utils.abi import (
|
|
122
|
+
check_if_arguments_can_be_encoded,
|
|
123
|
+
get_abi_element,
|
|
124
|
+
get_abi_element_info,
|
|
125
|
+
get_event_abi,
|
|
126
|
+
)
|
|
120
127
|
|
|
121
128
|
if TYPE_CHECKING:
|
|
122
129
|
from web3 import ( # noqa: F401
|
|
@@ -129,7 +136,8 @@ if TYPE_CHECKING:
|
|
|
129
136
|
|
|
130
137
|
|
|
131
138
|
class BaseContractEvent:
|
|
132
|
-
"""
|
|
139
|
+
"""
|
|
140
|
+
Base class for contract events
|
|
133
141
|
|
|
134
142
|
An event accessed via the api `contract.events.myEvents(*args, **kwargs)`
|
|
135
143
|
is a subclass of this class.
|
|
@@ -152,7 +160,7 @@ class BaseContractEvent:
|
|
|
152
160
|
|
|
153
161
|
@classmethod
|
|
154
162
|
def _get_event_abi(cls) -> ABIEvent:
|
|
155
|
-
return
|
|
163
|
+
return get_event_abi(cls.contract_abi, event_name=cls.event_name)
|
|
156
164
|
|
|
157
165
|
@combomethod
|
|
158
166
|
def process_receipt(
|
|
@@ -167,14 +175,20 @@ class BaseContractEvent:
|
|
|
167
175
|
try:
|
|
168
176
|
errors.name
|
|
169
177
|
except AttributeError:
|
|
170
|
-
raise
|
|
178
|
+
raise Web3AttributeError(
|
|
171
179
|
f"Error flag must be one of: {EventLogErrorFlags.flag_options()}"
|
|
172
180
|
)
|
|
173
181
|
|
|
174
182
|
for log in txn_receipt["logs"]:
|
|
175
183
|
try:
|
|
176
184
|
rich_log = get_event_data(self.w3.codec, self.abi, log)
|
|
177
|
-
except (
|
|
185
|
+
except (
|
|
186
|
+
MismatchedABI,
|
|
187
|
+
LogTopicError,
|
|
188
|
+
InvalidEventABI,
|
|
189
|
+
TypeError,
|
|
190
|
+
InsufficientDataBytes,
|
|
191
|
+
) as e:
|
|
178
192
|
if errors == DISCARD:
|
|
179
193
|
continue
|
|
180
194
|
elif errors == IGNORE:
|
|
@@ -189,7 +203,8 @@ class BaseContractEvent:
|
|
|
189
203
|
f"The log with transaction hash: {log['transactionHash']!r} "
|
|
190
204
|
f"and logIndex: {log['logIndex']} encountered the following "
|
|
191
205
|
f"error during processing: {type(e).__name__}({e}). It has "
|
|
192
|
-
"been discarded."
|
|
206
|
+
"been discarded.",
|
|
207
|
+
stacklevel=2,
|
|
193
208
|
)
|
|
194
209
|
continue
|
|
195
210
|
yield rich_log
|
|
@@ -203,12 +218,12 @@ class BaseContractEvent:
|
|
|
203
218
|
self,
|
|
204
219
|
abi: ABIEvent,
|
|
205
220
|
argument_filters: Optional[Dict[str, Any]] = None,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
from_block: Optional[BlockIdentifier] = None,
|
|
222
|
+
to_block: Optional[BlockIdentifier] = None,
|
|
223
|
+
block_hash: Optional[HexBytes] = None,
|
|
209
224
|
) -> FilterParams:
|
|
210
225
|
if not self.address:
|
|
211
|
-
raise
|
|
226
|
+
raise Web3TypeError(
|
|
212
227
|
"This method can be only called on "
|
|
213
228
|
"an instated contract with an address"
|
|
214
229
|
)
|
|
@@ -218,11 +233,12 @@ class BaseContractEvent:
|
|
|
218
233
|
|
|
219
234
|
_filters = dict(**argument_filters)
|
|
220
235
|
|
|
221
|
-
blkhash_set =
|
|
222
|
-
blknum_set =
|
|
236
|
+
blkhash_set = block_hash is not None
|
|
237
|
+
blknum_set = from_block is not None or to_block is not None
|
|
223
238
|
if blkhash_set and blknum_set:
|
|
224
239
|
raise Web3ValidationError(
|
|
225
|
-
"
|
|
240
|
+
"`block_hash` cannot be set at the same time as "
|
|
241
|
+
"`from_block` or `to_block`"
|
|
226
242
|
)
|
|
227
243
|
|
|
228
244
|
# Construct JSON-RPC raw filter presentation based on human readable
|
|
@@ -232,13 +248,13 @@ class BaseContractEvent:
|
|
|
232
248
|
self.w3.codec,
|
|
233
249
|
contract_address=self.address,
|
|
234
250
|
argument_filters=_filters,
|
|
235
|
-
|
|
236
|
-
|
|
251
|
+
from_block=from_block,
|
|
252
|
+
to_block=to_block,
|
|
237
253
|
address=self.address,
|
|
238
254
|
)
|
|
239
255
|
|
|
240
|
-
if
|
|
241
|
-
event_filter_params["blockHash"] =
|
|
256
|
+
if block_hash is not None:
|
|
257
|
+
event_filter_params["blockHash"] = block_hash
|
|
242
258
|
|
|
243
259
|
return event_filter_params
|
|
244
260
|
|
|
@@ -255,12 +271,12 @@ class BaseContractEvent:
|
|
|
255
271
|
for filter_name, filter_value in _filters.items():
|
|
256
272
|
_input = name_indexed_inputs[filter_name]
|
|
257
273
|
if is_array_type(_input["type"]):
|
|
258
|
-
raise
|
|
274
|
+
raise Web3TypeError(
|
|
259
275
|
"createFilter no longer supports array type filter arguments. "
|
|
260
276
|
"see the build_filter method for filtering array type filters."
|
|
261
277
|
)
|
|
262
278
|
if is_list_like(filter_value) and is_dynamic_sized_type(_input["type"]):
|
|
263
|
-
raise
|
|
279
|
+
raise Web3TypeError(
|
|
264
280
|
"createFilter no longer supports setting filter argument options "
|
|
265
281
|
"for dynamic sized types. See the build_filter method for setting "
|
|
266
282
|
"filters with the match_any method."
|
|
@@ -279,7 +295,7 @@ class BaseContractEvent:
|
|
|
279
295
|
# if no non-indexed args in argument filters, since indexed args are
|
|
280
296
|
# filtered pre-call to ``eth_getLogs`` by building specific ``topics``.
|
|
281
297
|
not any(
|
|
282
|
-
not arg["indexed"]
|
|
298
|
+
not cast(ABIComponentIndexed, arg)["indexed"]
|
|
283
299
|
for arg in event_abi["inputs"]
|
|
284
300
|
if arg["name"] in argument_filters
|
|
285
301
|
)
|
|
@@ -318,15 +334,15 @@ class BaseContractEvent:
|
|
|
318
334
|
def _set_up_filter_builder(
|
|
319
335
|
self,
|
|
320
336
|
argument_filters: Optional[Dict[str, Any]] = None,
|
|
321
|
-
|
|
322
|
-
|
|
337
|
+
from_block: Optional[BlockIdentifier] = None,
|
|
338
|
+
to_block: BlockIdentifier = "latest",
|
|
323
339
|
address: Optional[ChecksumAddress] = None,
|
|
324
340
|
topics: Optional[Sequence[Any]] = None,
|
|
325
341
|
filter_builder: Union[EventFilterBuilder, AsyncEventFilterBuilder] = None,
|
|
326
342
|
) -> None:
|
|
327
|
-
if
|
|
328
|
-
raise
|
|
329
|
-
"Missing mandatory keyword argument to create_filter:
|
|
343
|
+
if from_block is None:
|
|
344
|
+
raise Web3TypeError(
|
|
345
|
+
"Missing mandatory keyword argument to create_filter: `from_block`"
|
|
330
346
|
)
|
|
331
347
|
|
|
332
348
|
if argument_filters is None:
|
|
@@ -343,8 +359,8 @@ class BaseContractEvent:
|
|
|
343
359
|
self.w3.codec,
|
|
344
360
|
contract_address=self.address,
|
|
345
361
|
argument_filters=_filters,
|
|
346
|
-
|
|
347
|
-
|
|
362
|
+
from_block=from_block,
|
|
363
|
+
to_block=to_block,
|
|
348
364
|
address=address,
|
|
349
365
|
topics=topics,
|
|
350
366
|
)
|
|
@@ -352,8 +368,8 @@ class BaseContractEvent:
|
|
|
352
368
|
filter_builder.address = cast(
|
|
353
369
|
ChecksumAddress, event_filter_params.get("address")
|
|
354
370
|
)
|
|
355
|
-
filter_builder.
|
|
356
|
-
filter_builder.
|
|
371
|
+
filter_builder.from_block = event_filter_params.get("fromBlock")
|
|
372
|
+
filter_builder.to_block = event_filter_params.get("toBlock")
|
|
357
373
|
match_any_vals = {
|
|
358
374
|
arg: value
|
|
359
375
|
for arg, value in _filters.items()
|
|
@@ -374,7 +390,8 @@ class BaseContractEvent:
|
|
|
374
390
|
|
|
375
391
|
|
|
376
392
|
class BaseContractEvents:
|
|
377
|
-
"""
|
|
393
|
+
"""
|
|
394
|
+
Class containing contract event objects
|
|
378
395
|
|
|
379
396
|
This is available via:
|
|
380
397
|
|
|
@@ -403,7 +420,7 @@ class BaseContractEvents:
|
|
|
403
420
|
) -> None:
|
|
404
421
|
if abi:
|
|
405
422
|
self.abi = abi
|
|
406
|
-
self._events =
|
|
423
|
+
self._events = filter_abi_by_type("event", self.abi)
|
|
407
424
|
for event in self._events:
|
|
408
425
|
setattr(
|
|
409
426
|
self,
|
|
@@ -424,7 +441,7 @@ class BaseContractEvents:
|
|
|
424
441
|
"Are you sure you provided the correct contract abi?",
|
|
425
442
|
)
|
|
426
443
|
elif event_name not in self.__dict__["_events"]:
|
|
427
|
-
raise
|
|
444
|
+
raise ABIEventNotFound(
|
|
428
445
|
f"The event '{event_name}' was not found in this contract's abi. ",
|
|
429
446
|
"Are you sure you provided the correct contract abi?",
|
|
430
447
|
)
|
|
@@ -435,7 +452,8 @@ class BaseContractEvents:
|
|
|
435
452
|
return getattr(self, event_name)
|
|
436
453
|
|
|
437
454
|
def __iter__(self) -> Iterable[Type["BaseContractEvent"]]:
|
|
438
|
-
"""
|
|
455
|
+
"""
|
|
456
|
+
Iterate over supported
|
|
439
457
|
|
|
440
458
|
:return: Iterable of :class:`ContractEvent`
|
|
441
459
|
"""
|
|
@@ -445,19 +463,20 @@ class BaseContractEvents:
|
|
|
445
463
|
def __hasattr__(self, event_name: str) -> bool:
|
|
446
464
|
try:
|
|
447
465
|
return event_name in self.__dict__["_events"]
|
|
448
|
-
except
|
|
466
|
+
except ABIEventNotFound:
|
|
449
467
|
return False
|
|
450
468
|
|
|
451
469
|
|
|
452
470
|
class BaseContractFunction:
|
|
453
|
-
"""
|
|
471
|
+
"""
|
|
472
|
+
Base class for contract functions
|
|
454
473
|
|
|
455
474
|
A function accessed via the api `contract.functions.myMethod(*args, **kwargs)`
|
|
456
475
|
is a subclass of this class.
|
|
457
476
|
"""
|
|
458
477
|
|
|
459
478
|
address: ChecksumAddress = None
|
|
460
|
-
|
|
479
|
+
abi_element_identifier: ABIElementIdentifier = None
|
|
461
480
|
w3: Union["Web3", "AsyncWeb3"] = None
|
|
462
481
|
contract_abi: ABI = None
|
|
463
482
|
abi: ABIFunction = None
|
|
@@ -473,24 +492,36 @@ class BaseContractFunction:
|
|
|
473
492
|
|
|
474
493
|
def _set_function_info(self) -> None:
|
|
475
494
|
if not self.abi:
|
|
476
|
-
self.abi =
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
495
|
+
self.abi = cast(
|
|
496
|
+
ABIFunction,
|
|
497
|
+
get_abi_element(
|
|
498
|
+
self.contract_abi,
|
|
499
|
+
self.abi_element_identifier,
|
|
500
|
+
*self.args,
|
|
501
|
+
abi_codec=self.w3.codec,
|
|
502
|
+
**self.kwargs,
|
|
503
|
+
),
|
|
482
504
|
)
|
|
483
|
-
|
|
505
|
+
|
|
506
|
+
if self.abi_element_identifier in [
|
|
507
|
+
FallbackFn,
|
|
508
|
+
ReceiveFn,
|
|
509
|
+
]:
|
|
484
510
|
self.selector = encode_hex(b"")
|
|
485
|
-
elif is_text(self.
|
|
486
|
-
|
|
487
|
-
self.selector = encode_hex(
|
|
488
|
-
function_abi_to_4byte_selector(self.abi) # type: ignore
|
|
489
|
-
)
|
|
511
|
+
elif is_text(self.abi_element_identifier):
|
|
512
|
+
self.selector = encode_hex(function_abi_to_4byte_selector(self.abi))
|
|
490
513
|
else:
|
|
491
|
-
raise
|
|
514
|
+
raise Web3TypeError("Unsupported function identifier")
|
|
492
515
|
|
|
493
|
-
|
|
516
|
+
if self.abi_element_identifier in [
|
|
517
|
+
FallbackFn,
|
|
518
|
+
ReceiveFn,
|
|
519
|
+
]:
|
|
520
|
+
self.arguments = None
|
|
521
|
+
else:
|
|
522
|
+
self.arguments = get_normalized_abi_inputs(
|
|
523
|
+
self.abi, *self.args, **self.kwargs
|
|
524
|
+
)
|
|
494
525
|
|
|
495
526
|
def _get_call_txparams(self, transaction: Optional[TxParams] = None) -> TxParams:
|
|
496
527
|
if transaction is None:
|
|
@@ -499,26 +530,25 @@ class BaseContractFunction:
|
|
|
499
530
|
call_transaction = cast(TxParams, dict(**transaction))
|
|
500
531
|
|
|
501
532
|
if "data" in call_transaction:
|
|
502
|
-
raise
|
|
533
|
+
raise Web3ValueError("Cannot set 'data' field in call transaction")
|
|
503
534
|
|
|
504
535
|
if self.address:
|
|
505
536
|
call_transaction.setdefault("to", self.address)
|
|
506
537
|
if self.w3.eth.default_account is not empty:
|
|
507
|
-
# type ignored b/c check prevents an empty default_account
|
|
508
538
|
call_transaction.setdefault(
|
|
509
539
|
"from",
|
|
510
|
-
self.w3.eth.default_account,
|
|
540
|
+
cast(ChecksumAddress, self.w3.eth.default_account),
|
|
511
541
|
)
|
|
512
542
|
|
|
513
543
|
if "to" not in call_transaction:
|
|
514
544
|
if isinstance(self, type):
|
|
515
|
-
raise
|
|
545
|
+
raise Web3ValueError(
|
|
516
546
|
"When using `Contract.[methodtype].[method].call()` from"
|
|
517
547
|
" a contract factory you "
|
|
518
548
|
"must provide a `to` address with the transaction"
|
|
519
549
|
)
|
|
520
550
|
else:
|
|
521
|
-
raise
|
|
551
|
+
raise Web3ValueError(
|
|
522
552
|
"Please ensure that this contract instance has an address."
|
|
523
553
|
)
|
|
524
554
|
|
|
@@ -531,24 +561,23 @@ class BaseContractFunction:
|
|
|
531
561
|
transact_transaction = cast(TxParams, dict(**transaction))
|
|
532
562
|
|
|
533
563
|
if "data" in transact_transaction:
|
|
534
|
-
raise
|
|
564
|
+
raise Web3ValueError("Cannot set 'data' field in transact transaction")
|
|
535
565
|
|
|
536
566
|
if self.address is not None:
|
|
537
567
|
transact_transaction.setdefault("to", self.address)
|
|
538
568
|
if self.w3.eth.default_account is not empty:
|
|
539
|
-
# type ignored b/c check prevents an empty default_account
|
|
540
569
|
transact_transaction.setdefault(
|
|
541
|
-
"from", self.w3.eth.default_account
|
|
570
|
+
"from", cast(ChecksumAddress, self.w3.eth.default_account)
|
|
542
571
|
)
|
|
543
572
|
|
|
544
573
|
if "to" not in transact_transaction:
|
|
545
574
|
if isinstance(self, type):
|
|
546
|
-
raise
|
|
575
|
+
raise Web3ValueError(
|
|
547
576
|
"When using `Contract.transact` from a contract factory you "
|
|
548
577
|
"must provide a `to` address with the transaction"
|
|
549
578
|
)
|
|
550
579
|
else:
|
|
551
|
-
raise
|
|
580
|
+
raise Web3ValueError(
|
|
552
581
|
"Please ensure that this contract instance has an address."
|
|
553
582
|
)
|
|
554
583
|
return transact_transaction
|
|
@@ -560,26 +589,25 @@ class BaseContractFunction:
|
|
|
560
589
|
estimate_gas_transaction = cast(TxParams, dict(**transaction))
|
|
561
590
|
|
|
562
591
|
if "data" in estimate_gas_transaction:
|
|
563
|
-
raise
|
|
592
|
+
raise Web3ValueError("Cannot set 'data' field in estimate_gas transaction")
|
|
564
593
|
if "to" in estimate_gas_transaction:
|
|
565
|
-
raise
|
|
594
|
+
raise Web3ValueError("Cannot set to in estimate_gas transaction")
|
|
566
595
|
|
|
567
596
|
if self.address:
|
|
568
597
|
estimate_gas_transaction.setdefault("to", self.address)
|
|
569
598
|
if self.w3.eth.default_account is not empty:
|
|
570
|
-
# type ignored b/c check prevents an empty default_account
|
|
571
599
|
estimate_gas_transaction.setdefault(
|
|
572
|
-
"from", self.w3.eth.default_account
|
|
600
|
+
"from", cast(ChecksumAddress, self.w3.eth.default_account)
|
|
573
601
|
)
|
|
574
602
|
|
|
575
603
|
if "to" not in estimate_gas_transaction:
|
|
576
604
|
if isinstance(self, type):
|
|
577
|
-
raise
|
|
605
|
+
raise Web3ValueError(
|
|
578
606
|
"When using `Contract.estimate_gas` from a contract factory "
|
|
579
607
|
"you must provide a `to` address with the transaction"
|
|
580
608
|
)
|
|
581
609
|
else:
|
|
582
|
-
raise
|
|
610
|
+
raise Web3ValueError(
|
|
583
611
|
"Please ensure that this contract instance has an address."
|
|
584
612
|
)
|
|
585
613
|
return estimate_gas_transaction
|
|
@@ -591,21 +619,23 @@ class BaseContractFunction:
|
|
|
591
619
|
built_transaction = cast(TxParams, dict(**transaction))
|
|
592
620
|
|
|
593
621
|
if "data" in built_transaction:
|
|
594
|
-
raise
|
|
622
|
+
raise Web3ValueError("Cannot set 'data' field in build transaction")
|
|
595
623
|
|
|
596
624
|
if not self.address and "to" not in built_transaction:
|
|
597
|
-
raise
|
|
625
|
+
raise Web3ValueError(
|
|
598
626
|
"When using `ContractFunction.build_transaction` from a contract "
|
|
599
627
|
"factory you must provide a `to` address with the transaction"
|
|
600
628
|
)
|
|
601
629
|
if self.address and "to" in built_transaction:
|
|
602
|
-
raise
|
|
630
|
+
raise Web3ValueError(
|
|
631
|
+
"Cannot set 'to' field in contract call build transaction"
|
|
632
|
+
)
|
|
603
633
|
|
|
604
634
|
if self.address:
|
|
605
635
|
built_transaction.setdefault("to", self.address)
|
|
606
636
|
|
|
607
637
|
if "to" not in built_transaction:
|
|
608
|
-
raise
|
|
638
|
+
raise Web3ValueError(
|
|
609
639
|
"Please ensure that this contract instance has an address."
|
|
610
640
|
)
|
|
611
641
|
|
|
@@ -650,7 +680,7 @@ class BaseContractFunctions:
|
|
|
650
680
|
self.address = address
|
|
651
681
|
|
|
652
682
|
if self.abi:
|
|
653
|
-
self._functions =
|
|
683
|
+
self._functions = filter_abi_by_type("function", self.abi)
|
|
654
684
|
for func in self._functions:
|
|
655
685
|
setattr(
|
|
656
686
|
self,
|
|
@@ -661,16 +691,16 @@ class BaseContractFunctions:
|
|
|
661
691
|
contract_abi=self.abi,
|
|
662
692
|
address=self.address,
|
|
663
693
|
decode_tuples=decode_tuples,
|
|
664
|
-
|
|
694
|
+
abi_element_identifier=func["name"],
|
|
665
695
|
),
|
|
666
696
|
)
|
|
667
697
|
|
|
668
|
-
def __iter__(self) ->
|
|
698
|
+
def __iter__(self) -> Iterable["ABIFunction"]:
|
|
669
699
|
if not hasattr(self, "_functions") or not self._functions:
|
|
670
700
|
return
|
|
671
701
|
|
|
672
702
|
for func in self._functions:
|
|
673
|
-
yield func["name"]
|
|
703
|
+
yield self[func["name"]]
|
|
674
704
|
|
|
675
705
|
def __getitem__(self, function_name: str) -> ABIFunction:
|
|
676
706
|
return getattr(self, function_name)
|
|
@@ -683,7 +713,8 @@ class BaseContractFunctions:
|
|
|
683
713
|
|
|
684
714
|
|
|
685
715
|
class BaseContract:
|
|
686
|
-
"""
|
|
716
|
+
"""
|
|
717
|
+
Base class for Contract proxy classes.
|
|
687
718
|
|
|
688
719
|
First you need to create your Contract classes using
|
|
689
720
|
:meth:`web3.eth.Eth.contract` that takes compiled Solidity contract
|
|
@@ -726,21 +757,10 @@ class BaseContract:
|
|
|
726
757
|
|
|
727
758
|
# Public API
|
|
728
759
|
#
|
|
729
|
-
@combomethod
|
|
730
|
-
@deprecate_method("encode_abi()")
|
|
731
|
-
def encodeABI(
|
|
732
|
-
cls,
|
|
733
|
-
fn_name: str,
|
|
734
|
-
args: Optional[Any] = None,
|
|
735
|
-
kwargs: Optional[Any] = None,
|
|
736
|
-
data: Optional[HexStr] = None,
|
|
737
|
-
) -> HexStr:
|
|
738
|
-
return cls.encode_abi(fn_name, args, kwargs, data)
|
|
739
|
-
|
|
740
760
|
@combomethod
|
|
741
761
|
def encode_abi(
|
|
742
762
|
cls,
|
|
743
|
-
|
|
763
|
+
abi_element_identifier: str,
|
|
744
764
|
args: Optional[Any] = None,
|
|
745
765
|
kwargs: Optional[Any] = None,
|
|
746
766
|
data: Optional[HexStr] = None,
|
|
@@ -751,18 +771,21 @@ class BaseContract:
|
|
|
751
771
|
|
|
752
772
|
:param data: defaults to function selector
|
|
753
773
|
"""
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
774
|
+
args = args or tuple()
|
|
775
|
+
kwargs = kwargs or {}
|
|
776
|
+
|
|
777
|
+
element_info = get_abi_element_info(
|
|
778
|
+
cls.abi,
|
|
779
|
+
abi_element_identifier,
|
|
780
|
+
*args,
|
|
781
|
+
abi_codec=cls.w3.codec,
|
|
782
|
+
**kwargs,
|
|
760
783
|
)
|
|
761
784
|
|
|
762
785
|
if data is None:
|
|
763
|
-
data =
|
|
786
|
+
data = element_info["selector"]
|
|
764
787
|
|
|
765
|
-
return encode_abi(cls.w3,
|
|
788
|
+
return encode_abi(cls.w3, element_info["abi"], element_info["arguments"], data)
|
|
766
789
|
|
|
767
790
|
@combomethod
|
|
768
791
|
def all_functions(
|
|
@@ -775,7 +798,7 @@ class BaseContract:
|
|
|
775
798
|
@combomethod
|
|
776
799
|
def get_function_by_signature(self, signature: str) -> "BaseContractFunction":
|
|
777
800
|
if " " in signature:
|
|
778
|
-
raise
|
|
801
|
+
raise Web3ValueError(
|
|
779
802
|
"Function signature should not contain any spaces. "
|
|
780
803
|
f"Found spaces in input: {signature}"
|
|
781
804
|
)
|
|
@@ -807,9 +830,9 @@ class BaseContract:
|
|
|
807
830
|
self, selector: Union[bytes, int, HexStr]
|
|
808
831
|
) -> "BaseContractFunction":
|
|
809
832
|
def callable_check(fn_abi: ABIFunction) -> bool:
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
833
|
+
return encode_hex(function_abi_to_4byte_selector(fn_abi)) == to_4byte_hex(
|
|
834
|
+
selector
|
|
835
|
+
)
|
|
813
836
|
|
|
814
837
|
fns = self.find_functions_by_identifier(
|
|
815
838
|
self.abi, self.w3, self.address, callable_check
|
|
@@ -820,9 +843,7 @@ class BaseContract:
|
|
|
820
843
|
def decode_function_input(
|
|
821
844
|
self, data: HexStr
|
|
822
845
|
) -> Tuple["BaseContractFunction", Dict[str, Any]]:
|
|
823
|
-
|
|
824
|
-
data = HexBytes(data) # type: ignore
|
|
825
|
-
func = self.get_function_by_selector(data[:4])
|
|
846
|
+
func = self.get_function_by_selector(HexBytes(data)[:4])
|
|
826
847
|
arguments = decode_transaction_data(
|
|
827
848
|
func.abi, data, normalizers=BASE_RETURN_NORMALIZERS
|
|
828
849
|
)
|
|
@@ -832,7 +853,10 @@ class BaseContract:
|
|
|
832
853
|
def find_functions_by_args(self, *args: Any) -> "BaseContractFunction":
|
|
833
854
|
def callable_check(fn_abi: ABIFunction) -> bool:
|
|
834
855
|
return check_if_arguments_can_be_encoded(
|
|
835
|
-
fn_abi,
|
|
856
|
+
fn_abi,
|
|
857
|
+
*args,
|
|
858
|
+
abi_codec=self.w3.codec,
|
|
859
|
+
**{},
|
|
836
860
|
)
|
|
837
861
|
|
|
838
862
|
return self.find_functions_by_identifier(
|
|
@@ -852,7 +876,7 @@ class BaseContract:
|
|
|
852
876
|
@classmethod
|
|
853
877
|
def _prepare_transaction(
|
|
854
878
|
cls,
|
|
855
|
-
|
|
879
|
+
abi_element_identifier: ABIElementIdentifier,
|
|
856
880
|
fn_args: Optional[Any] = None,
|
|
857
881
|
fn_kwargs: Optional[Any] = None,
|
|
858
882
|
transaction: Optional[TxParams] = None,
|
|
@@ -860,7 +884,7 @@ class BaseContract:
|
|
|
860
884
|
return prepare_transaction(
|
|
861
885
|
cls.address,
|
|
862
886
|
cls.w3,
|
|
863
|
-
|
|
887
|
+
abi_element_identifier=abi_element_identifier,
|
|
864
888
|
contract_abi=cls.abi,
|
|
865
889
|
transaction=transaction,
|
|
866
890
|
fn_args=fn_args,
|
|
@@ -870,45 +894,44 @@ class BaseContract:
|
|
|
870
894
|
@classmethod
|
|
871
895
|
def _find_matching_fn_abi(
|
|
872
896
|
cls,
|
|
873
|
-
fn_identifier: Optional[
|
|
874
|
-
args:
|
|
875
|
-
kwargs:
|
|
876
|
-
) ->
|
|
877
|
-
return
|
|
878
|
-
cls.abi,
|
|
897
|
+
fn_identifier: Optional[ABIElementIdentifier] = None,
|
|
898
|
+
*args: Sequence[Any],
|
|
899
|
+
**kwargs: Dict[str, Any],
|
|
900
|
+
) -> ABIElement:
|
|
901
|
+
return get_abi_element(
|
|
902
|
+
cls.abi,
|
|
903
|
+
fn_identifier,
|
|
904
|
+
*args,
|
|
905
|
+
abi_codec=cls.w3.codec,
|
|
906
|
+
**kwargs,
|
|
879
907
|
)
|
|
880
908
|
|
|
881
909
|
@classmethod
|
|
882
|
-
def
|
|
910
|
+
def _get_event_abi(
|
|
883
911
|
cls,
|
|
884
912
|
event_name: Optional[str] = None,
|
|
885
913
|
argument_names: Optional[Sequence[str]] = None,
|
|
886
914
|
) -> ABIEvent:
|
|
887
|
-
return
|
|
915
|
+
return get_event_abi(
|
|
888
916
|
abi=cls.abi, event_name=event_name, argument_names=argument_names
|
|
889
917
|
)
|
|
890
918
|
|
|
891
919
|
@combomethod
|
|
892
920
|
def _encode_constructor_data(
|
|
893
|
-
cls, args:
|
|
921
|
+
cls, *args: Sequence[Any], **kwargs: Dict[str, Any]
|
|
894
922
|
) -> HexStr:
|
|
895
|
-
constructor_abi =
|
|
923
|
+
constructor_abi = find_constructor_abi_element_by_type(cls.abi)
|
|
896
924
|
|
|
897
925
|
if constructor_abi:
|
|
898
|
-
|
|
899
|
-
args = tuple()
|
|
900
|
-
if kwargs is None:
|
|
901
|
-
kwargs = {}
|
|
902
|
-
|
|
903
|
-
arguments = merge_args_and_kwargs(constructor_abi, args, kwargs)
|
|
926
|
+
arguments = get_normalized_abi_inputs(constructor_abi, *args, **kwargs)
|
|
904
927
|
|
|
905
928
|
deploy_data = add_0x_prefix(
|
|
906
929
|
encode_abi(cls.w3, constructor_abi, arguments, data=cls.bytecode)
|
|
907
930
|
)
|
|
908
931
|
else:
|
|
909
|
-
if args
|
|
932
|
+
if args or kwargs:
|
|
910
933
|
msg = "Constructor args were provided, but no constructor function was provided." # noqa: E501
|
|
911
|
-
raise
|
|
934
|
+
raise Web3TypeError(msg)
|
|
912
935
|
|
|
913
936
|
deploy_data = to_hex(cls.bytecode)
|
|
914
937
|
|
|
@@ -947,7 +970,7 @@ class BaseContract:
|
|
|
947
970
|
w3=w3,
|
|
948
971
|
contract_abi=abi,
|
|
949
972
|
address=address,
|
|
950
|
-
|
|
973
|
+
abi_element_identifier=FallbackFn,
|
|
951
974
|
)()
|
|
952
975
|
|
|
953
976
|
return cast(function_type, NonExistentFallbackFunction()) # type: ignore
|
|
@@ -965,7 +988,7 @@ class BaseContract:
|
|
|
965
988
|
w3=w3,
|
|
966
989
|
contract_abi=abi,
|
|
967
990
|
address=address,
|
|
968
|
-
|
|
991
|
+
abi_element_identifier=ReceiveFn,
|
|
969
992
|
)()
|
|
970
993
|
|
|
971
994
|
return cast(function_type, NonExistentReceiveFunction()) # type: ignore
|
|
@@ -995,7 +1018,7 @@ class BaseContractCaller:
|
|
|
995
1018
|
"""
|
|
996
1019
|
|
|
997
1020
|
# mypy types
|
|
998
|
-
_functions:
|
|
1021
|
+
_functions: Sequence[ABIFunction]
|
|
999
1022
|
|
|
1000
1023
|
def __init__(
|
|
1001
1024
|
self,
|
|
@@ -1011,6 +1034,9 @@ class BaseContractCaller:
|
|
|
1011
1034
|
self._functions = []
|
|
1012
1035
|
|
|
1013
1036
|
def __getattr__(self, function_name: str) -> Any:
|
|
1037
|
+
function_names = [
|
|
1038
|
+
fn["name"] for fn in self._functions if fn.get("type") == "function"
|
|
1039
|
+
]
|
|
1014
1040
|
if self.abi is None:
|
|
1015
1041
|
raise NoABIFound(
|
|
1016
1042
|
"There is no ABI found for this contract.",
|
|
@@ -1020,8 +1046,8 @@ class BaseContractCaller:
|
|
|
1020
1046
|
"The ABI for this contract contains no function definitions. ",
|
|
1021
1047
|
"Are you sure you provided the correct contract ABI?",
|
|
1022
1048
|
)
|
|
1023
|
-
elif function_name not in
|
|
1024
|
-
functions_available = ", ".join(
|
|
1049
|
+
elif function_name not in function_names:
|
|
1050
|
+
functions_available = ", ".join(function_names)
|
|
1025
1051
|
raise ABIFunctionNotFound(
|
|
1026
1052
|
f"The function '{function_name}' was not found in this contract's ABI.",
|
|
1027
1053
|
" Here is a list of all of the function names found: ",
|
|
@@ -1075,7 +1101,7 @@ class BaseContractConstructor:
|
|
|
1075
1101
|
|
|
1076
1102
|
@combomethod
|
|
1077
1103
|
def _encode_data_in_transaction(self, *args: Any, **kwargs: Any) -> HexStr:
|
|
1078
|
-
constructor_abi =
|
|
1104
|
+
constructor_abi = find_constructor_abi_element_by_type(self.abi)
|
|
1079
1105
|
|
|
1080
1106
|
if constructor_abi:
|
|
1081
1107
|
if not args:
|
|
@@ -1083,7 +1109,8 @@ class BaseContractConstructor:
|
|
|
1083
1109
|
if not kwargs:
|
|
1084
1110
|
kwargs = {}
|
|
1085
1111
|
|
|
1086
|
-
arguments =
|
|
1112
|
+
arguments = get_normalized_abi_inputs(constructor_abi, *args, **kwargs)
|
|
1113
|
+
|
|
1087
1114
|
data = add_0x_prefix(
|
|
1088
1115
|
encode_abi(self.w3, constructor_abi, arguments, data=self.bytecode)
|
|
1089
1116
|
)
|
|
@@ -1103,9 +1130,8 @@ class BaseContractConstructor:
|
|
|
1103
1130
|
)
|
|
1104
1131
|
|
|
1105
1132
|
if self.w3.eth.default_account is not empty:
|
|
1106
|
-
# type ignored b/c check prevents an empty default_account
|
|
1107
1133
|
estimate_gas_transaction.setdefault(
|
|
1108
|
-
"from", self.w3.eth.default_account
|
|
1134
|
+
"from", cast(ChecksumAddress, self.w3.eth.default_account)
|
|
1109
1135
|
)
|
|
1110
1136
|
|
|
1111
1137
|
estimate_gas_transaction["data"] = self.data_in_transaction
|
|
@@ -1122,9 +1148,8 @@ class BaseContractConstructor:
|
|
|
1122
1148
|
)
|
|
1123
1149
|
|
|
1124
1150
|
if self.w3.eth.default_account is not empty:
|
|
1125
|
-
# type ignored b/c check prevents an empty default_account
|
|
1126
1151
|
transact_transaction.setdefault(
|
|
1127
|
-
"from", self.w3.eth.default_account
|
|
1152
|
+
"from", cast(ChecksumAddress, self.w3.eth.default_account)
|
|
1128
1153
|
)
|
|
1129
1154
|
|
|
1130
1155
|
transact_transaction["data"] = self.data_in_transaction
|
|
@@ -1143,7 +1168,7 @@ class BaseContractConstructor:
|
|
|
1143
1168
|
) -> None:
|
|
1144
1169
|
keys_found = transaction.keys() & forbidden_keys
|
|
1145
1170
|
if keys_found:
|
|
1146
|
-
raise
|
|
1171
|
+
raise Web3ValueError(
|
|
1147
1172
|
f"Cannot set '{', '.join(keys_found)}' field(s) in transaction"
|
|
1148
1173
|
)
|
|
1149
1174
|
|
|
@@ -1151,7 +1176,7 @@ class BaseContractConstructor:
|
|
|
1151
1176
|
class NonExistentFallbackFunction:
|
|
1152
1177
|
@staticmethod
|
|
1153
1178
|
def _raise_exception() -> NoReturn:
|
|
1154
|
-
raise
|
|
1179
|
+
raise ABIFallbackNotFound("No fallback function was found in the contract ABI.")
|
|
1155
1180
|
|
|
1156
1181
|
def __getattr__(self, attr: Any) -> Callable[[], None]:
|
|
1157
1182
|
return self._raise_exception
|
|
@@ -1160,7 +1185,7 @@ class NonExistentFallbackFunction:
|
|
|
1160
1185
|
class NonExistentReceiveFunction:
|
|
1161
1186
|
@staticmethod
|
|
1162
1187
|
def _raise_exception() -> NoReturn:
|
|
1163
|
-
raise
|
|
1188
|
+
raise ABIReceiveNotFound("No receive function was found in the contract ABI.")
|
|
1164
1189
|
|
|
1165
1190
|
def __getattr__(self, attr: Any) -> Callable[[], None]:
|
|
1166
1191
|
return self._raise_exception
|