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.
Files changed (270) hide show
  1. ens/__init__.py +13 -2
  2. ens/_normalization.py +2 -17
  3. ens/async_ens.py +33 -21
  4. ens/base_ens.py +3 -1
  5. ens/ens.py +16 -11
  6. ens/exceptions.py +16 -29
  7. ens/specs/nf.json +1 -1
  8. ens/specs/normalization_spec.json +1 -1
  9. ens/utils.py +52 -63
  10. web3/__init__.py +20 -24
  11. web3/_utils/abi.py +115 -271
  12. web3/_utils/async_transactions.py +7 -4
  13. web3/_utils/batching.py +217 -0
  14. web3/_utils/blocks.py +6 -2
  15. web3/_utils/caching.py +128 -5
  16. web3/_utils/compat/__init__.py +2 -3
  17. web3/_utils/contract_sources/compile_contracts.py +1 -1
  18. web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
  19. web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
  20. web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
  21. web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
  22. web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
  23. web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
  24. web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
  25. web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
  26. web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
  27. web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
  28. web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
  29. web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
  30. web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
  31. web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
  32. web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
  33. web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
  34. web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
  35. web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
  36. web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
  37. web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
  38. web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
  39. web3/_utils/contracts.py +130 -236
  40. web3/_utils/datatypes.py +5 -1
  41. web3/_utils/decorators.py +13 -23
  42. web3/_utils/empty.py +1 -1
  43. web3/_utils/encoding.py +16 -12
  44. web3/_utils/ens.py +2 -1
  45. web3/_utils/error_formatters_utils.py +5 -3
  46. web3/_utils/events.py +66 -69
  47. web3/_utils/fee_utils.py +1 -3
  48. web3/_utils/filters.py +24 -22
  49. web3/_utils/formatters.py +2 -2
  50. web3/_utils/http.py +5 -3
  51. web3/_utils/http_session_manager.py +303 -0
  52. web3/_utils/math.py +14 -15
  53. web3/_utils/method_formatters.py +34 -36
  54. web3/_utils/module.py +2 -1
  55. web3/_utils/module_testing/__init__.py +0 -3
  56. web3/_utils/module_testing/eth_module.py +695 -643
  57. web3/_utils/module_testing/module_testing_utils.py +61 -34
  58. web3/_utils/module_testing/persistent_connection_provider.py +56 -25
  59. web3/_utils/module_testing/utils.py +258 -0
  60. web3/_utils/module_testing/web3_module.py +438 -17
  61. web3/_utils/normalizers.py +13 -11
  62. web3/_utils/rpc_abi.py +5 -32
  63. web3/_utils/threads.py +8 -7
  64. web3/_utils/transactions.py +14 -12
  65. web3/_utils/type_conversion.py +5 -1
  66. web3/_utils/validation.py +17 -17
  67. web3/auto/gethdev.py +7 -2
  68. web3/beacon/__init__.py +6 -1
  69. web3/beacon/async_beacon.py +9 -5
  70. web3/beacon/{main.py → beacon.py} +7 -5
  71. web3/contract/__init__.py +7 -0
  72. web3/contract/async_contract.py +47 -46
  73. web3/contract/base_contract.py +183 -158
  74. web3/contract/contract.py +49 -43
  75. web3/contract/utils.py +203 -59
  76. web3/datastructures.py +79 -31
  77. web3/eth/__init__.py +7 -0
  78. web3/eth/async_eth.py +39 -51
  79. web3/eth/base_eth.py +17 -10
  80. web3/eth/eth.py +30 -68
  81. web3/exceptions.py +108 -82
  82. web3/gas_strategies/time_based.py +8 -6
  83. web3/geth.py +1 -254
  84. web3/main.py +75 -122
  85. web3/manager.py +316 -146
  86. web3/method.py +38 -31
  87. web3/middleware/__init__.py +67 -89
  88. web3/middleware/attrdict.py +36 -49
  89. web3/middleware/base.py +174 -0
  90. web3/middleware/buffered_gas_estimate.py +20 -21
  91. web3/middleware/filter.py +157 -117
  92. web3/middleware/formatting.py +124 -108
  93. web3/middleware/gas_price_strategy.py +20 -32
  94. web3/middleware/names.py +29 -26
  95. web3/middleware/proof_of_authority.py +68 -0
  96. web3/middleware/pythonic.py +2 -2
  97. web3/middleware/signing.py +74 -89
  98. web3/middleware/stalecheck.py +52 -79
  99. web3/middleware/validation.py +5 -13
  100. web3/module.py +54 -10
  101. web3/providers/__init__.py +10 -6
  102. web3/providers/async_base.py +117 -39
  103. web3/providers/auto.py +3 -3
  104. web3/providers/base.py +89 -33
  105. web3/providers/eth_tester/__init__.py +5 -0
  106. web3/providers/eth_tester/defaults.py +1 -64
  107. web3/providers/eth_tester/main.py +99 -31
  108. web3/providers/eth_tester/middleware.py +45 -73
  109. web3/providers/ipc.py +42 -46
  110. web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
  111. web3/providers/persistent/__init__.py +22 -0
  112. web3/providers/persistent/async_ipc.py +153 -0
  113. web3/providers/{persistent.py → persistent/persistent.py} +106 -25
  114. web3/providers/persistent/persistent_connection.py +84 -0
  115. web3/providers/{websocket → persistent}/request_processor.py +94 -32
  116. web3/providers/persistent/utils.py +43 -0
  117. web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
  118. web3/providers/rpc/__init__.py +11 -0
  119. web3/providers/rpc/async_rpc.py +171 -0
  120. web3/providers/rpc/rpc.py +179 -0
  121. web3/providers/rpc/utils.py +92 -0
  122. web3/testing.py +4 -4
  123. web3/tools/benchmark/main.py +22 -22
  124. web3/tools/benchmark/node.py +2 -8
  125. web3/tools/benchmark/reporting.py +2 -2
  126. web3/tools/benchmark/utils.py +1 -1
  127. web3/tracing.py +9 -5
  128. web3/types.py +30 -107
  129. web3/utils/__init__.py +58 -5
  130. web3/utils/abi.py +575 -10
  131. web3/utils/async_exception_handling.py +19 -7
  132. web3/utils/caching.py +32 -13
  133. web3/utils/exception_handling.py +7 -5
  134. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
  135. web3-7.0.0.dist-info/METADATA +112 -0
  136. web3-7.0.0.dist-info/RECORD +167 -0
  137. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
  138. ethpm/__init__.py +0 -20
  139. ethpm/_utils/__init__.py +0 -0
  140. ethpm/_utils/backend.py +0 -93
  141. ethpm/_utils/cache.py +0 -44
  142. ethpm/_utils/chains.py +0 -119
  143. ethpm/_utils/contract.py +0 -35
  144. ethpm/_utils/deployments.py +0 -145
  145. ethpm/_utils/ipfs.py +0 -116
  146. ethpm/_utils/protobuf/__init__.py +0 -0
  147. ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
  148. ethpm/_utils/registry.py +0 -29
  149. ethpm/assets/__init__.py +0 -0
  150. ethpm/assets/ens/v3.json +0 -1
  151. ethpm/assets/escrow/with_bytecode_v3.json +0 -1
  152. ethpm/assets/ipfs_file.proto +0 -32
  153. ethpm/assets/owned/output_v3.json +0 -1
  154. ethpm/assets/owned/with_contract_type_v3.json +0 -1
  155. ethpm/assets/registry/contracts/Authority.sol +0 -156
  156. ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
  157. ethpm/assets/registry/contracts/PackageDB.sol +0 -225
  158. ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
  159. ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
  160. ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
  161. ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
  162. ethpm/assets/registry/solc_input.json +0 -1
  163. ethpm/assets/registry/solc_output.json +0 -1
  164. ethpm/assets/registry/v3.json +0 -1
  165. ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
  166. ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
  167. ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
  168. ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
  169. ethpm/assets/simple-registry/solc_input.json +0 -33
  170. ethpm/assets/simple-registry/solc_output.json +0 -1
  171. ethpm/assets/simple-registry/v3.json +0 -1
  172. ethpm/assets/standard-token/output_v3.json +0 -1
  173. ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
  174. ethpm/assets/vyper_registry/0.1.0.json +0 -1
  175. ethpm/assets/vyper_registry/registry.vy +0 -216
  176. ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
  177. ethpm/backends/__init__.py +0 -0
  178. ethpm/backends/base.py +0 -43
  179. ethpm/backends/http.py +0 -108
  180. ethpm/backends/ipfs.py +0 -219
  181. ethpm/backends/registry.py +0 -154
  182. ethpm/constants.py +0 -17
  183. ethpm/contract.py +0 -187
  184. ethpm/dependencies.py +0 -58
  185. ethpm/deployments.py +0 -80
  186. ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
  187. ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
  188. ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
  189. ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
  190. ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
  191. ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
  192. ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
  193. ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
  194. ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
  195. ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
  196. ethpm/ethpm-spec/examples/owned/v3.json +0 -1
  197. ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
  198. ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
  199. ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
  200. ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
  201. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
  202. ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
  203. ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
  204. ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
  205. ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
  206. ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
  207. ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
  208. ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
  209. ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
  210. ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
  211. ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
  212. ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
  213. ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
  214. ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
  215. ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
  216. ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
  217. ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
  218. ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
  219. ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
  220. ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
  221. ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
  222. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
  223. ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
  224. ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
  225. ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
  226. ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
  227. ethpm/ethpm-spec/spec/package.spec.json +0 -379
  228. ethpm/ethpm-spec/spec/v3.spec.json +0 -483
  229. ethpm/exceptions.py +0 -68
  230. ethpm/package.py +0 -438
  231. ethpm/tools/__init__.py +0 -4
  232. ethpm/tools/builder.py +0 -930
  233. ethpm/tools/checker.py +0 -312
  234. ethpm/tools/get_manifest.py +0 -19
  235. ethpm/uri.py +0 -141
  236. ethpm/validation/__init__.py +0 -0
  237. ethpm/validation/manifest.py +0 -146
  238. ethpm/validation/misc.py +0 -39
  239. ethpm/validation/package.py +0 -80
  240. ethpm/validation/uri.py +0 -163
  241. web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
  242. web3/_utils/miner.py +0 -88
  243. web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
  244. web3/_utils/request.py +0 -265
  245. web3/middleware/abi.py +0 -11
  246. web3/middleware/async_cache.py +0 -99
  247. web3/middleware/cache.py +0 -374
  248. web3/middleware/exception_handling.py +0 -49
  249. web3/middleware/exception_retry_request.py +0 -188
  250. web3/middleware/fixture.py +0 -190
  251. web3/middleware/geth_poa.py +0 -81
  252. web3/middleware/normalize_request_parameters.py +0 -11
  253. web3/middleware/simulate_unmined_transaction.py +0 -43
  254. web3/pm.py +0 -602
  255. web3/providers/async_rpc.py +0 -99
  256. web3/providers/rpc.py +0 -98
  257. web3/providers/websocket/__init__.py +0 -11
  258. web3/providers/websocket/websocket_connection.py +0 -42
  259. web3/tools/__init__.py +0 -4
  260. web3/tools/pytest_ethereum/__init__.py +0 -0
  261. web3/tools/pytest_ethereum/_utils.py +0 -145
  262. web3/tools/pytest_ethereum/deployer.py +0 -48
  263. web3/tools/pytest_ethereum/exceptions.py +0 -22
  264. web3/tools/pytest_ethereum/linker.py +0 -128
  265. web3/tools/pytest_ethereum/plugins.py +0 -33
  266. web3-6.20.3.dist-info/METADATA +0 -104
  267. web3-6.20.3.dist-info/RECORD +0 -283
  268. web3-6.20.3.dist-info/entry_points.txt +0 -2
  269. /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
  270. {web3-6.20.3.dist-info → web3-7.0.0.dist-info}/WHEEL +0 -0
