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/middleware/base.py CHANGED
@@ -40,6 +40,14 @@ class Web3Middleware:
40
40
  def __init__(self, w3: Union["AsyncWeb3", "Web3"]) -> None:
41
41
  self._w3 = w3
42
42
 
43
+ def __hash__(self) -> int:
44
+ return hash(f"{self.__class__.__name__}({str(self.__dict__)})")
45
+
46
+ def __eq__(self, other: Any) -> bool:
47
+ if not isinstance(other, Web3Middleware):
48
+ return False
49
+ return self.__hash__() == other.__hash__()
50
+
43
51
  # -- sync -- #
44
52
 
45
53
  def wrap_make_request(self, make_request: "MakeRequestFn") -> "MakeRequestFn":
web3/middleware/filter.py CHANGED
@@ -167,7 +167,7 @@ def iter_latest_block(
167
167
 
168
168
  while True:
169
169
  latest_block = w3.eth.block_number
170
- if is_bounded_range and latest_block > to_block:
170
+ if is_bounded_range and latest_block > cast(BlockNumber, to_block):
171
171
  yield None
172
172
  # No new blocks since last iteration.
173
173
  if _last is not None and _last == latest_block:
@@ -255,7 +255,7 @@ class RequestLogs:
255
255
  if from_block is None or from_block == "latest":
256
256
  self._from_block = BlockNumber(w3.eth.block_number + 1)
257
257
  elif is_string(from_block) and is_hex(from_block):
258
- self._from_block = BlockNumber(hex_to_integer(from_block))
258
+ self._from_block = BlockNumber(hex_to_integer(cast(HexStr, from_block)))
259
259
  else:
260
260
  self._from_block = from_block
261
261
  self._to_block = to_block
@@ -272,7 +272,7 @@ class RequestLogs:
272
272
  elif self._to_block == "latest":
273
273
  to_block = self.w3.eth.block_number
274
274
  elif is_string(self._to_block) and is_hex(self._to_block):
275
- to_block = BlockNumber(hex_to_integer(self._to_block))
275
+ to_block = BlockNumber(hex_to_integer(cast(HexStr, self._to_block)))
276
276
  else:
277
277
  to_block = self._to_block
278
278
 
@@ -19,6 +19,9 @@ from eth_account import (
19
19
  from eth_account.signers.local import (
20
20
  LocalAccount,
21
21
  )
22
+ from eth_account.types import (
23
+ TransactionDictType as EthAccountTxParams,
24
+ )
22
25
  from eth_keys.datatypes import (
23
26
  PrivateKey,
24
27
  )
@@ -211,7 +214,9 @@ class SignAndSendRawMiddlewareBuilder(Web3MiddlewareBuilder):
211
214
  return method, params
212
215
  else:
213
216
  account = self._accounts[to_checksum_address(tx_from)]
214
- raw_tx = account.sign_transaction(filled_transaction).raw_transaction
217
+ raw_tx = account.sign_transaction(
218
+ cast(EthAccountTxParams, filled_transaction)
219
+ ).raw_transaction
215
220
 
216
221
  return (
217
222
  RPCEndpoint("eth_sendRawTransaction"),
@@ -0,0 +1,33 @@
1
+ """
2
+ The goal of this script is to install the latest versions, including pre-releases, for
3
+ libraries that we maintain (and therefore control the release process) during our CI
4
+ runs. This helps us test pre-releases before they cause any issues once stable versions
5
+ are released.
6
+ """
7
+
8
+ import subprocess
9
+ import sys
10
+
11
+ ETHEREUM_LIBRARIES = [
12
+ "eth-account",
13
+ "eth-abi",
14
+ "eth-account",
15
+ "eth-hash[pycryptodome]",
16
+ "eth-typing",
17
+ "eth-utils",
18
+ "hexbytes",
19
+ "eth-tester[py-evm]",
20
+ "py-geth",
21
+ ]
22
+
23
+
24
+ def install_eth_pre_releases() -> None:
25
+ for lib in ETHEREUM_LIBRARIES:
26
+ print(f"Installing {lib} with `--pre` and `-U`")
27
+ subprocess.check_call(
28
+ [sys.executable, "-m", "pip", "install", "--pre", "-U", lib]
29
+ )
30
+
31
+
32
+ if __name__ == "__main__":
33
+ install_eth_pre_releases()
@@ -0,0 +1,16 @@
1
+ import re
2
+
3
+
4
+ def get_pygeth_version() -> str:
5
+ with open("setup.py") as f:
6
+ setup_contents = f.read()
7
+ version_match = re.search(r"py-geth\s*([><=~!]+)\s*([\d.]+)", setup_contents)
8
+ if version_match:
9
+ return "".join(version_match.group(1, 2))
10
+ else:
11
+ raise ValueError("py-geth not found in setup.py")
12
+
13
+
14
+ if __name__ == "__main__":
15
+ version = get_pygeth_version()
16
+ print(version)
web3/types.py CHANGED
@@ -27,13 +27,13 @@ from hexbytes import (
27
27
  HexBytes,
28
28
  )
29
29
 
30
- from web3._utils.compat import (
31
- NotRequired,
32
- )
33
- from web3._utils.function_identifiers import (
30
+ from web3._utils.abi_element_identifiers import (
34
31
  FallbackFn,
35
32
  ReceiveFn,
36
33
  )
34
+ from web3._utils.compat import (
35
+ NotRequired,
36
+ )
37
37
 
38
38
  if TYPE_CHECKING:
39
39
  from web3.contract.async_contract import AsyncContractFunction # noqa: F401
@@ -53,7 +53,7 @@ BlockParams = Literal["latest", "earliest", "pending", "safe", "finalized"]
53
53
  BlockIdentifier = Union[BlockParams, BlockNumber, Hash32, HexStr, HexBytes, int]
54
54
  LatestBlockParam = Literal["latest"]
55
55
 
56
- FunctionIdentifier = Union[str, Type[FallbackFn], Type[ReceiveFn]]
56
+ ABIElementIdentifier = Union[str, Type[FallbackFn], Type[ReceiveFn]]
57
57
 
58
58
  # bytes, hexbytes, or hexstr representing a 32 byte hash
59
59
  _Hash32 = Union[Hash32, HexBytes, HexStr]
@@ -75,46 +75,6 @@ class AccessListEntry(TypedDict):
75
75
  AccessList = NewType("AccessList", Sequence[AccessListEntry])
76
76
 
77
77
 
78
- # todo: move these to eth_typing once web3 is type hinted
79
- class ABIEventParams(TypedDict, total=False):
80
- indexed: bool
81
- name: str
82
- type: str
83
-
84
-
85
- class ABIEvent(TypedDict, total=False):
86
- anonymous: bool
87
- inputs: Sequence["ABIEventParams"]
88
- name: str
89
- type: Literal["event"]
90
-
91
-
92
- class ABIFunctionComponents(TypedDict, total=False):
93
- components: Sequence["ABIFunctionComponents"]
94
- name: str
95
- type: str
96
-
97
-
98
- class ABIFunctionParams(TypedDict, total=False):
99
- components: Sequence["ABIFunctionComponents"]
100
- name: str
101
- type: str
102
-
103
-
104
- class ABIFunction(TypedDict, total=False):
105
- constant: bool
106
- inputs: Sequence["ABIFunctionParams"]
107
- name: str
108
- outputs: Sequence["ABIFunctionParams"]
109
- payable: bool
110
- stateMutability: Literal["pure", "view", "nonpayable", "payable"]
111
- type: Literal["function", "constructor", "fallback", "receive"]
112
-
113
-
114
- ABIElement = Union[ABIFunction, ABIEvent]
115
- ABI = Sequence[Union[ABIFunction, ABIEvent]]
116
-
117
-
118
78
  class EventData(TypedDict):
119
79
  address: ChecksumAddress
120
80
  args: Dict[str, Any]
web3/utils/__init__.py CHANGED
@@ -3,11 +3,35 @@ NOTE: This is a public utility module. Any changes to these utility methods woul
3
3
  classify as breaking changes.
4
4
  """
5
5
 
6
- from .abi import (
6
+ from eth_utils.abi import (
7
+ abi_to_signature,
8
+ collapse_if_tuple,
9
+ event_abi_to_log_topic,
10
+ event_signature_to_log_topic,
11
+ filter_abi_by_name,
12
+ filter_abi_by_type,
13
+ function_abi_to_4byte_selector,
14
+ function_signature_to_4byte_selector,
7
15
  get_abi_input_names,
16
+ get_abi_input_types,
8
17
  get_abi_output_names,
18
+ get_abi_output_types,
19
+ get_aligned_abi_inputs,
20
+ get_all_event_abis,
21
+ get_all_function_abis,
22
+ get_normalized_abi_inputs,
23
+ )
24
+ from .abi import ( # NOQA
25
+ check_if_arguments_can_be_encoded,
26
+ get_abi_element_info,
27
+ get_abi_element,
28
+ get_event_abi,
29
+ get_event_log_topics,
30
+ log_topic_to_bytes,
31
+ )
32
+ from .address import (
33
+ get_create_address,
9
34
  )
10
- from .address import get_create_address
11
35
  from .async_exception_handling import (
12
36
  async_handle_offchain_lookup,
13
37
  )
@@ -19,10 +43,30 @@ from .exception_handling import (
19
43
  )
20
44
 
21
45
  __all__ = [
22
- "SimpleCache",
23
- "async_handle_offchain_lookup",
46
+ "abi_to_signature",
47
+ "collapse_if_tuple",
48
+ "event_abi_to_log_topic",
49
+ "event_signature_to_log_topic",
50
+ "filter_abi_by_name",
51
+ "filter_abi_by_type",
52
+ "function_abi_to_4byte_selector",
53
+ "function_signature_to_4byte_selector",
24
54
  "get_abi_input_names",
55
+ "get_abi_input_types",
25
56
  "get_abi_output_names",
57
+ "get_abi_output_types",
58
+ "get_aligned_abi_inputs",
59
+ "get_all_event_abis",
60
+ "get_all_function_abis",
61
+ "get_normalized_abi_inputs",
62
+ "check_if_arguments_can_be_encoded",
63
+ "get_abi_element_info",
64
+ "get_abi_element",
65
+ "get_event_abi",
66
+ "get_event_log_topics",
67
+ "log_topic_to_bytes",
26
68
  "get_create_address",
69
+ "async_handle_offchain_lookup",
70
+ "SimpleCache",
27
71
  "handle_offchain_lookup",
28
72
  ]