Skip to content

Commit 2df6140

Browse files
committed
Make sure all methods got ported to the new layout
1 parent f242d15 commit 2df6140

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed

web3/contract/async_contract.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
async_estimate_gas_for_function,
5959
async_transact_with_contract_function,
6060
find_functions_by_identifier,
61+
get_function_by_identifier,
6162
)
6263
from web3.types import ( # noqa: F401
6364
ABI,
@@ -191,6 +192,12 @@ def find_functions_by_identifier(
191192
contract_abi, w3, address, callable_check, AsyncContractFunction
192193
)
193194

195+
@combomethod
196+
def get_function_by_identifier(
197+
cls, fns: Sequence[BaseContractFunction], identifier: str
198+
) -> BaseContractFunction:
199+
return get_function_by_identifier(fns, identifier)
200+
194201

195202
class AsyncContractConstructor(BaseContractConstructor):
196203
@combomethod

web3/contract/base_contract.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
NoABIEventsFound,
100100
NoABIFound,
101101
NoABIFunctionsFound,
102-
ValidationError,
102+
Web3ValidationError,
103103
)
104104
from web3.logs import (
105105
DISCARD,
@@ -218,7 +218,7 @@ def callable_check(fn_abi: ABIFunction) -> bool:
218218
fns = self.find_functions_by_identifier(
219219
self.abi, self.w3, self.address, callable_check
220220
)
221-
return get_function_by_identifier(fns, "signature")
221+
return self.get_function_by_identifier(fns, "signature")
222222

223223
@combomethod
224224
def find_functions_by_name(self, fn_name: str) -> "BaseContractFunction":
@@ -232,7 +232,7 @@ def callable_check(fn_abi: ABIFunction) -> bool:
232232
@combomethod
233233
def get_function_by_name(self, fn_name: str) -> "BaseContractFunction":
234234
fns = self.find_functions_by_name(fn_name)
235-
return get_function_by_identifier(fns, "name")
235+
return self.get_function_by_identifier(fns, "name")
236236

237237
@combomethod
238238
def get_function_by_selector(
@@ -246,7 +246,7 @@ def callable_check(fn_abi: ABIFunction) -> bool:
246246
fns = self.find_functions_by_identifier(
247247
self.abi, self.w3, self.address, callable_check
248248
)
249-
return get_function_by_identifier(fns, "selector")
249+
return self.get_function_by_identifier(fns, "selector")
250250

251251
@combomethod
252252
def decode_function_input(
@@ -279,7 +279,7 @@ def callable_check(fn_abi: ABIFunction) -> bool:
279279
@combomethod
280280
def get_function_by_args(self, *args: Any) -> "BaseContractFunction":
281281
fns = self.find_functions_by_args(*args)
282-
return get_function_by_identifier(fns, "args")
282+
return self.get_function_by_identifier(fns, "args")
283283

284284
#
285285
# Private Helpers
@@ -364,6 +364,14 @@ def find_functions_by_identifier(
364364
"This method should be implemented in the inherited class"
365365
)
366366

367+
@combomethod
368+
def get_function_by_identifier(
369+
cls, fns: Sequence["BaseContractFunction"], identifier: str
370+
) -> "BaseContractFunction":
371+
raise NotImplementedError(
372+
"This method should be implemented in the inherited class"
373+
)
374+
367375
@staticmethod
368376
def get_fallback_function(
369377
abi: ABI,
@@ -947,7 +955,7 @@ def _get_event_filter_params(
947955
blkhash_set = blockHash is not None
948956
blknum_set = fromBlock is not None or toBlock is not None
949957
if blkhash_set and blknum_set:
950-
raise ValidationError(
958+
raise Web3ValidationError(
951959
"blockHash cannot be set at the same time as fromBlock or toBlock"
952960
)
953961

@@ -972,6 +980,26 @@ def _get_event_filter_params(
972980
def factory(cls, class_name: str, **kwargs: Any) -> PropertyCheckingFactory:
973981
return PropertyCheckingFactory(class_name, (cls,), kwargs)
974982

983+
@staticmethod
984+
def check_for_forbidden_api_filter_arguments(
985+
event_abi: ABIEvent, _filters: Dict[str, Any]
986+
) -> None:
987+
name_indexed_inputs = {_input["name"]: _input for _input in event_abi["inputs"]}
988+
989+
for filter_name, filter_value in _filters.items():
990+
_input = name_indexed_inputs[filter_name]
991+
if is_array_type(_input["type"]):
992+
raise TypeError(
993+
"createFilter no longer supports array type filter arguments. "
994+
"see the build_filter method for filtering array type filters."
995+
)
996+
if is_list_like(filter_value) and is_dynamic_sized_type(_input["type"]):
997+
raise TypeError(
998+
"createFilter no longer supports setting filter argument options "
999+
"for dynamic sized types. See the build_filter method for setting "
1000+
"filters with the match_any method."
1001+
)
1002+
9751003
@combomethod
9761004
def _set_up_filter_builder(
9771005
self,
@@ -994,7 +1022,7 @@ def _set_up_filter_builder(
9941022

9951023
event_abi = self._get_event_abi()
9961024

997-
check_for_forbidden_api_filter_arguments(event_abi, _filters)
1025+
self.check_for_forbidden_api_filter_arguments(event_abi, _filters)
9981026

9991027
_, event_filter_params = construct_event_filter_params(
10001028
self._get_event_abi(),
@@ -1137,35 +1165,3 @@ def call_function(
11371165
block_identifier=block_identifier,
11381166
ccip_read_enabled=ccip_read_enabled,
11391167
)
1140-
1141-
1142-
def check_for_forbidden_api_filter_arguments(
1143-
event_abi: ABIEvent, _filters: Dict[str, Any]
1144-
) -> None:
1145-
name_indexed_inputs = {_input["name"]: _input for _input in event_abi["inputs"]}
1146-
1147-
for filter_name, filter_value in _filters.items():
1148-
_input = name_indexed_inputs[filter_name]
1149-
if is_array_type(_input["type"]):
1150-
raise TypeError(
1151-
"createFilter no longer supports array type filter arguments. "
1152-
"see the build_filter method for filtering array type filters."
1153-
)
1154-
if is_list_like(filter_value) and is_dynamic_sized_type(_input["type"]):
1155-
raise TypeError(
1156-
"createFilter no longer supports setting filter argument options for "
1157-
"dynamic sized types. See the build_filter method for setting "
1158-
"filters with the match_any method."
1159-
)
1160-
1161-
1162-
def get_function_by_identifier(
1163-
fns: Sequence[BaseContractFunction], identifier: str
1164-
) -> BaseContractFunction:
1165-
if len(fns) > 1:
1166-
raise ValueError(
1167-
f"Found multiple functions with matching {identifier}. " f"Found: {fns!r}"
1168-
)
1169-
elif len(fns) == 0:
1170-
raise ValueError(f"Could not find any function with matching {identifier}")
1171-
return fns[0]

web3/contract/contract.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
call_contract_function,
5858
estimate_gas_for_function,
5959
find_functions_by_identifier,
60+
get_function_by_identifier,
6061
transact_with_contract_function,
6162
)
6263
from web3.types import ( # noqa: F401
@@ -312,6 +313,12 @@ def find_functions_by_identifier(
312313
contract_abi, w3, address, callable_check, ContractFunction
313314
)
314315

316+
@combomethod
317+
def get_function_by_identifier(
318+
cls, fns: Sequence[BaseContractFunction], identifier: str
319+
) -> BaseContractFunction:
320+
return get_function_by_identifier(fns, identifier)
321+
315322

316323
class ContractConstructor(BaseContractConstructor):
317324
@combomethod

web3/contract/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Callable,
66
List,
77
Optional,
8+
Sequence,
89
Tuple,
910
Type,
1011
)
@@ -246,6 +247,18 @@ def find_functions_by_identifier(
246247
]
247248

248249

250+
def get_function_by_identifier(
251+
fns: Sequence[BaseContractFunction], identifier: str
252+
) -> BaseContractFunction:
253+
if len(fns) > 1:
254+
raise ValueError(
255+
f"Found multiple functions with matching {identifier}. " f"Found: {fns!r}"
256+
)
257+
elif len(fns) == 0:
258+
raise ValueError(f"Could not find any function with matching {identifier}")
259+
return fns[0]
260+
261+
249262
# --- async --- #
250263

251264

0 commit comments

Comments
 (0)