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/utils.py
CHANGED
|
@@ -9,21 +9,32 @@ from typing import (
|
|
|
9
9
|
Tuple,
|
|
10
10
|
Type,
|
|
11
11
|
Union,
|
|
12
|
+
cast,
|
|
12
13
|
)
|
|
13
14
|
|
|
14
15
|
from eth_abi.exceptions import (
|
|
15
16
|
DecodingError,
|
|
16
17
|
)
|
|
17
18
|
from eth_typing import (
|
|
19
|
+
ABI,
|
|
20
|
+
ABICallable,
|
|
21
|
+
ABIFunction,
|
|
18
22
|
ChecksumAddress,
|
|
23
|
+
TypeStr,
|
|
24
|
+
)
|
|
25
|
+
from eth_utils.abi import (
|
|
26
|
+
filter_abi_by_type,
|
|
27
|
+
get_abi_output_types,
|
|
28
|
+
)
|
|
29
|
+
from eth_utils.toolz import (
|
|
30
|
+
compose,
|
|
31
|
+
curry,
|
|
19
32
|
)
|
|
20
33
|
from hexbytes import (
|
|
21
34
|
HexBytes,
|
|
22
35
|
)
|
|
23
36
|
|
|
24
37
|
from web3._utils.abi import (
|
|
25
|
-
filter_by_type,
|
|
26
|
-
get_abi_output_types,
|
|
27
38
|
map_abi_data,
|
|
28
39
|
named_tree,
|
|
29
40
|
recursive_dict_to_namedtuple,
|
|
@@ -31,8 +42,10 @@ from web3._utils.abi import (
|
|
|
31
42
|
from web3._utils.async_transactions import (
|
|
32
43
|
async_fill_transaction_defaults,
|
|
33
44
|
)
|
|
45
|
+
from web3._utils.compat import (
|
|
46
|
+
TypeAlias,
|
|
47
|
+
)
|
|
34
48
|
from web3._utils.contracts import (
|
|
35
|
-
find_matching_fn_abi,
|
|
36
49
|
prepare_transaction,
|
|
37
50
|
)
|
|
38
51
|
from web3._utils.normalizers import (
|
|
@@ -43,36 +56,79 @@ from web3._utils.transactions import (
|
|
|
43
56
|
)
|
|
44
57
|
from web3.exceptions import (
|
|
45
58
|
BadFunctionCallOutput,
|
|
59
|
+
Web3ValueError,
|
|
46
60
|
)
|
|
47
61
|
from web3.types import (
|
|
48
|
-
|
|
49
|
-
ABIFunction,
|
|
62
|
+
ABIElementIdentifier,
|
|
50
63
|
BlockIdentifier,
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
RPCEndpoint,
|
|
65
|
+
StateOverride,
|
|
53
66
|
TContractFn,
|
|
54
67
|
TxParams,
|
|
55
68
|
)
|
|
69
|
+
from web3.utils.abi import (
|
|
70
|
+
get_abi_element,
|
|
71
|
+
)
|
|
56
72
|
|
|
57
73
|
if TYPE_CHECKING:
|
|
58
74
|
from web3 import ( # noqa: F401
|
|
59
75
|
AsyncWeb3,
|
|
60
76
|
Web3,
|
|
61
77
|
)
|
|
78
|
+
from web3.providers.persistent import ( # noqa: F401
|
|
79
|
+
PersistentConnectionProvider,
|
|
80
|
+
)
|
|
62
81
|
|
|
63
82
|
ACCEPTABLE_EMPTY_STRINGS = ["0x", b"0x", "", b""]
|
|
64
83
|
|
|
65
84
|
|
|
85
|
+
@curry
|
|
86
|
+
def format_contract_call_return_data_curried(
|
|
87
|
+
async_w3: Union["AsyncWeb3", "Web3"],
|
|
88
|
+
decode_tuples: bool,
|
|
89
|
+
fn_abi: ABICallable,
|
|
90
|
+
abi_element_identifier: ABIElementIdentifier,
|
|
91
|
+
normalizers: Tuple[Callable[..., Any], ...],
|
|
92
|
+
output_types: Sequence[TypeStr],
|
|
93
|
+
return_data: Any,
|
|
94
|
+
) -> Any:
|
|
95
|
+
"""
|
|
96
|
+
Helper function for formatting contract call return data for batch requests. Curry
|
|
97
|
+
with all arguments except `return_data` and process `return_data` once it is
|
|
98
|
+
available.
|
|
99
|
+
"""
|
|
100
|
+
try:
|
|
101
|
+
output_data = async_w3.codec.decode(output_types, return_data)
|
|
102
|
+
except DecodingError as e:
|
|
103
|
+
msg = (
|
|
104
|
+
f"Could not decode contract function call to {abi_element_identifier} "
|
|
105
|
+
f"with return data: {str(return_data)}, output_types: {output_types}"
|
|
106
|
+
)
|
|
107
|
+
raise BadFunctionCallOutput(msg) from e
|
|
108
|
+
|
|
109
|
+
_normalizers = itertools.chain(
|
|
110
|
+
BASE_RETURN_NORMALIZERS,
|
|
111
|
+
normalizers,
|
|
112
|
+
)
|
|
113
|
+
normalized_data = map_abi_data(_normalizers, output_types, output_data)
|
|
114
|
+
|
|
115
|
+
if decode_tuples and fn_abi["type"] == "function":
|
|
116
|
+
decoded = named_tree(fn_abi["outputs"], normalized_data)
|
|
117
|
+
normalized_data = recursive_dict_to_namedtuple(decoded)
|
|
118
|
+
|
|
119
|
+
return normalized_data[0] if len(normalized_data) == 1 else normalized_data
|
|
120
|
+
|
|
121
|
+
|
|
66
122
|
def call_contract_function(
|
|
67
123
|
w3: "Web3",
|
|
68
124
|
address: ChecksumAddress,
|
|
69
125
|
normalizers: Tuple[Callable[..., Any], ...],
|
|
70
|
-
|
|
126
|
+
abi_element_identifier: ABIElementIdentifier,
|
|
71
127
|
transaction: TxParams,
|
|
72
128
|
block_id: Optional[BlockIdentifier] = None,
|
|
73
129
|
contract_abi: Optional[ABI] = None,
|
|
74
|
-
|
|
75
|
-
state_override: Optional[
|
|
130
|
+
abi_callable: Optional[ABICallable] = None,
|
|
131
|
+
state_override: Optional[StateOverride] = None,
|
|
76
132
|
ccip_read_enabled: Optional[bool] = None,
|
|
77
133
|
decode_tuples: Optional[bool] = False,
|
|
78
134
|
*args: Any,
|
|
@@ -85,9 +141,9 @@ def call_contract_function(
|
|
|
85
141
|
call_transaction = prepare_transaction(
|
|
86
142
|
address,
|
|
87
143
|
w3,
|
|
88
|
-
|
|
144
|
+
abi_element_identifier=abi_element_identifier,
|
|
89
145
|
contract_abi=contract_abi,
|
|
90
|
-
|
|
146
|
+
abi_callable=abi_callable,
|
|
91
147
|
transaction=transaction,
|
|
92
148
|
fn_args=args,
|
|
93
149
|
fn_kwargs=kwargs,
|
|
@@ -100,12 +156,50 @@ def call_contract_function(
|
|
|
100
156
|
ccip_read_enabled=ccip_read_enabled,
|
|
101
157
|
)
|
|
102
158
|
|
|
103
|
-
if
|
|
104
|
-
|
|
105
|
-
|
|
159
|
+
if abi_callable is None:
|
|
160
|
+
abi_callable = cast(
|
|
161
|
+
ABIFunction,
|
|
162
|
+
get_abi_element(
|
|
163
|
+
contract_abi,
|
|
164
|
+
abi_element_identifier,
|
|
165
|
+
*args,
|
|
166
|
+
abi_codec=w3.codec,
|
|
167
|
+
**kwargs,
|
|
168
|
+
),
|
|
106
169
|
)
|
|
107
170
|
|
|
108
|
-
|
|
171
|
+
# get the output types, which only exist for function types
|
|
172
|
+
output_types = []
|
|
173
|
+
if abi_callable["type"] == "function":
|
|
174
|
+
output_types = get_abi_output_types(abi_callable)
|
|
175
|
+
|
|
176
|
+
provider = w3.provider
|
|
177
|
+
if hasattr(provider, "_is_batching") and provider._is_batching:
|
|
178
|
+
BatchingReturnData: TypeAlias = Tuple[Tuple[RPCEndpoint, Any], Tuple[Any, ...]]
|
|
179
|
+
request_information = tuple(cast(BatchingReturnData, return_data))
|
|
180
|
+
method_and_params = request_information[0]
|
|
181
|
+
|
|
182
|
+
# append return data formatting to result formatters
|
|
183
|
+
current_response_formatters = request_information[1]
|
|
184
|
+
current_result_formatters = current_response_formatters[0]
|
|
185
|
+
updated_result_formatters = compose(
|
|
186
|
+
# contract call return data formatter
|
|
187
|
+
format_contract_call_return_data_curried(
|
|
188
|
+
w3,
|
|
189
|
+
decode_tuples,
|
|
190
|
+
abi_callable,
|
|
191
|
+
abi_element_identifier,
|
|
192
|
+
normalizers,
|
|
193
|
+
output_types,
|
|
194
|
+
),
|
|
195
|
+
current_result_formatters,
|
|
196
|
+
)
|
|
197
|
+
response_formatters = (
|
|
198
|
+
updated_result_formatters, # result formatters
|
|
199
|
+
current_response_formatters[1], # error formatters
|
|
200
|
+
current_response_formatters[2], # null result formatters
|
|
201
|
+
)
|
|
202
|
+
return (method_and_params, response_formatters)
|
|
109
203
|
|
|
110
204
|
try:
|
|
111
205
|
output_data = w3.codec.decode(output_types, return_data)
|
|
@@ -123,7 +217,7 @@ def call_contract_function(
|
|
|
123
217
|
)
|
|
124
218
|
else:
|
|
125
219
|
msg = (
|
|
126
|
-
f"Could not decode contract function call to {
|
|
220
|
+
f"Could not decode contract function call to {abi_element_identifier} "
|
|
127
221
|
f"with return data: {str(return_data)}, output_types: {output_types}"
|
|
128
222
|
)
|
|
129
223
|
raise BadFunctionCallOutput(msg) from e
|
|
@@ -134,8 +228,8 @@ def call_contract_function(
|
|
|
134
228
|
)
|
|
135
229
|
normalized_data = map_abi_data(_normalizers, output_types, output_data)
|
|
136
230
|
|
|
137
|
-
if decode_tuples:
|
|
138
|
-
decoded = named_tree(
|
|
231
|
+
if decode_tuples and abi_callable["type"] == "function":
|
|
232
|
+
decoded = named_tree(abi_callable["outputs"], normalized_data)
|
|
139
233
|
normalized_data = recursive_dict_to_namedtuple(decoded)
|
|
140
234
|
|
|
141
235
|
if len(normalized_data) == 1:
|
|
@@ -147,7 +241,7 @@ def call_contract_function(
|
|
|
147
241
|
def transact_with_contract_function(
|
|
148
242
|
address: ChecksumAddress,
|
|
149
243
|
w3: "Web3",
|
|
150
|
-
|
|
244
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
151
245
|
transaction: Optional[TxParams] = None,
|
|
152
246
|
contract_abi: Optional[ABI] = None,
|
|
153
247
|
fn_abi: Optional[ABIFunction] = None,
|
|
@@ -161,10 +255,10 @@ def transact_with_contract_function(
|
|
|
161
255
|
transact_transaction = prepare_transaction(
|
|
162
256
|
address,
|
|
163
257
|
w3,
|
|
164
|
-
|
|
258
|
+
abi_element_identifier=abi_element_identifier,
|
|
165
259
|
contract_abi=contract_abi,
|
|
166
260
|
transaction=transaction,
|
|
167
|
-
|
|
261
|
+
abi_callable=fn_abi,
|
|
168
262
|
fn_args=args,
|
|
169
263
|
fn_kwargs=kwargs,
|
|
170
264
|
)
|
|
@@ -176,16 +270,17 @@ def transact_with_contract_function(
|
|
|
176
270
|
def estimate_gas_for_function(
|
|
177
271
|
address: ChecksumAddress,
|
|
178
272
|
w3: "Web3",
|
|
179
|
-
|
|
273
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
180
274
|
transaction: Optional[TxParams] = None,
|
|
181
275
|
contract_abi: Optional[ABI] = None,
|
|
182
276
|
fn_abi: Optional[ABIFunction] = None,
|
|
183
277
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
184
|
-
state_override: Optional[
|
|
278
|
+
state_override: Optional[StateOverride] = None,
|
|
185
279
|
*args: Any,
|
|
186
280
|
**kwargs: Any,
|
|
187
281
|
) -> int:
|
|
188
|
-
"""
|
|
282
|
+
"""
|
|
283
|
+
Estimates gas cost a function call would take.
|
|
189
284
|
|
|
190
285
|
Don't call this directly, instead use :meth:`Contract.estimate_gas`
|
|
191
286
|
on your contract instance.
|
|
@@ -193,9 +288,9 @@ def estimate_gas_for_function(
|
|
|
193
288
|
estimate_transaction = prepare_transaction(
|
|
194
289
|
address,
|
|
195
290
|
w3,
|
|
196
|
-
|
|
291
|
+
abi_element_identifier=abi_element_identifier,
|
|
197
292
|
contract_abi=contract_abi,
|
|
198
|
-
|
|
293
|
+
abi_callable=fn_abi,
|
|
199
294
|
transaction=transaction,
|
|
200
295
|
fn_args=args,
|
|
201
296
|
fn_kwargs=kwargs,
|
|
@@ -207,14 +302,15 @@ def estimate_gas_for_function(
|
|
|
207
302
|
def build_transaction_for_function(
|
|
208
303
|
address: ChecksumAddress,
|
|
209
304
|
w3: "Web3",
|
|
210
|
-
|
|
305
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
211
306
|
transaction: Optional[TxParams] = None,
|
|
212
307
|
contract_abi: Optional[ABI] = None,
|
|
213
308
|
fn_abi: Optional[ABIFunction] = None,
|
|
214
309
|
*args: Any,
|
|
215
310
|
**kwargs: Any,
|
|
216
311
|
) -> TxParams:
|
|
217
|
-
"""
|
|
312
|
+
"""
|
|
313
|
+
Builds a dictionary with the fields required to make the given transaction
|
|
218
314
|
|
|
219
315
|
Don't call this directly, instead use :meth:`Contract.build_transaction`
|
|
220
316
|
on your contract instance.
|
|
@@ -222,9 +318,9 @@ def build_transaction_for_function(
|
|
|
222
318
|
prepared_transaction = prepare_transaction(
|
|
223
319
|
address,
|
|
224
320
|
w3,
|
|
225
|
-
|
|
321
|
+
abi_element_identifier=abi_element_identifier,
|
|
226
322
|
contract_abi=contract_abi,
|
|
227
|
-
|
|
323
|
+
abi_callable=fn_abi,
|
|
228
324
|
transaction=transaction,
|
|
229
325
|
fn_args=args,
|
|
230
326
|
fn_kwargs=kwargs,
|
|
@@ -242,14 +338,14 @@ def find_functions_by_identifier(
|
|
|
242
338
|
callable_check: Callable[..., Any],
|
|
243
339
|
function_type: Type[TContractFn],
|
|
244
340
|
) -> List[TContractFn]:
|
|
245
|
-
fns_abi =
|
|
341
|
+
fns_abi = filter_abi_by_type("function", contract_abi)
|
|
246
342
|
return [
|
|
247
343
|
function_type.factory(
|
|
248
344
|
fn_abi["name"],
|
|
249
345
|
w3=w3,
|
|
250
346
|
contract_abi=contract_abi,
|
|
251
347
|
address=address,
|
|
252
|
-
|
|
348
|
+
abi_element_identifier=fn_abi["name"],
|
|
253
349
|
abi=fn_abi,
|
|
254
350
|
)
|
|
255
351
|
for fn_abi in fns_abi
|
|
@@ -261,11 +357,11 @@ def get_function_by_identifier(
|
|
|
261
357
|
fns: Sequence[TContractFn], identifier: str
|
|
262
358
|
) -> TContractFn:
|
|
263
359
|
if len(fns) > 1:
|
|
264
|
-
raise
|
|
360
|
+
raise Web3ValueError(
|
|
265
361
|
f"Found multiple functions with matching {identifier}. " f"Found: {fns!r}"
|
|
266
362
|
)
|
|
267
363
|
elif len(fns) == 0:
|
|
268
|
-
raise
|
|
364
|
+
raise Web3ValueError(f"Could not find any function with matching {identifier}")
|
|
269
365
|
return fns[0]
|
|
270
366
|
|
|
271
367
|
|
|
@@ -276,12 +372,12 @@ async def async_call_contract_function(
|
|
|
276
372
|
async_w3: "AsyncWeb3",
|
|
277
373
|
address: ChecksumAddress,
|
|
278
374
|
normalizers: Tuple[Callable[..., Any], ...],
|
|
279
|
-
|
|
375
|
+
abi_element_identifier: ABIElementIdentifier,
|
|
280
376
|
transaction: TxParams,
|
|
281
377
|
block_id: Optional[BlockIdentifier] = None,
|
|
282
378
|
contract_abi: Optional[ABI] = None,
|
|
283
379
|
fn_abi: Optional[ABIFunction] = None,
|
|
284
|
-
state_override: Optional[
|
|
380
|
+
state_override: Optional[StateOverride] = None,
|
|
285
381
|
ccip_read_enabled: Optional[bool] = None,
|
|
286
382
|
decode_tuples: Optional[bool] = False,
|
|
287
383
|
*args: Any,
|
|
@@ -294,9 +390,9 @@ async def async_call_contract_function(
|
|
|
294
390
|
call_transaction = prepare_transaction(
|
|
295
391
|
address,
|
|
296
392
|
async_w3,
|
|
297
|
-
|
|
393
|
+
abi_element_identifier=abi_element_identifier,
|
|
298
394
|
contract_abi=contract_abi,
|
|
299
|
-
|
|
395
|
+
abi_callable=fn_abi,
|
|
300
396
|
transaction=transaction,
|
|
301
397
|
fn_args=args,
|
|
302
398
|
fn_kwargs=kwargs,
|
|
@@ -310,11 +406,60 @@ async def async_call_contract_function(
|
|
|
310
406
|
)
|
|
311
407
|
|
|
312
408
|
if fn_abi is None:
|
|
313
|
-
fn_abi =
|
|
314
|
-
|
|
409
|
+
fn_abi = cast(
|
|
410
|
+
ABIFunction,
|
|
411
|
+
get_abi_element(
|
|
412
|
+
contract_abi,
|
|
413
|
+
abi_element_identifier,
|
|
414
|
+
*args,
|
|
415
|
+
abi_codec=async_w3.codec,
|
|
416
|
+
**kwargs,
|
|
417
|
+
),
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
# get the output types, which only exist for function types
|
|
421
|
+
output_types = []
|
|
422
|
+
if fn_abi["type"] == "function":
|
|
423
|
+
output_types = get_abi_output_types(fn_abi)
|
|
424
|
+
|
|
425
|
+
if async_w3.provider._is_batching:
|
|
426
|
+
contract_call_return_data_formatter = format_contract_call_return_data_curried(
|
|
427
|
+
async_w3,
|
|
428
|
+
decode_tuples,
|
|
429
|
+
fn_abi,
|
|
430
|
+
abi_element_identifier,
|
|
431
|
+
normalizers,
|
|
432
|
+
output_types,
|
|
315
433
|
)
|
|
434
|
+
if async_w3.provider.has_persistent_connection:
|
|
435
|
+
# get the current request id
|
|
436
|
+
provider = cast("PersistentConnectionProvider", async_w3.provider)
|
|
437
|
+
current_request_id = provider._batch_request_counter - 1
|
|
438
|
+
provider._request_processor.append_result_formatter_for_request(
|
|
439
|
+
current_request_id, contract_call_return_data_formatter
|
|
440
|
+
)
|
|
441
|
+
else:
|
|
442
|
+
BatchingReturnData: TypeAlias = Tuple[
|
|
443
|
+
Tuple[RPCEndpoint, Any], Tuple[Any, ...]
|
|
444
|
+
]
|
|
445
|
+
request_information = tuple(cast(BatchingReturnData, return_data))
|
|
446
|
+
method_and_params = request_information[0]
|
|
447
|
+
|
|
448
|
+
# append return data formatter to result formatters
|
|
449
|
+
current_response_formatters = request_information[1]
|
|
450
|
+
current_result_formatters = current_response_formatters[0]
|
|
451
|
+
updated_result_formatters = compose(
|
|
452
|
+
contract_call_return_data_formatter,
|
|
453
|
+
current_result_formatters,
|
|
454
|
+
)
|
|
455
|
+
response_formatters = (
|
|
456
|
+
updated_result_formatters, # result formatters
|
|
457
|
+
current_response_formatters[1], # error formatters
|
|
458
|
+
current_response_formatters[2], # null result formatters
|
|
459
|
+
)
|
|
460
|
+
return (method_and_params, response_formatters)
|
|
316
461
|
|
|
317
|
-
|
|
462
|
+
return return_data
|
|
318
463
|
|
|
319
464
|
try:
|
|
320
465
|
output_data = async_w3.codec.decode(output_types, return_data)
|
|
@@ -332,7 +477,7 @@ async def async_call_contract_function(
|
|
|
332
477
|
)
|
|
333
478
|
else:
|
|
334
479
|
msg = (
|
|
335
|
-
f"Could not decode contract function call to {
|
|
480
|
+
f"Could not decode contract function call to {abi_element_identifier} "
|
|
336
481
|
f"with return data: {str(return_data)}, output_types: {output_types}"
|
|
337
482
|
)
|
|
338
483
|
raise BadFunctionCallOutput(msg) from e
|
|
@@ -347,16 +492,13 @@ async def async_call_contract_function(
|
|
|
347
492
|
decoded = named_tree(fn_abi["outputs"], normalized_data)
|
|
348
493
|
normalized_data = recursive_dict_to_namedtuple(decoded)
|
|
349
494
|
|
|
350
|
-
if len(normalized_data) == 1
|
|
351
|
-
return normalized_data[0]
|
|
352
|
-
else:
|
|
353
|
-
return normalized_data
|
|
495
|
+
return normalized_data[0] if len(normalized_data) == 1 else normalized_data
|
|
354
496
|
|
|
355
497
|
|
|
356
498
|
async def async_transact_with_contract_function(
|
|
357
499
|
address: ChecksumAddress,
|
|
358
500
|
async_w3: "AsyncWeb3",
|
|
359
|
-
|
|
501
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
360
502
|
transaction: Optional[TxParams] = None,
|
|
361
503
|
contract_abi: Optional[ABI] = None,
|
|
362
504
|
fn_abi: Optional[ABIFunction] = None,
|
|
@@ -370,10 +512,10 @@ async def async_transact_with_contract_function(
|
|
|
370
512
|
transact_transaction = prepare_transaction(
|
|
371
513
|
address,
|
|
372
514
|
async_w3,
|
|
373
|
-
|
|
515
|
+
abi_element_identifier=abi_element_identifier,
|
|
374
516
|
contract_abi=contract_abi,
|
|
375
517
|
transaction=transaction,
|
|
376
|
-
|
|
518
|
+
abi_callable=fn_abi,
|
|
377
519
|
fn_args=args,
|
|
378
520
|
fn_kwargs=kwargs,
|
|
379
521
|
)
|
|
@@ -385,16 +527,17 @@ async def async_transact_with_contract_function(
|
|
|
385
527
|
async def async_estimate_gas_for_function(
|
|
386
528
|
address: ChecksumAddress,
|
|
387
529
|
async_w3: "AsyncWeb3",
|
|
388
|
-
|
|
530
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
389
531
|
transaction: Optional[TxParams] = None,
|
|
390
532
|
contract_abi: Optional[ABI] = None,
|
|
391
533
|
fn_abi: Optional[ABIFunction] = None,
|
|
392
534
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
393
|
-
state_override: Optional[
|
|
535
|
+
state_override: Optional[StateOverride] = None,
|
|
394
536
|
*args: Any,
|
|
395
537
|
**kwargs: Any,
|
|
396
538
|
) -> int:
|
|
397
|
-
"""
|
|
539
|
+
"""
|
|
540
|
+
Estimates gas cost a function call would take.
|
|
398
541
|
|
|
399
542
|
Don't call this directly, instead use :meth:`Contract.estimate_gas`
|
|
400
543
|
on your contract instance.
|
|
@@ -402,9 +545,9 @@ async def async_estimate_gas_for_function(
|
|
|
402
545
|
estimate_transaction = prepare_transaction(
|
|
403
546
|
address,
|
|
404
547
|
async_w3,
|
|
405
|
-
|
|
548
|
+
abi_element_identifier=abi_element_identifier,
|
|
406
549
|
contract_abi=contract_abi,
|
|
407
|
-
|
|
550
|
+
abi_callable=fn_abi,
|
|
408
551
|
transaction=transaction,
|
|
409
552
|
fn_args=args,
|
|
410
553
|
fn_kwargs=kwargs,
|
|
@@ -418,14 +561,15 @@ async def async_estimate_gas_for_function(
|
|
|
418
561
|
async def async_build_transaction_for_function(
|
|
419
562
|
address: ChecksumAddress,
|
|
420
563
|
async_w3: "AsyncWeb3",
|
|
421
|
-
|
|
564
|
+
abi_element_identifier: Optional[ABIElementIdentifier] = None,
|
|
422
565
|
transaction: Optional[TxParams] = None,
|
|
423
566
|
contract_abi: Optional[ABI] = None,
|
|
424
567
|
fn_abi: Optional[ABIFunction] = None,
|
|
425
568
|
*args: Any,
|
|
426
569
|
**kwargs: Any,
|
|
427
570
|
) -> TxParams:
|
|
428
|
-
"""
|
|
571
|
+
"""
|
|
572
|
+
Builds a dictionary with the fields required to make the given transaction
|
|
429
573
|
|
|
430
574
|
Don't call this directly, instead use :meth:`Contract.build_transaction`
|
|
431
575
|
on your contract instance.
|
|
@@ -433,9 +577,9 @@ async def async_build_transaction_for_function(
|
|
|
433
577
|
prepared_transaction = prepare_transaction(
|
|
434
578
|
address,
|
|
435
579
|
async_w3,
|
|
436
|
-
|
|
580
|
+
abi_element_identifier=abi_element_identifier,
|
|
437
581
|
contract_abi=contract_abi,
|
|
438
|
-
|
|
582
|
+
abi_callable=fn_abi,
|
|
439
583
|
transaction=transaction,
|
|
440
584
|
fn_args=args,
|
|
441
585
|
fn_kwargs=kwargs,
|