web3 7.0.0b8__py3-none-any.whl → 7.1.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.
Files changed (46) hide show
  1. ens/async_ens.py +16 -7
  2. ens/base_ens.py +3 -1
  3. ens/exceptions.py +2 -7
  4. ens/utils.py +0 -17
  5. web3/_utils/abi.py +100 -257
  6. web3/_utils/compat/__init__.py +1 -0
  7. web3/_utils/contracts.py +116 -205
  8. web3/_utils/encoding.py +4 -5
  9. web3/_utils/events.py +28 -33
  10. web3/_utils/fee_utils.py +2 -2
  11. web3/_utils/filters.py +2 -5
  12. web3/_utils/http_session_manager.py +30 -7
  13. web3/_utils/method_formatters.py +3 -3
  14. web3/_utils/module_testing/eth_module.py +59 -37
  15. web3/_utils/module_testing/module_testing_utils.py +43 -1
  16. web3/_utils/module_testing/persistent_connection_provider.py +2 -0
  17. web3/_utils/module_testing/web3_module.py +8 -8
  18. web3/_utils/normalizers.py +10 -8
  19. web3/_utils/validation.py +5 -7
  20. web3/beacon/api_endpoints.py +3 -0
  21. web3/beacon/async_beacon.py +18 -2
  22. web3/beacon/beacon.py +18 -2
  23. web3/contract/async_contract.py +26 -25
  24. web3/contract/base_contract.py +116 -80
  25. web3/contract/contract.py +26 -25
  26. web3/contract/utils.py +86 -55
  27. web3/datastructures.py +21 -11
  28. web3/eth/async_eth.py +1 -2
  29. web3/eth/eth.py +1 -2
  30. web3/exceptions.py +22 -9
  31. web3/gas_strategies/time_based.py +4 -0
  32. web3/manager.py +34 -12
  33. web3/middleware/base.py +8 -0
  34. web3/middleware/filter.py +3 -3
  35. web3/middleware/signing.py +6 -1
  36. web3/scripts/install_pre_releases.py +33 -0
  37. web3/scripts/parse_pygeth_version.py +16 -0
  38. web3/types.py +5 -45
  39. web3/utils/__init__.py +48 -4
  40. web3/utils/abi.py +575 -10
  41. {web3-7.0.0b8.dist-info → web3-7.1.0.dist-info}/METADATA +10 -10
  42. {web3-7.0.0b8.dist-info → web3-7.1.0.dist-info}/RECORD +46 -44
  43. {web3-7.0.0b8.dist-info → web3-7.1.0.dist-info}/WHEEL +1 -1
  44. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
  45. {web3-7.0.0b8.dist-info → web3-7.1.0.dist-info}/LICENSE +0 -0
  46. {web3-7.0.0b8.dist-info → web3-7.1.0.dist-info}/top_level.txt +0 -0
web3/utils/abi.py CHANGED
@@ -1,21 +1,586 @@
1
+ import functools
1
2
  from typing import (
3
+ Any,
4
+ Dict,
2
5
  List,
6
+ Optional,
7
+ Sequence,
8
+ Tuple,
3
9
  Union,
10
+ cast,
4
11
  )
5
12
 