@@ -1,190 +0,0 @@
1
- from typing import (
2
- TYPE_CHECKING,
3
- Any,
4
- Callable,
5
- Dict,
6
- Optional,
7
- cast,
8
- )
9
-
10
- from web3.types import (
11
- AsyncMiddleware,
12
- AsyncMiddlewareCoroutine,
13
- Middleware,
14
- RPCEndpoint,
15
- RPCResponse,
16
- )
17
-
18
- if TYPE_CHECKING:
19
- from web3.main import ( # noqa: F401
20
- AsyncWeb3,
21
- Web3,
22
- )
23
- from web3.providers import ( # noqa: F401
24
- PersistentConnectionProvider,
25
- )
26
-
27
-
28
- def construct_fixture_middleware(fixtures: Dict[RPCEndpoint, Any]) -> Middleware:
29
- """
30
- Constructs a middleware which returns a static response for any method
31
- which is found in the provided fixtures.
32
- """
33
-
34
- def fixture_middleware(
35
- make_request: Callable[[RPCEndpoint, Any], Any], _: "Web3"
36
- ) -> Callable[[RPCEndpoint, Any], RPCResponse]:
37
- def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
38
- if method in fixtures:
39
- result = fixtures[method]
40
- return {"result": result}
41
- else:
42
- return make_request(method, params)
43
-
44
- return middleware
45
-
46
- return fixture_middleware
47
-
48
-
49
- def construct_result_generator_middleware(
50
- result_generators: Dict[RPCEndpoint, Any]
51
- ) -> Middleware:
52
- """
53
- Constructs a middleware which intercepts requests for any method found in
54
- the provided mapping of endpoints to generator functions, returning
55
- whatever response the generator function returns. Callbacks must be
56
- functions with the signature `fn(method, params)`.
57
- """
58
-
59
- def result_generator_middleware(
60
- make_request: Callable[[RPCEndpoint, Any], Any], _: "Web3"
61
- ) -> Callable[[RPCEndpoint, Any], RPCResponse]:
62
- def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
63
- if method in result_generators:
64
- result = result_generators[method](method, params)
65
- return {"result": result}
66
- else:
67
- return make_request(method, params)
68
-
69
- return middleware
70
-
71
- return result_generator_middleware
72
-
73
-
74
- def construct_error_generator_middleware(
75
- error_generators: Dict[RPCEndpoint, Any]
76
- ) -> Middleware:
77
- """
78
- Constructs a middleware which intercepts requests for any method found in
79
- the provided mapping of endpoints to generator functions, returning
80
- whatever error message the generator function returns. Callbacks must be
81
- functions with the signature `fn(method, params)`.
82
- """
83
-
84
- def error_generator_middleware(
85
- make_request: Callable[[RPCEndpoint, Any], Any], _: "Web3"
86
- ) -> Callable[[RPCEndpoint, Any], RPCResponse]:
87
- def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
88
- if method in error_generators:
89
- error = error_generators[method](method, params)
90
- if isinstance(error, dict) and error.get("error", False):
91
- return {
92
- "error": {
93
- "code": error.get("code", -32000),
94
- "message": error["error"].get("message", ""),
95
- "data": error.get("data", ""),
96
- }
97
- }
98
- else:
99
- return {"error": error}
100
- else:
101
- return make_request(method, params)
102
-
103
- return middleware
104
-
105
- return error_generator_middleware
106
-
107
-
108
- # --- async --- #
109
-
110
-
111
- async def async_construct_result_generator_middleware(
112
- result_generators: Dict[RPCEndpoint, Any]
113
- ) -> AsyncMiddleware:
114
- """
115
- Constructs a middleware which returns a static response for any method
116
- which is found in the provided fixtures.
117
- """
118
-
119
- async def result_generator_middleware(
120
- make_request: Callable[[RPCEndpoint, Any], Any], async_w3: "AsyncWeb3"
121
- ) -> AsyncMiddlewareCoroutine:
122
- async def middleware(method: RPCEndpoint, params: Any) -> Optional[RPCResponse]:
123
- if method in result_generators:
124
- result = result_generators[method](method, params)
125
-
126
- if async_w3.provider.has_persistent_connection:
127
- provider = cast("PersistentConnectionProvider", async_w3.provider)
128
- response = await make_request(method, params)
129
- provider._request_processor.append_middleware_response_processor(
130
- # processed asynchronously later but need to pass the actual
131
- # response to the next middleware
132
- response,
133
- lambda _: {"result": result},
134
- )
135
- return response
136
- else:
137
- return {"result": result}
138
- else:
139
- return await make_request(method, params)
140
-
141
- return middleware
142
-
143
- return result_generator_middleware
144
-
145
-
146
- async def async_construct_error_generator_middleware(
147
- error_generators: Dict[RPCEndpoint, Any]
148
- ) -> AsyncMiddleware:
149
- """
150
- Constructs a middleware which intercepts requests for any method found in
151
- the provided mapping of endpoints to generator functions, returning
152
- whatever error message the generator function returns. Callbacks must be
153
- functions with the signature `fn(method, params)`.
154
- """
155
-
156
- async def error_generator_middleware(
157
- make_request: Callable[[RPCEndpoint, Any], Any], async_w3: "AsyncWeb3"
158
- ) -> AsyncMiddlewareCoroutine:
159
- async def middleware(method: RPCEndpoint, params: Any) -> Optional[RPCResponse]:
160
- if method in error_generators:
161
- error = error_generators[method](method, params)
162
- if isinstance(error, dict) and error.get("error", False):
163
- error_response = {
164
- "error": {
165
- "code": error.get("code", -32000),
166
- "message": error["error"].get("message", ""),
167
- "data": error.get("data", ""),
168
- }
169
- }
170
- else:
171
- error_response = {"error": error}
172
-
173
- if async_w3.provider.has_persistent_connection:
174
- provider = cast("PersistentConnectionProvider", async_w3.provider)
175
- response = await make_request(method, params)
176
- provider._request_processor.append_middleware_response_processor(
177
- # processed asynchronously later but need to pass the actual
178
- # response to the next middleware
179
- response,
180
- lambda _: error_response,
181
- )
182
- return response
183
- else:
184
- return cast(RPCResponse, error_response)
185
- else:
186
- return await make_request(method, params)
187
-
188
- return middleware
189
-
190
- return error_generator_middleware
@@ -1,81 +0,0 @@
1
- from typing import (
2
- TYPE_CHECKING,
3
- Any,
4
- Callable,
5
- )
6
-
7
- from eth_utils import (
8
- is_dict,
9
- )
10
- from eth_utils.curried import (
11
- apply_formatter_if,
12
- apply_formatters_to_dict,
13
- apply_key_map,
14
- is_null,
15
- )
16
- from eth_utils.toolz import (
17
- complement,
18
- compose,
19
- )
20
- from hexbytes import (
21
- HexBytes,
22
- )
23
-
24
- from web3._utils.rpc_abi import (
25
- RPC,
26
- )
27
- from web3.middleware.formatting import (
28
- async_construct_formatting_middleware,
29
- construct_formatting_middleware,
30
- )
31
- from web3.types import (
32
- AsyncMiddlewareCoroutine,
33
- RPCEndpoint,
34
- )
35
-
36
- if TYPE_CHECKING:
37
- from web3 import ( # noqa: F401
38
- AsyncWeb3,
39
- Web3,
40
- )
41
-
42
- is_not_null = complement(is_null)
43
-
44
- remap_geth_poa_fields = apply_key_map(
45
- {
46
- "extraData": "proofOfAuthorityData",
47
- }
48
- )
49
-
50
- pythonic_geth_poa = apply_formatters_to_dict(
51
- {
52
- "proofOfAuthorityData": HexBytes,
53
- }
54
- )
55
-
56
- geth_poa_cleanup = compose(pythonic_geth_poa, remap_geth_poa_fields)
57
-
58
-
59
- geth_poa_middleware = construct_formatting_middleware(
60
- result_formatters={
61
- RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, geth_poa_cleanup),
62
- RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, geth_poa_cleanup),
63
- },
64
- )
65
-
66
-
67
- async def async_geth_poa_middleware(
68
- make_request: Callable[[RPCEndpoint, Any], Any], w3: "AsyncWeb3"
69
- ) -> AsyncMiddlewareCoroutine:
70
- middleware = await async_construct_formatting_middleware(
71
- result_formatters={
72
- RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, geth_poa_cleanup),
73
- RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, geth_poa_cleanup),
74
- RPC.eth_subscribe: apply_formatter_if(
75
- is_not_null,
76
- # original call to eth_subscribe returns a string, needs a dict check
77
- apply_formatter_if(is_dict, geth_poa_cleanup),
78
- ),
79
- },
80
- )
81
- return await middleware(make_request, w3)
@@ -1,11 +0,0 @@
1
- from web3._utils.method_formatters import (
2
- METHOD_NORMALIZERS,
3
- )
4
-
5
- from .formatting import (
6
- construct_formatting_middleware,
7
- )
8
-
9
- request_parameter_normalizer = construct_formatting_middleware(
10
- request_formatters=METHOD_NORMALIZERS,
11
- )
@@ -1,43 +0,0 @@
1
- import collections
2
- import itertools
3
- from typing import (
4
- Any,
5
- Callable,
6
- )
7
-
8
- from eth_typing import (
9
- Hash32,
10
- )
11
-
12
- from web3 import (
13
- Web3,
14
- )
15
- from web3.types import (
16
- RPCEndpoint,
17
- RPCResponse,
18
- TxReceipt,
19
- )
20
-
21
- counter = itertools.count()
22
-
23
- INVOCATIONS_BEFORE_RESULT = 5
24
-
25
-
26
- def unmined_receipt_simulator_middleware(
27
- make_request: Callable[[RPCEndpoint, Any], Any], w3: Web3
28
- ) -> Callable[[RPCEndpoint, Any], RPCResponse]:
29
- receipt_counters: DefaultDict[Hash32, TxReceipt] = collections.defaultdict( # type: ignore # noqa: F821, E501
30
- itertools.count
31
- )
32
-
33
- def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
34
- if method == "eth_getTransactionReceipt":
35
- txn_hash = params[0]
36
- if next(receipt_counters[txn_hash]) < INVOCATIONS_BEFORE_RESULT:
37
- return {"result": None}
38
- else:
39
- return make_request(method, params)
40
- else:
41
- return make_request(method, params)
42
-
43
- return middleware