web3 7.0.0b6__py3-none-any.whl → 7.0.0b7__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
- web3/__init__.py +21 -5
- 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/http.py +3 -0
- web3/_utils/http_session_manager.py +280 -0
- web3/_utils/method_formatters.py +0 -2
- web3/_utils/module_testing/eth_module.py +82 -109
- web3/_utils/module_testing/module_testing_utils.py +14 -9
- web3/_utils/module_testing/persistent_connection_provider.py +1 -0
- web3/_utils/rpc_abi.py +0 -3
- web3/beacon/__init__.py +5 -0
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/beacon.py +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/base_contract.py +10 -1
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +0 -33
- web3/eth/eth.py +2 -53
- web3/middleware/__init__.py +17 -0
- web3/providers/__init__.py +21 -0
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +0 -6
- web3/providers/eth_tester/middleware.py +3 -8
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +16 -12
- web3/providers/rpc/rpc.py +16 -12
- web3/providers/rpc/utils.py +0 -3
- web3/tools/benchmark/main.py +7 -6
- web3/tools/benchmark/node.py +1 -1
- web3/utils/__init__.py +14 -5
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/exception_handling.py +7 -5
- {web3-7.0.0b6.dist-info → web3-7.0.0b7.dist-info}/METADATA +7 -5
- {web3-7.0.0b6.dist-info → web3-7.0.0b7.dist-info}/RECORD +58 -59
- {web3-7.0.0b6.dist-info → web3-7.0.0b7.dist-info}/WHEEL +1 -1
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/request.py +0 -265
- {web3-7.0.0b6.dist-info → web3-7.0.0b7.dist-info}/LICENSE +0 -0
- {web3-7.0.0b6.dist-info → web3-7.0.0b7.dist-info}/top_level.txt +0 -0
web3/eth/__init__.py
CHANGED
web3/eth/async_eth.py
CHANGED
|
@@ -127,17 +127,6 @@ class AsyncEth(BaseEth):
|
|
|
127
127
|
async def accounts(self) -> Tuple[ChecksumAddress]:
|
|
128
128
|
return await self._accounts()
|
|
129
129
|
|
|
130
|
-
# eth_hashrate
|
|
131
|
-
|
|
132
|
-
_hashrate: Method[Callable[[], Awaitable[int]]] = Method(
|
|
133
|
-
RPC.eth_hashrate,
|
|
134
|
-
is_property=True,
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
@property
|
|
138
|
-
async def hashrate(self) -> int:
|
|
139
|
-
return await self._hashrate()
|
|
140
|
-
|
|
141
130
|
# eth_blockNumber
|
|
142
131
|
|
|
143
132
|
get_block_number: Method[Callable[[], Awaitable[BlockNumber]]] = Method(
|
|
@@ -160,17 +149,6 @@ class AsyncEth(BaseEth):
|
|
|
160
149
|
async def chain_id(self) -> int:
|
|
161
150
|
return await self._chain_id()
|
|
162
151
|
|
|
163
|
-
# eth_coinbase
|
|
164
|
-
|
|
165
|
-
_coinbase: Method[Callable[[], Awaitable[ChecksumAddress]]] = Method(
|
|
166
|
-
RPC.eth_coinbase,
|
|
167
|
-
is_property=True,
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
@property
|
|
171
|
-
async def coinbase(self) -> ChecksumAddress:
|
|
172
|
-
return await self._coinbase()
|
|
173
|
-
|
|
174
152
|
# eth_gasPrice
|
|
175
153
|
|
|
176
154
|
_gas_price: Method[Callable[[], Awaitable[Wei]]] = Method(
|
|
@@ -206,17 +184,6 @@ class AsyncEth(BaseEth):
|
|
|
206
184
|
)
|
|
207
185
|
return await async_fee_history_priority_fee(self)
|
|
208
186
|
|
|
209
|
-
# eth_mining
|
|
210
|
-
|
|
211
|
-
_mining: Method[Callable[[], Awaitable[bool]]] = Method(
|
|
212
|
-
RPC.eth_mining,
|
|
213
|
-
is_property=True,
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
@property
|
|
217
|
-
async def mining(self) -> bool:
|
|
218
|
-
return await self._mining()
|
|
219
|
-
|
|
220
187
|
# eth_syncing
|
|
221
188
|
|
|
222
189
|
_syncing: Method[Callable[[], Awaitable[Union[SyncStatus, bool]]]] = Method(
|
web3/eth/eth.py
CHANGED
|
@@ -119,17 +119,6 @@ class Eth(BaseEth):
|
|
|
119
119
|
def accounts(self) -> Tuple[ChecksumAddress]:
|
|
120
120
|
return self._accounts()
|
|
121
121
|
|
|
122
|
-
# eth_hashrate
|
|
123
|
-
|
|
124
|
-
_hashrate: Method[Callable[[], int]] = Method(
|
|
125
|
-
RPC.eth_hashrate,
|
|
126
|
-
is_property=True,
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
@property
|
|
130
|
-
def hashrate(self) -> int:
|
|
131
|
-
return self._hashrate()
|
|
132
|
-
|
|
133
122
|
# eth_blockNumber
|
|
134
123
|
|
|
135
124
|
get_block_number: Method[Callable[[], BlockNumber]] = Method(
|
|
@@ -152,17 +141,6 @@ class Eth(BaseEth):
|
|
|
152
141
|
def chain_id(self) -> int:
|
|
153
142
|
return self._chain_id()
|
|
154
143
|
|
|
155
|
-
# eth_coinbase
|
|
156
|
-
|
|
157
|
-
_coinbase: Method[Callable[[], ChecksumAddress]] = Method(
|
|
158
|
-
RPC.eth_coinbase,
|
|
159
|
-
is_property=True,
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
@property
|
|
163
|
-
def coinbase(self) -> ChecksumAddress:
|
|
164
|
-
return self._coinbase()
|
|
165
|
-
|
|
166
144
|
# eth_gasPrice
|
|
167
145
|
|
|
168
146
|
_gas_price: Method[Callable[[], Wei]] = Method(
|
|
@@ -198,17 +176,6 @@ class Eth(BaseEth):
|
|
|
198
176
|
)
|
|
199
177
|
return fee_history_priority_fee(self)
|
|
200
178
|
|
|
201
|
-
# eth_mining
|
|
202
|
-
|
|
203
|
-
_mining: Method[Callable[[], bool]] = Method(
|
|
204
|
-
RPC.eth_mining,
|
|
205
|
-
is_property=True,
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
@property
|
|
209
|
-
def mining(self) -> bool:
|
|
210
|
-
return self._mining()
|
|
211
|
-
|
|
212
179
|
# eth_syncing
|
|
213
180
|
|
|
214
181
|
_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
|
|
@@ -285,7 +252,8 @@ class Eth(BaseEth):
|
|
|
285
252
|
return self._call(transaction, block_identifier, state_override)
|
|
286
253
|
except OffchainLookup as offchain_lookup:
|
|
287
254
|
durin_calldata = handle_offchain_lookup(
|
|
288
|
-
offchain_lookup.payload,
|
|
255
|
+
offchain_lookup.payload,
|
|
256
|
+
transaction,
|
|
289
257
|
)
|
|
290
258
|
transaction["data"] = durin_calldata
|
|
291
259
|
|
|
@@ -660,25 +628,6 @@ class Eth(BaseEth):
|
|
|
660
628
|
mungers=[default_root_munger],
|
|
661
629
|
)
|
|
662
630
|
|
|
663
|
-
# eth_submitHashrate
|
|
664
|
-
|
|
665
|
-
submit_hashrate: Method[Callable[[int, _Hash32], bool]] = Method(
|
|
666
|
-
RPC.eth_submitHashrate,
|
|
667
|
-
mungers=[default_root_munger],
|
|
668
|
-
)
|
|
669
|
-
|
|
670
|
-
# eth_getWork, eth_submitWork
|
|
671
|
-
|
|
672
|
-
get_work: Method[Callable[[], List[HexBytes]]] = Method(
|
|
673
|
-
RPC.eth_getWork,
|
|
674
|
-
is_property=True,
|
|
675
|
-
)
|
|
676
|
-
|
|
677
|
-
submit_work: Method[Callable[[int, _Hash32, _Hash32], bool]] = Method(
|
|
678
|
-
RPC.eth_submitWork,
|
|
679
|
-
mungers=[default_root_munger],
|
|
680
|
-
)
|
|
681
|
-
|
|
682
631
|
@overload
|
|
683
632
|
# type error: Overloaded function signatures 1 and 2 overlap with incompatible return types # noqa: E501
|
|
684
633
|
def contract(self, address: None = None, **kwargs: Any) -> Type[Contract]: # type: ignore[overload-overlap] # noqa: E501
|
web3/middleware/__init__.py
CHANGED
|
@@ -92,3 +92,20 @@ async def async_combine_middleware(
|
|
|
92
92
|
initialized = mw(async_w3)
|
|
93
93
|
accumulator_fn = await initialized.async_wrap_make_request(accumulator_fn)
|
|
94
94
|
return accumulator_fn
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
__all__ = [
|
|
98
|
+
"AttributeDictMiddleware",
|
|
99
|
+
"Middleware",
|
|
100
|
+
"Web3Middleware",
|
|
101
|
+
"BufferedGasEstimateMiddleware",
|
|
102
|
+
"LocalFilterMiddleware",
|
|
103
|
+
"FormattingMiddlewareBuilder",
|
|
104
|
+
"GasPriceStrategyMiddleware",
|
|
105
|
+
"ENSNameToAddressMiddleware",
|
|
106
|
+
"ExtraDataToPOAMiddleware",
|
|
107
|
+
"PythonicMiddleware",
|
|
108
|
+
"SignAndSendRawMiddlewareBuilder",
|
|
109
|
+
"StalecheckMiddlewareBuilder",
|
|
110
|
+
"ValidationMiddleware",
|
|
111
|
+
]
|
web3/providers/__init__.py
CHANGED
|
@@ -8,6 +8,10 @@ from .base import (
|
|
|
8
8
|
BaseProvider,
|
|
9
9
|
JSONBaseProvider,
|
|
10
10
|
)
|
|
11
|
+
from .eth_tester import (
|
|
12
|
+
AsyncEthereumTesterProvider,
|
|
13
|
+
EthereumTesterProvider,
|
|
14
|
+
)
|
|
11
15
|
from .ipc import (
|
|
12
16
|
IPCProvider,
|
|
13
17
|
)
|
|
@@ -26,3 +30,20 @@ from .persistent import (
|
|
|
26
30
|
from .auto import (
|
|
27
31
|
AutoProvider,
|
|
28
32
|
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"AsyncBaseProvider",
|
|
36
|
+
"AsyncEthereumTesterProvider",
|
|
37
|
+
"AsyncHTTPProvider",
|
|
38
|
+
"AsyncIPCProvider",
|
|
39
|
+
"AutoProvider",
|
|
40
|
+
"BaseProvider",
|
|
41
|
+
"EthereumTesterProvider",
|
|
42
|
+
"HTTPProvider",
|
|
43
|
+
"IPCProvider",
|
|
44
|
+
"JSONBaseProvider",
|
|
45
|
+
"LegacyWebSocketProvider",
|
|
46
|
+
"PersistentConnection",
|
|
47
|
+
"PersistentConnectionProvider",
|
|
48
|
+
"WebSocketProvider",
|
|
49
|
+
]
|
|
@@ -243,12 +243,6 @@ API_ENDPOINTS = {
|
|
|
243
243
|
"eth": {
|
|
244
244
|
"protocolVersion": static_return(63),
|
|
245
245
|
"syncing": static_return(False),
|
|
246
|
-
"coinbase": compose(
|
|
247
|
-
operator.itemgetter(0),
|
|
248
|
-
call_eth_tester("get_accounts"),
|
|
249
|
-
),
|
|
250
|
-
"mining": static_return(False),
|
|
251
|
-
"hashrate": static_return(0),
|
|
252
246
|
"chainId": static_return(131277322940537), # from fixture generation file
|
|
253
247
|
"feeHistory": call_eth_tester("get_fee_history"),
|
|
254
248
|
"maxPriorityFeePerGas": static_return(10**9),
|
|
@@ -59,7 +59,7 @@ if TYPE_CHECKING:
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def is_named_block(value: Any) -> bool:
|
|
62
|
-
return value in {"latest", "earliest", "
|
|
62
|
+
return value in {"latest", "earliest", "safe", "finalized"}
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
def is_hexstr(value: Any) -> bool:
|
|
@@ -334,9 +334,7 @@ result_formatters: Optional[Dict[RPCEndpoint, Callable[..., Any]]] = {
|
|
|
334
334
|
|
|
335
335
|
|
|
336
336
|
def guess_from(w3: "Web3", _: TxParams) -> ChecksumAddress:
|
|
337
|
-
if w3.eth.
|
|
338
|
-
return w3.eth.coinbase
|
|
339
|
-
elif w3.eth.accounts and len(w3.eth.accounts) > 0:
|
|
337
|
+
if w3.eth.accounts and len(w3.eth.accounts) > 0:
|
|
340
338
|
return w3.eth.accounts[0]
|
|
341
339
|
|
|
342
340
|
return None
|
|
@@ -360,11 +358,8 @@ def fill_default(
|
|
|
360
358
|
async def async_guess_from(
|
|
361
359
|
async_w3: "AsyncWeb3", _: TxParams
|
|
362
360
|
) -> Optional[ChecksumAddress]:
|
|
363
|
-
coinbase = await async_w3.eth.coinbase
|
|
364
361
|
accounts = await async_w3.eth.accounts
|
|
365
|
-
if
|
|
366
|
-
return coinbase
|
|
367
|
-
elif accounts is not None and len(accounts) > 0:
|
|
362
|
+
if accounts is not None and len(accounts) > 0:
|
|
368
363
|
return accounts[0]
|
|
369
364
|
return None
|
|
370
365
|
|
web3/providers/rpc/__init__.py
CHANGED
web3/providers/rpc/async_rpc.py
CHANGED
|
@@ -29,11 +29,6 @@ from web3._utils.empty import (
|
|
|
29
29
|
from web3._utils.http import (
|
|
30
30
|
construct_user_agent,
|
|
31
31
|
)
|
|
32
|
-
from web3._utils.request import (
|
|
33
|
-
async_cache_and_return_session as _async_cache_and_return_session,
|
|
34
|
-
async_make_post_request,
|
|
35
|
-
get_default_http_endpoint,
|
|
36
|
-
)
|
|
37
32
|
from web3.types import (
|
|
38
33
|
RPCEndpoint,
|
|
39
34
|
RPCResponse,
|
|
@@ -45,6 +40,9 @@ from ..._utils.batching import (
|
|
|
45
40
|
from ..._utils.caching import (
|
|
46
41
|
async_handle_request_caching,
|
|
47
42
|
)
|
|
43
|
+
from ..._utils.http_session_manager import (
|
|
44
|
+
HTTPSessionManager,
|
|
45
|
+
)
|
|
48
46
|
from ..async_base import (
|
|
49
47
|
AsyncJSONBaseProvider,
|
|
50
48
|
)
|
|
@@ -63,13 +61,17 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
63
61
|
self,
|
|
64
62
|
endpoint_uri: Optional[Union[URI, str]] = None,
|
|
65
63
|
request_kwargs: Optional[Any] = None,
|
|
66
|
-
exception_retry_configuration:
|
|
67
|
-
ExceptionRetryConfiguration, Empty
|
|
64
|
+
exception_retry_configuration: Optional[
|
|
65
|
+
Union[ExceptionRetryConfiguration, Empty]
|
|
68
66
|
] = empty,
|
|
69
67
|
**kwargs: Any,
|
|
70
68
|
) -> None:
|
|
69
|
+
self._request_session_manager = HTTPSessionManager()
|
|
70
|
+
|
|
71
71
|
if endpoint_uri is None:
|
|
72
|
-
self.endpoint_uri =
|
|
72
|
+
self.endpoint_uri = (
|
|
73
|
+
self._request_session_manager.get_default_http_endpoint()
|
|
74
|
+
)
|
|
73
75
|
else:
|
|
74
76
|
self.endpoint_uri = URI(endpoint_uri)
|
|
75
77
|
|
|
@@ -79,7 +81,9 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
79
81
|
super().__init__(**kwargs)
|
|
80
82
|
|
|
81
83
|
async def cache_async_session(self, session: ClientSession) -> ClientSession:
|
|
82
|
-
return await
|
|
84
|
+
return await self._request_session_manager.async_cache_and_return_session(
|
|
85
|
+
self.endpoint_uri, session
|
|
86
|
+
)
|
|
83
87
|
|
|
84
88
|
def __str__(self) -> str:
|
|
85
89
|
return f"RPC connection {self.endpoint_uri}"
|
|
@@ -123,7 +127,7 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
123
127
|
):
|
|
124
128
|
for i in range(self.exception_retry_configuration.retries):
|
|
125
129
|
try:
|
|
126
|
-
return await async_make_post_request(
|
|
130
|
+
return await self._request_session_manager.async_make_post_request(
|
|
127
131
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
128
132
|
)
|
|
129
133
|
except tuple(self.exception_retry_configuration.errors):
|
|
@@ -136,7 +140,7 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
136
140
|
raise
|
|
137
141
|
return None
|
|
138
142
|
else:
|
|
139
|
-
return await async_make_post_request(
|
|
143
|
+
return await self._request_session_manager.async_make_post_request(
|
|
140
144
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
141
145
|
)
|
|
142
146
|
|
|
@@ -159,7 +163,7 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
159
163
|
) -> List[RPCResponse]:
|
|
160
164
|
self.logger.debug(f"Making batch request HTTP - uri: `{self.endpoint_uri}`")
|
|
161
165
|
request_data = self.encode_batch_rpc_request(batch_requests)
|
|
162
|
-
raw_response = await async_make_post_request(
|
|
166
|
+
raw_response = await self._request_session_manager.async_make_post_request(
|
|
163
167
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
164
168
|
)
|
|
165
169
|
self.logger.debug("Received batch response HTTP.")
|
web3/providers/rpc/rpc.py
CHANGED
|
@@ -27,11 +27,6 @@ from web3._utils.empty import (
|
|
|
27
27
|
from web3._utils.http import (
|
|
28
28
|
construct_user_agent,
|
|
29
29
|
)
|
|
30
|
-
from web3._utils.request import (
|
|
31
|
-
cache_and_return_session,
|
|
32
|
-
get_default_http_endpoint,
|
|
33
|
-
make_post_request,
|
|
34
|
-
)
|
|
35
30
|
from web3.types import (
|
|
36
31
|
RPCEndpoint,
|
|
37
32
|
RPCResponse,
|
|
@@ -43,6 +38,9 @@ from ..._utils.batching import (
|
|
|
43
38
|
from ..._utils.caching import (
|
|
44
39
|
handle_request_caching,
|
|
45
40
|
)
|
|
41
|
+
from ..._utils.http_session_manager import (
|
|
42
|
+
HTTPSessionManager,
|
|
43
|
+
)
|
|
46
44
|
from ..base import (
|
|
47
45
|
JSONBaseProvider,
|
|
48
46
|
)
|
|
@@ -67,13 +65,17 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
67
65
|
endpoint_uri: Optional[Union[URI, str]] = None,
|
|
68
66
|
request_kwargs: Optional[Any] = None,
|
|
69
67
|
session: Optional[Any] = None,
|
|
70
|
-
exception_retry_configuration:
|
|
71
|
-
ExceptionRetryConfiguration, Empty
|
|
68
|
+
exception_retry_configuration: Optional[
|
|
69
|
+
Union[ExceptionRetryConfiguration, Empty]
|
|
72
70
|
] = empty,
|
|
73
71
|
**kwargs: Any,
|
|
74
72
|
) -> None:
|
|
73
|
+
self._request_session_manager = HTTPSessionManager()
|
|
74
|
+
|
|
75
75
|
if endpoint_uri is None:
|
|
76
|
-
self.endpoint_uri =
|
|
76
|
+
self.endpoint_uri = (
|
|
77
|
+
self._request_session_manager.get_default_http_endpoint()
|
|
78
|
+
)
|
|
77
79
|
else:
|
|
78
80
|
self.endpoint_uri = URI(endpoint_uri)
|
|
79
81
|
|
|
@@ -81,7 +83,9 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
81
83
|
self._exception_retry_configuration = exception_retry_configuration
|
|
82
84
|
|
|
83
85
|
if session:
|
|
84
|
-
cache_and_return_session(
|
|
86
|
+
self._request_session_manager.cache_and_return_session(
|
|
87
|
+
self.endpoint_uri, session
|
|
88
|
+
)
|
|
85
89
|
|
|
86
90
|
super().__init__(**kwargs)
|
|
87
91
|
|
|
@@ -131,7 +135,7 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
131
135
|
):
|
|
132
136
|
for i in range(self.exception_retry_configuration.retries):
|
|
133
137
|
try:
|
|
134
|
-
return make_post_request(
|
|
138
|
+
return self._request_session_manager.make_post_request(
|
|
135
139
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
136
140
|
)
|
|
137
141
|
except tuple(self.exception_retry_configuration.errors) as e:
|
|
@@ -144,7 +148,7 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
144
148
|
raise e
|
|
145
149
|
return None
|
|
146
150
|
else:
|
|
147
|
-
return make_post_request(
|
|
151
|
+
return self._request_session_manager.make_post_request(
|
|
148
152
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
149
153
|
)
|
|
150
154
|
|
|
@@ -167,7 +171,7 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
167
171
|
) -> List[RPCResponse]:
|
|
168
172
|
self.logger.debug(f"Making batch request HTTP, uri: `{self.endpoint_uri}`")
|
|
169
173
|
request_data = self.encode_batch_rpc_request(batch_requests)
|
|
170
|
-
raw_response = make_post_request(
|
|
174
|
+
raw_response = self._request_session_manager.make_post_request(
|
|
171
175
|
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
172
176
|
)
|
|
173
177
|
self.logger.debug("Received batch response HTTP.")
|
web3/providers/rpc/utils.py
CHANGED
web3/tools/benchmark/main.py
CHANGED
|
@@ -108,13 +108,14 @@ def main(logger: logging.Logger, num_calls: int) -> None:
|
|
|
108
108
|
asyncio.set_event_loop(loop)
|
|
109
109
|
|
|
110
110
|
# -- sync -- #
|
|
111
|
-
|
|
111
|
+
account = w3_http.eth.accounts[0]
|
|
112
112
|
|
|
113
113
|
# -- async -- #
|
|
114
114
|
async_w3_http = loop.run_until_complete(
|
|
115
115
|
build_async_w3_http(fixture.endpoint_uri)
|
|
116
116
|
)
|
|
117
|
-
|
|
117
|
+
async_accounts = loop.run_until_complete(async_w3_http.eth.accounts)
|
|
118
|
+
async_account = async_accounts[0]
|
|
118
119
|
|
|
119
120
|
methods = [
|
|
120
121
|
{
|
|
@@ -126,17 +127,17 @@ def main(logger: logging.Logger, num_calls: int) -> None:
|
|
|
126
127
|
{
|
|
127
128
|
"name": "eth_sendTransaction",
|
|
128
129
|
"params": {},
|
|
129
|
-
"exec": lambda w3_http=w3_http,
|
|
130
|
+
"exec": lambda w3_http=w3_http, account=account: w3_http.eth.send_transaction( # noqa: E501
|
|
130
131
|
{
|
|
131
132
|
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
132
|
-
"from":
|
|
133
|
+
"from": account,
|
|
133
134
|
"value": Wei(1),
|
|
134
135
|
}
|
|
135
136
|
),
|
|
136
|
-
"async_exec": lambda async_w3_http=async_w3_http,
|
|
137
|
+
"async_exec": lambda async_w3_http=async_w3_http, async_account=async_account: async_w3_http.eth.send_transaction( # noqa: E501
|
|
137
138
|
{
|
|
138
139
|
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
139
|
-
"from":
|
|
140
|
+
"from": async_account,
|
|
140
141
|
"value": Wei(1),
|
|
141
142
|
}
|
|
142
143
|
),
|
web3/tools/benchmark/node.py
CHANGED
web3/utils/__init__.py
CHANGED
|
@@ -3,17 +3,26 @@ 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 .abi import (
|
|
7
7
|
get_abi_input_names,
|
|
8
8
|
get_abi_output_names,
|
|
9
9
|
)
|
|
10
|
-
from .address import get_create_address
|
|
11
|
-
from .async_exception_handling import (
|
|
10
|
+
from .address import get_create_address
|
|
11
|
+
from .async_exception_handling import (
|
|
12
12
|
async_handle_offchain_lookup,
|
|
13
13
|
)
|
|
14
|
-
from .caching import (
|
|
14
|
+
from .caching import (
|
|
15
15
|
SimpleCache,
|
|
16
16
|
)
|
|
17
|
-
from .exception_handling import (
|
|
17
|
+
from .exception_handling import (
|
|
18
18
|
handle_offchain_lookup,
|
|
19
19
|
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"SimpleCache",
|
|
23
|
+
"async_handle_offchain_lookup",
|
|
24
|
+
"get_abi_input_names",
|
|
25
|
+
"get_abi_output_names",
|
|
26
|
+
"get_create_address",
|
|
27
|
+
"handle_offchain_lookup",
|
|
28
|
+
]
|
|
@@ -3,6 +3,10 @@ from typing import (
|
|
|
3
3
|
Dict,
|
|
4
4
|
)
|
|
5
5
|
|
|
6
|
+
from aiohttp import (
|
|
7
|
+
ClientSession,
|
|
8
|
+
ClientTimeout,
|
|
9
|
+
)
|
|
6
10
|
from eth_abi import (
|
|
7
11
|
abi,
|
|
8
12
|
)
|
|
@@ -10,10 +14,8 @@ from eth_typing import (
|
|
|
10
14
|
URI,
|
|
11
15
|
)
|
|
12
16
|
|
|
13
|
-
from web3._utils.
|
|
14
|
-
|
|
15
|
-
async_get_response_from_get_request,
|
|
16
|
-
async_get_response_from_post_request,
|
|
17
|
+
from web3._utils.http import (
|
|
18
|
+
DEFAULT_HTTP_TIMEOUT,
|
|
17
19
|
)
|
|
18
20
|
from web3._utils.type_conversion import (
|
|
19
21
|
to_bytes_if_hex,
|
|
@@ -41,6 +43,7 @@ async def async_handle_offchain_lookup(
|
|
|
41
43
|
"`sender` value does not equal `to` address in transaction."
|
|
42
44
|
)
|
|
43
45
|
|
|
46
|
+
session = ClientSession()
|
|
44
47
|
for url in offchain_lookup_payload["urls"]:
|
|
45
48
|
formatted_url = URI(
|
|
46
49
|
str(url)
|
|
@@ -50,13 +53,17 @@ async def async_handle_offchain_lookup(
|
|
|
50
53
|
|
|
51
54
|
try:
|
|
52
55
|
if "{data}" in url and "{sender}" in url:
|
|
53
|
-
response = await
|
|
56
|
+
response = await session.get(
|
|
57
|
+
formatted_url, timeout=ClientTimeout(DEFAULT_HTTP_TIMEOUT)
|
|
58
|
+
)
|
|
54
59
|
elif "{sender}" in url:
|
|
55
|
-
response = await
|
|
60
|
+
response = await session.post(
|
|
56
61
|
formatted_url,
|
|
57
62
|
data={"data": formatted_data, "sender": formatted_sender},
|
|
63
|
+
timeout=ClientTimeout(DEFAULT_HTTP_TIMEOUT),
|
|
58
64
|
)
|
|
59
65
|
else:
|
|
66
|
+
await session.close()
|
|
60
67
|
raise Web3ValidationError("url not formatted properly.")
|
|
61
68
|
except Exception:
|
|
62
69
|
continue # try next url if timeout or issues making the request
|
|
@@ -64,13 +71,15 @@ async def async_handle_offchain_lookup(
|
|
|
64
71
|
if (
|
|
65
72
|
400 <= response.status <= 499
|
|
66
73
|
): # if request returns 400 error, raise exception
|
|
74
|
+
await session.close()
|
|
67
75
|
response.raise_for_status()
|
|
68
76
|
if not 200 <= response.status <= 299: # if not 400 error, try next url
|
|
69
77
|
continue
|
|
70
78
|
|
|
71
|
-
result = await
|
|
79
|
+
result = await response.json()
|
|
72
80
|
|
|
73
81
|
if "data" not in result.keys():
|
|
82
|
+
await session.close()
|
|
74
83
|
raise Web3ValidationError(
|
|
75
84
|
"Improperly formatted response for offchain lookup HTTP request"
|
|
76
85
|
" - missing 'data' field."
|
|
@@ -91,5 +100,8 @@ async def async_handle_offchain_lookup(
|
|
|
91
100
|
]
|
|
92
101
|
)
|
|
93
102
|
|
|
103
|
+
await session.close()
|
|
94
104
|
return encoded_data_with_function_selector
|
|
105
|
+
|
|
106
|
+
await session.close()
|
|
95
107
|
raise MultipleFailedRequests("Offchain lookup failed for supplied urls.")
|
web3/utils/exception_handling.py
CHANGED
|
@@ -9,10 +9,10 @@ from eth_abi import (
|
|
|
9
9
|
from eth_typing import (
|
|
10
10
|
URI,
|
|
11
11
|
)
|
|
12
|
+
import requests
|
|
12
13
|
|
|
13
|
-
from web3._utils.
|
|
14
|
-
|
|
15
|
-
get_response_from_post_request,
|
|
14
|
+
from web3._utils.http import (
|
|
15
|
+
DEFAULT_HTTP_TIMEOUT,
|
|
16
16
|
)
|
|
17
17
|
from web3._utils.type_conversion import (
|
|
18
18
|
to_bytes_if_hex,
|
|
@@ -40,6 +40,7 @@ def handle_offchain_lookup(
|
|
|
40
40
|
"Returned `sender` value does not equal `to` address in transaction."
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
+
session = requests.Session()
|
|
43
44
|
for url in offchain_lookup_payload["urls"]:
|
|
44
45
|
formatted_url = URI(
|
|
45
46
|
str(url)
|
|
@@ -49,14 +50,15 @@ def handle_offchain_lookup(
|
|
|
49
50
|
|
|
50
51
|
try:
|
|
51
52
|
if "{data}" in url and "{sender}" in url:
|
|
52
|
-
response =
|
|
53
|
+
response = session.get(formatted_url, timeout=DEFAULT_HTTP_TIMEOUT)
|
|
53
54
|
elif "{sender}" in url:
|
|
54
|
-
response =
|
|
55
|
+
response = session.post(
|
|
55
56
|
formatted_url,
|
|
56
57
|
data={
|
|
57
58
|
"data": formatted_data,
|
|
58
59
|
"sender": formatted_sender,
|
|
59
60
|
},
|
|
61
|
+
timeout=DEFAULT_HTTP_TIMEOUT,
|
|
60
62
|
)
|
|
61
63
|
else:
|
|
62
64
|
raise Web3ValidationError("url not formatted properly.")
|