6
- from web3.types import (
13
+ from eth_abi import (
14
+ codec,
15
+ )
16
+ from eth_abi.codec import (
17
+ ABICodec,
18
+ )
19
+ from eth_abi.registry import (
20
+ registry as default_registry,
21
+ )
22
+ from eth_typing import (
23
+ ABI,
24
+ ABICallable,
25
+ ABIConstructor,
26
+ ABIElement,
27
+ ABIElementInfo,
7
28
  ABIEvent,
8
- ABIFunction,
29
+ ABIFallback,
30
+ ABIReceive,
31
+ HexStr,
32
+ Primitives,
33
+ )
34
+ from eth_utils.address import (
35
+ is_binary_address,
36
+ is_checksum_address,
37
+ )
38
+ from eth_utils.conversions import (
39
+ hexstr_if_str,
40
+ to_bytes,
41
+ )
42
+ from eth_utils.hexadecimal import (
43
+ encode_hex,
44
+ )
45
+ from eth_utils.toolz import (
46
+ pipe,
47
+ )
48
+ from eth_utils.types import (
49
+ is_list_like,
50
+ is_text,
51
+ )
52
+ from hexbytes import (
53
+ HexBytes,
54
+ )
55
+
56
+ from web3._utils.abi import (
57
+ filter_by_argument_name,
58
+ )
59
+ from web3._utils.abi_element_identifiers import (
60
+ FallbackFn,
61
+ ReceiveFn,
9
62
  )
63
+ from web3.exceptions import (
64
+ ABIConstructorNotFound,
65
+ ABIFallbackNotFound,
66
+ ABIReceiveNotFound,
67
+ MismatchedABI,
68
+ Web3TypeError,
69
+ Web3ValidationError,
70
+ Web3ValueError,
71
+ )
72
+ from web3.types import (
73
+ ABIElementIdentifier,
74
+ )
75
+
76
+ from eth_utils.abi import ( # noqa
77
+ abi_to_signature,
78
+ event_abi_to_log_topic,
79
+ filter_abi_by_name,
80
+ filter_abi_by_type,
81
+ function_abi_to_4byte_selector,
82
+ get_aligned_abi_inputs,
83
+ get_normalized_abi_inputs,
84
+ )
85
+
86
+
87
+ def _filter_by_argument_count(
88
+ num_arguments: int, contract_abi: ABI
89
+ ) -> List[ABIElement]:
90
+ return [
91
+ abi
92
+ for abi in contract_abi
93
+ if abi["type"] != "fallback"
94
+ and abi["type"] != "receive"
95
+ and len(abi.get("inputs", [])) == num_arguments
96
+ ]
97
+
98
+
99
+ def _filter_by_encodability(
100
+ abi_codec: codec.ABIEncoder,
101
+ contract_abi: ABI,
102
+ *args: Optional[Sequence[Any]],
103
+ **kwargs: Optional[Dict[str, Any]],
104
+ ) -> List[ABICallable]:
105
+ return [
106
+ cast(ABICallable, function_abi)
107
+ for function_abi in contract_abi
108
+ if check_if_arguments_can_be_encoded(
109
+ function_abi, *args, abi_codec=abi_codec, **kwargs
110
+ )
111
+ ]
112
+
113
+
114
+ def _get_constructor_function_abi(contract_abi: ABI) -> ABIConstructor:
115
+ """
116
+ Return the receive function ABI from the contract ABI.
117
+ """
118
+ filtered_abis = filter_abi_by_type("constructor", contract_abi)
119
+
120
+ if len(filtered_abis) > 1:
121
+ raise MismatchedABI("Multiple constructor functions found in the contract ABI.")
122
+
123
+ if filtered_abis:
124
+ return filtered_abis[0]
125
+ else:
126
+ raise ABIConstructorNotFound(
127
+ "No constructor function was found in the contract ABI."
128
+ )
129
+
130
+
131
+ def _get_receive_function_abi(contract_abi: ABI) -> ABIReceive:
132
+ """
133
+ Return the receive function ABI from the contract ABI.
134
+ """
135
+ filtered_abis = filter_abi_by_type("receive", contract_abi)
136
+
137
+ if len(filtered_abis) > 1:
138
+ raise MismatchedABI("Multiple receive functions found in the contract ABI.")
139
+
140
+ if filtered_abis:
141
+ return filtered_abis[0]
142
+ else:
143
+ raise ABIReceiveNotFound("No receive function was found in the contract ABI.")
144
+
145
+
146
+ def _get_fallback_function_abi(contract_abi: ABI) -> ABIFallback:
147
+ """
148
+ Return the fallback function ABI from the contract ABI.
149
+ """
150
+ filtered_abis = filter_abi_by_type("fallback", contract_abi)
151
+
152
+ if len(filtered_abis) > 1:
153
+ raise MismatchedABI("Multiple fallback functions found in the contract ABI.")
154
+
155
+ if filtered_abis:
156
+ return filtered_abis[0]
157
+ else:
158
+ raise ABIFallbackNotFound("No fallback function was found in the contract ABI.")
159
+
160
+
161
+ def _mismatched_abi_error_diagnosis(
162
+ abi_element_identifier: ABIElementIdentifier,
163
+ matching_function_signatures: Sequence[str],
164
+ arg_count_matches: int,
165
+ encoding_matches: int,
166
+ *args: Optional[Sequence[Any]],
167
+ **kwargs: Optional[Dict[str, Any]],
168
+ ) -> str:
169
+ """
170
+ Raise a ``MismatchedABI`` when a function ABI lookup results in an error.
171
+
172
+ An error may result from multiple functions matching the provided signature and
173
+ arguments or no functions are identified.
174
+ """
175
+ diagnosis = "\n"
176
+ if arg_count_matches == 0:
177
+ diagnosis += "Function invocation failed due to improper number of arguments."
178
+ elif encoding_matches == 0:
179
+ diagnosis += "Function invocation failed due to no matching argument types."
180
+ elif encoding_matches > 1:
181
+ diagnosis += (
182
+ "Ambiguous argument encoding. "
183
+ "Provided arguments can be encoded to multiple functions "
184
+ "matching this call."
185
+ )
186
+
187
+ collapsed_args = _extract_argument_types(*args)
188
+ collapsed_kwargs = dict(
189
+ {(k, _extract_argument_types([v])) for k, v in kwargs.items()}
190
+ )
191
+
192
+ return (
193
+ f"\nCould not identify the intended function with name "
194
+ f"`{abi_element_identifier}`, positional arguments with type(s) "
195
+ f"`({collapsed_args})` and keyword arguments with type(s) "
196
+ f"`{collapsed_kwargs}`."
197
+ f"\nFound {len(matching_function_signatures)} function(s) with the name "
198
+ f"`{abi_element_identifier}`: {matching_function_signatures}{diagnosis}"
199
+ )
200
+
201
+
202
+ def _extract_argument_types(*args: Sequence[Any]) -> str:
203
+ """
204
+ Takes a list of arguments and returns a string representation of the argument types,
205
+ appropriately collapsing `tuple` types into the respective nested types.
206
+ """
207
+ collapsed_args = []
208
+
209
+ for arg in args:
210
+ if is_list_like(arg):
211
+ collapsed_nested = []
212
+ for nested in arg:
213
+ if is_list_like(nested):
214
+ collapsed_nested.append(f"({_extract_argument_types(nested)})")
215
+ else:
216
+ collapsed_nested.append(_get_argument_readable_type(nested))
217
+ collapsed_args.append(",".join(collapsed_nested))
218
+ else:
219
+ collapsed_args.append(_get_argument_readable_type(arg))
220
+
221
+ return ",".join(collapsed_args)
222
+
223
+
224
+ def _get_argument_readable_type(arg: Any) -> str:
225
+ """
226
+ Returns the class name of the argument, or `address` if the argument is an address.
227
+ """
228
+ if is_checksum_address(arg) or is_binary_address(arg):
229
+ return "address"
230
+
231
+ return arg.__class__.__name__
232
+
233
+
234
+ def get_abi_element_info(
235
+ abi: ABI,
236
+ abi_element_identifier: ABIElementIdentifier,
237
+ *args: Optional[Sequence[Any]],
238
+ abi_codec: Optional[Any] = None,
239
+ **kwargs: Optional[Dict[str, Any]],
240
+ ) -> ABIElementInfo:
241
+ """
242
+ Information about the function ABI, selector and input arguments.
243
+
244
+ Returns the ABI which matches the provided identifier, named arguments (``args``)
245
+ and keyword args (``kwargs``).
246
+
247
+ :param abi: Contract ABI.
248
+ :type abi: `ABI`
249
+ :param abi_element_identifier: Find an element ABI with matching identifier.
250
+ :type abi_element_identifier: `ABIElementIdentifier`
251
+ :param args: Find a function ABI with matching args.
252
+ :type args: `Optional[Sequence[Any]]`
253
+ :param abi_codec: Codec used for encoding and decoding. Default with \
254
+ `strict_bytes_type_checking` enabled.
255
+ :type abi_codec: `Optional[Any]`
256
+ :param kwargs: Find an element ABI with matching kwargs.
257
+ :type kwargs: `Optional[Dict[str, Any]]`
258
+ :return: Element information including the ABI, selector and args.
259
+ :rtype: `ABIElementInfo`
260
+
261
+ .. doctest::
262
+
263
+ >>> from web3.utils.abi import get_abi_element_info
264
+ >>> abi = [
265
+ ... {
266
+ ... "constant": False,
267
+ ... "inputs": [
268
+ ... {"name": "a", "type": "uint256"},
269
+ ... {"name": "b", "type": "uint256"},
270
+ ... ],
271
+ ... "name": "multiply",
272
+ ... "outputs": [{"name": "result", "type": "uint256"}],
273
+ ... "payable": False,
274
+ ... "stateMutability": "nonpayable",
275
+ ... "type": "function",
276
+ ... }
277
+ ... ]
278
+ >>> fn_info = get_abi_element_info(abi, "multiply", *[7, 3])
279
+ >>> fn_info["abi"]
280
+ {'constant': False, 'inputs': [{'name': 'a', 'type': 'uint256'}, {\
281
+ 'name': 'b', 'type': 'uint256'}], 'name': 'multiply', 'outputs': [{\
282
+ 'name': 'result', 'type': 'uint256'}], 'payable': False, \
283
+ 'stateMutability': 'nonpayable', 'type': 'function'}
284
+ >>> fn_info["selector"]
285
+ '0x165c4a16'
286
+ >>> fn_info["arguments"]
287
+ (7, 3)
288
+ """
289
+ fn_abi = get_abi_element(
290
+ abi, abi_element_identifier, *args, abi_codec=abi_codec, **kwargs
291
+ )
292
+ fn_selector = encode_hex(function_abi_to_4byte_selector(fn_abi))
293
+ fn_inputs: Tuple[Any, ...] = tuple()
294
+
295
+ if fn_abi["type"] == "fallback" or fn_abi["type"] == "receive":
296
+ return ABIElementInfo(abi=fn_abi, selector=fn_selector, arguments=tuple())
297
+ else:
298
+ fn_inputs = get_normalized_abi_inputs(fn_abi, *args, **kwargs)
299
+ _, aligned_fn_inputs = get_aligned_abi_inputs(fn_abi, fn_inputs)
300
+
301
+ return ABIElementInfo(
302
+ abi=fn_abi, selector=fn_selector, arguments=aligned_fn_inputs
303
+ )
304
+
305
+
306
+ def get_abi_element(
307
+ abi: ABI,
308
+ abi_element_identifier: ABIElementIdentifier,
309
+ *args: Optional[Sequence[Any]],
310
+ abi_codec: Optional[Any] = None,
311
+ **kwargs: Optional[Dict[str, Any]],
312
+ ) -> ABIElement:
313
+ """
314
+ Return the interface for an ``ABIElement`` which matches the provided identifier
315
+ and arguments.
316
+
317
+ The ABI which matches the provided identifier, named arguments (``args``) and
318
+ keyword args (``kwargs``) will be returned.
319
+
320
+ The `abi_codec` may be overridden if custom encoding and decoding is required. The
321
+ default is used if no codec is provided. More details about customizations are in
322
+ the `eth-abi Codecs Doc <https://eth-abi.readthedocs.io/en/latest/codecs.html>`__.
323
+
324
+ :param abi: Contract ABI.
325
+ :type abi: `ABI`
326
+ :param abi_element_identifier: Find an element ABI with matching identifier.
327
+ :type abi_element_identifier: `ABIElementIdentifier`
328
+ :param args: Find an element ABI with matching args.
329
+ :type args: `Optional[Sequence[Any]]`
330
+ :param abi_codec: Codec used for encoding and decoding. Default with \
331
+ `strict_bytes_type_checking` enabled.
332
+ :type abi_codec: `Optional[Any]`
333
+ :param kwargs: Find an element ABI with matching kwargs.
334
+ :type kwargs: `Optional[Dict[str, Any]]`
335
+ :return: ABI element for the specific ABI element.
336
+ :rtype: `ABIElement`
337
+
338
+ .. doctest::
339
+
340
+ >>> from web3.utils.abi import get_abi_element
341
+ >>> abi = [
342
+ ... {
343
+ ... "constant": False,
344
+ ... "inputs": [
345
+ ... {"name": "a", "type": "uint256"},
346
+ ... {"name": "b", "type": "uint256"},
347
+ ... ],
348
+ ... "name": "multiply",
349
+ ... "outputs": [{"name": "result", "type": "uint256"}],
350
+ ... "payable": False,
351
+ ... "stateMutability": "nonpayable",
352
+ ... "type": "function",
353
+ ... }
354
+ ... ]
355
+ >>> get_abi_element(abi, "multiply", *[7, 3])
356
+ {'constant': False, 'inputs': [{'name': 'a', 'type': 'uint256'}, {\
357
+ 'name': 'b', 'type': 'uint256'}], 'name': 'multiply', 'outputs': [{'name': 'result', \
358
+ 'type': 'uint256'}], 'payable': False, 'stateMutability': 'nonpayable', \
359
+ 'type': 'function'}
360
+ """
361
+ if abi_codec is None:
362
+ abi_codec = ABICodec(default_registry)
363
+
364
+ if abi_element_identifier is FallbackFn or abi_element_identifier == "fallback":
365
+ return _get_fallback_function_abi(abi)
366
+
367
+ if abi_element_identifier is ReceiveFn or abi_element_identifier == "receive":
368
+ return _get_receive_function_abi(abi)
369
+
370
+ if abi_element_identifier is None or not is_text(abi_element_identifier):
371
+ raise Web3TypeError("Unsupported function identifier")
372
+
373
+ filtered_abis_by_name: Sequence[ABIElement]
374
+ if abi_element_identifier == "constructor":
375
+ filtered_abis_by_name = [_get_constructor_function_abi(abi)]
376
+ else:
377
+ filtered_abis_by_name = filter_abi_by_name(
378
+ cast(str, abi_element_identifier), abi
379
+ )
380
+
381
+ arg_count = len(args) + len(kwargs)
382
+ filtered_abis_by_arg_count = _filter_by_argument_count(
383
+ arg_count, filtered_abis_by_name
384
+ )
385
+
386
+ if not args and not kwargs and len(filtered_abis_by_arg_count) == 1:
387
+ return filtered_abis_by_arg_count[0]
388
+
389
+ elements_with_encodable_args = _filter_by_encodability(
390
+ abi_codec, filtered_abis_by_arg_count, *args, **kwargs
391
+ )
392
+
393
+ if len(elements_with_encodable_args) != 1:
394
+ matching_function_signatures = [
395
+ abi_to_signature(func) for func in filtered_abis_by_name
396
+ ]
397
+
398
+ error_diagnosis = _mismatched_abi_error_diagnosis(
399
+ abi_element_identifier,
400
+ matching_function_signatures,
401
+ len(filtered_abis_by_arg_count),
402
+ len(elements_with_encodable_args),
403
+ *args,
404
+ **kwargs,
405
+ )
406
+
407
+ raise MismatchedABI(error_diagnosis)
408
+
409
+ return elements_with_encodable_args[0]
410
+
411
+
412
+ def check_if_arguments_can_be_encoded(
413
+ abi_element: ABIElement,
414
+ *args: Optional[Sequence[Any]],
415
+ abi_codec: Optional[Any] = None,
416
+ **kwargs: Optional[Dict[str, Any]],
417
+ ) -> bool:
418
+ """
419
+ Check if the provided arguments can be encoded with the element ABI.
420
+
421
+ :param abi_element: The ABI element.
422
+ :type abi_element: `ABIElement`
423
+ :param args: Positional arguments.
424
+ :type args: `Optional[Sequence[Any]]`
425
+ :param abi_codec: Codec used for encoding and decoding. Default with \
426
+ `strict_bytes_type_checking` enabled.
427
+ :type abi_codec: `Optional[Any]`
428
+ :param kwargs: Keyword arguments.
429
+ :type kwargs: `Optional[Dict[str, Any]]`
430
+ :return: True if the arguments can be encoded, False otherwise.
431
+ :rtype: `bool`
432
+
433
+ .. doctest::
434
+
435
+ >>> from web3.utils.abi import check_if_arguments_can_be_encoded
436
+ >>> abi = {
437
+ ... "constant": False,
438
+ ... "inputs": [
439
+ ... {"name": "a", "type": "uint256"},
440
+ ... {"name": "b", "type": "uint256"},
441
+ ... ],
442
+ ... "name": "multiply",
443
+ ... "outputs": [{"name": "result", "type": "uint256"}],
444
+ ... "payable": False,
445
+ ... "stateMutability": "nonpayable",
446
+ ... "type": "function",
447
+ ... }
448
+ >>> check_if_arguments_can_be_encoded(abi, *[7, 3], **{})
449
+ True
450
+ """
451
+ if abi_element["type"] == "fallback" or abi_element["type"] == "receive":
452
+ return True
453
+
454
+ try:
455
+ arguments = get_normalized_abi_inputs(abi_element, *args, **kwargs)
456
+ except TypeError:
457
+ return False
458
+
459
+ if len(abi_element.get("inputs", ())) != len(arguments):
460
+ return False
461
+
462
+ try:
463
+ types, aligned_args = get_aligned_abi_inputs(abi_element, arguments)
464
+ except TypeError:
465
+ return False
466
+
467
+ if abi_codec is None:
468
+ abi_codec = ABICodec(default_registry)
469
+
470
+ return all(
471
+ abi_codec.is_encodable(_type, arg) for _type, arg in zip(types, aligned_args)
472
+ )
473
+
474
+
475
+ def get_event_abi(
476
+ abi: ABI,
477
+ event_name: str,
478
+ argument_names: Optional[Sequence[str]] = None,
479
+ ) -> ABIEvent:
480
+ """
481
+ Find the event interface with the given name and/or arguments.
482
+
483
+ :param abi: Contract ABI.
484
+ :type abi: `ABI`
485
+ :param event_name: Find an event abi with matching event name.
486
+ :type event_name: `str`
487
+ :param argument_names: Find an event abi with matching arguments.
488
+ :type argument_names: `Optional[Sequence[str]]`
489
+ :return: ABI for the event interface.
490
+ :rtype: `ABIEvent`
491
+
492
+ .. doctest::
493
+
494
+ >>> from web3.utils import get_event_abi
495
+ >>> abi = [
496
+ ... {"type": "function", "name": "myFunction", "inputs": [], "outputs": []},
497
+ ... {"type": "function", "name": "myFunction2", "inputs": [], "outputs": []},
498
+ ... {"type": "event", "name": "MyEvent", "inputs": []}
499
+ ... ]
500
+ >>> get_event_abi(abi, 'MyEvent')
501
+ {'type': 'event', 'name': 'MyEvent', 'inputs': []}
502
+ """
503
+ filters: List[functools.partial[Sequence[ABIElement]]] = [
504
+ functools.partial(filter_abi_by_type, "event"),
505
+ ]
506
+
507
+ if event_name is None or event_name == "":
508
+ raise Web3ValidationError(
509
+ "event_name is required in order to match an event ABI."
510
+ )
511
+
512
+ filters.append(functools.partial(filter_abi_by_name, event_name))
513
+
514
+ if argument_names is not None:
515
+ filters.append(functools.partial(filter_by_argument_name, argument_names))
516
+
517
+ event_abi_candidates = cast(Sequence[ABIEvent], pipe(abi, *filters))
518
+
519
+ if len(event_abi_candidates) == 1:
520
+ return event_abi_candidates[0]
521
+ elif len(event_abi_candidates) == 0:
522
+ raise Web3ValueError("No matching events found")
523
+ else:
524
+ raise Web3ValueError("Multiple events found")
525
+
526
+
527
+ def get_event_log_topics(
528
+ event_abi: ABIEvent,
529
+ topics: Sequence[HexBytes],
530
+ ) -> Sequence[HexBytes]:
531
+ r"""
532
+ Return topics for an event ABI.
533
+
534
+ :param event_abi: Event ABI.
535
+ :type event_abi: `ABIEvent`
536
+ :param topics: Transaction topics from a `LogReceipt`.
537
+ :type topics: `Sequence[HexBytes]`
538
+ :return: Event topics for the event ABI.
539
+ :rtype: `Sequence[HexBytes]`
540
+
541
+ .. doctest::
542
+
543
+ >>> from web3.utils import get_event_log_topics
544
+ >>> abi = {
545
+ ... 'type': 'event',
546
+ ... 'anonymous': False,
547
+ ... 'name': 'MyEvent',
548
+ ... 'inputs': [
549
+ ... {
550
+ ... 'name': 's',
551
+ ... 'type': 'uint256'
552
+ ... }
553
+ ... ]
554
+ ... }
555
+ >>> keccak_signature = b'l+Ff\xba\x8d\xa5\xa9W\x17b\x1d\x87\x9aw\xder_=\x81g\t\xb9\xcb\xe9\xf0Y\xb8\xf8u\xe2\x84' # noqa: E501
556
+ >>> get_event_log_topics(abi, [keccak_signature, '0x1', '0x2'])
557
+ ['0x1', '0x2']
558
+ """
559
+ if event_abi["anonymous"]:
560
+ return topics
561
+ elif not topics or len(topics) == 0:
562
+ raise MismatchedABI("Expected non-anonymous event to have 1 or more topics")
563
+ elif event_abi_to_log_topic(event_abi) != log_topic_to_bytes(topics[0]):
564
+ raise MismatchedABI("The event signature did not match the provided ABI")
565
+ else:
566
+ return topics[1:]
567
+
10
568
 
569
+ def log_topic_to_bytes(
570
+ log_topic: Union[Primitives, HexStr, str],
571
+ ) -> bytes:
572
+ r"""
573
+ Return topic signature as bytes.
11
574
 
12
- def get_abi_input_names(abi: Union[ABIFunction, ABIEvent]) -> List[str]:
13
- if "inputs" not in abi and abi["type"] == "fallback":
14
- return []
15
- return [arg["name"] for arg in abi["inputs"]]
575
+ :param log_topic: Event topic from a `LogReceipt`.
576
+ :type log_topic: `Union[Primitives, HexStr, str]`
577
+ :return: Topic signature as bytes.
578
+ :rtype: `bytes`
16
579
 
580
+ .. doctest::
17
581
 
18
- def get_abi_output_names(abi: Union[ABIFunction]) -> List[str]:
19
- if "outputs" not in abi and abi["type"] == "fallback":
20
- return []
21
- return [arg["name"] for arg in abi["outputs"]]
582
+ >>> from web3.utils import log_topic_to_bytes
583
+ >>> log_topic_to_bytes('0xa12fd1')
584
+ b'\xa1/\xd1'
585
+ """
586
+ return hexstr_if_str(to_bytes, log_topic)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: web3
3
- Version: 7.0.0b8
3
+ Version: 7.1.0
4
4
  Summary: web3: A Python library for interacting with Ethereum
5
5
  Home-page: https://github.com/ethereum/web3.py
6
6
  Author: The Ethereum Foundation
@@ -20,16 +20,17 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Requires-Python: >=3.8, <4
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: aiohttp >=3.7.4.post0
24
23
  Requires-Dist: eth-abi >=5.0.1
25
- Requires-Dist: eth-account >=0.12.2
24
+ Requires-Dist: eth-account >=0.13.1
26
25
  Requires-Dist: eth-hash[pycryptodome] >=0.5.1
27
- Requires-Dist: eth-typing >=4.0.0
28
- Requires-Dist: eth-utils >=4.0.0
26
+ Requires-Dist: eth-typing >=5.0.0
27
+ Requires-Dist: eth-utils >=5.0.0
29
28
  Requires-Dist: hexbytes >=1.2.0
29
+ Requires-Dist: aiohttp >=3.7.4.post0
30
30
  Requires-Dist: pydantic >=2.4.0
31
- Requires-Dist: requests >=2.16.0
31
+ Requires-Dist: requests >=2.23.0
32
32
  Requires-Dist: typing-extensions >=4.0.1
33
+ Requires-Dist: types-requests >=2.0.0
33
34
  Requires-Dist: websockets >=10.0.0
34
35
  Requires-Dist: pyunormalize >=15.0.0
35
36
  Requires-Dist: pywin32 >=223 ; platform_system == "Windows"
@@ -39,6 +40,7 @@ Requires-Dist: bumpversion >=0.5.3 ; extra == 'dev'
39
40
  Requires-Dist: flaky >=3.7.0 ; extra == 'dev'
40
41
  Requires-Dist: hypothesis >=3.31.2 ; extra == 'dev'
41
42
  Requires-Dist: ipython ; extra == 'dev'
43
+ Requires-Dist: mypy ==1.10.0 ; extra == 'dev'
42
44
  Requires-Dist: pre-commit >=3.4.0 ; extra == 'dev'
43
45
  Requires-Dist: pytest-asyncio <0.23,>=0.21.2 ; extra == 'dev'
44
46
  Requires-Dist: pytest-mock >=1.10 ; extra == 'dev'
@@ -51,9 +53,8 @@ Requires-Dist: sphinx >=6.0.0 ; extra == 'dev'
51
53
  Requires-Dist: sphinx-autobuild >=2021.3.14 ; extra == 'dev'
52
54
  Requires-Dist: sphinx-rtd-theme >=1.0.0 ; extra == 'dev'
53
55
  Requires-Dist: towncrier <22,>=21 ; extra == 'dev'
54
- Requires-Dist: eth-account >=0.13.0 ; extra == 'dev'
55
56
  Requires-Dist: eth-tester[py-evm] <0.13.0b1,>=0.11.0b1 ; extra == 'dev'
56
- Requires-Dist: py-geth >=5.0.0b1 ; extra == 'dev'
57
+ Requires-Dist: py-geth >=5.0.0 ; extra == 'dev'
57
58
  Requires-Dist: pytest-asyncio <0.23,>=0.18.1 ; extra == 'dev'
58
59
  Requires-Dist: pytest-xdist >=2.4.0 ; extra == 'dev'
59
60
  Requires-Dist: pytest >=7.0.0 ; extra == 'dev'
@@ -62,10 +63,9 @@ Requires-Dist: sphinx >=6.0.0 ; extra == 'docs'
62
63
  Requires-Dist: sphinx-autobuild >=2021.3.14 ; extra == 'docs'
63
64
  Requires-Dist: sphinx-rtd-theme >=1.0.0 ; extra == 'docs'
64
65
  Requires-Dist: towncrier <22,>=21 ; extra == 'docs'
65
- Requires-Dist: eth-account >=0.13.0 ; extra == 'docs'
66
66
  Provides-Extra: test
67
67
  Requires-Dist: eth-tester[py-evm] <0.13.0b1,>=0.11.0b1 ; extra == 'test'
68
- Requires-Dist: py-geth >=5.0.0b1 ; extra == 'test'
68
+ Requires-Dist: py-geth >=5.0.0 ; extra == 'test'
69
69
  Requires-Dist: pytest-asyncio <0.23,>=0.18.1 ; extra == 'test'
70
70
  Requires-Dist: pytest-mock >=1.10 ; extra == 'test'
71
71
  Requires-Dist: pytest-xdist >=2.4.0 ; extra == 'test'