Skip to content

Commit 578b8e8

Browse files
committed
Minor refactoring for eth-tester middleware, separate async
1 parent 0569189 commit 578b8e8

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

web3/providers/eth_tester/middleware.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,6 @@ def is_hexstr(value: Any) -> bool:
307307
}
308308

309309

310-
async def async_ethereum_tester_middleware( # type: ignore
311-
make_request, web3: "Web3"
312-
) -> Middleware:
313-
middleware = await async_construct_formatting_middleware(
314-
request_formatters=request_formatters, result_formatters=result_formatters
315-
)
316-
return await middleware(make_request, web3)
317-
318-
319310
ethereum_tester_middleware = construct_formatting_middleware(
320311
request_formatters=request_formatters, result_formatters=result_formatters
321312
)
@@ -330,17 +321,6 @@ def guess_from(w3: "Web3", _: TxParams) -> ChecksumAddress:
330321
return None
331322

332323

333-
async def async_guess_from(async_w3: "Web3", _: TxParams) -> ChecksumAddress:
334-
coinbase = await async_w3.eth.coinbase # type: ignore
335-
accounts = await async_w3.eth.accounts # type: ignore
336-
if coinbase is not None:
337-
return coinbase
338-
elif accounts is not None and len(accounts) > 0:
339-
return accounts[0]
340-
341-
return None
342-
343-
344324
@curry
345325
def fill_default(
346326
field: str, guess_func: Callable[..., Any], w3: "Web3", transaction: TxParams
@@ -353,6 +333,28 @@ def fill_default(
353333
return assoc(transaction, field, guess_val)
354334

355335

336+
# --- async --- #
337+
338+
339+
async def async_ethereum_tester_middleware( # type: ignore
340+
make_request, web3: "Web3"
341+
) -> Middleware:
342+
middleware = await async_construct_formatting_middleware(
343+
request_formatters=request_formatters, result_formatters=result_formatters
344+
)
345+
return await middleware(make_request, web3)
346+
347+
348+
async def async_guess_from(async_w3: "Web3", _: TxParams) -> Optional[ChecksumAddress]:
349+
coinbase = await async_w3.eth.coinbase # type: ignore
350+
accounts = await async_w3.eth.accounts # type: ignore
351+
if coinbase is not None:
352+
return coinbase
353+
elif accounts is not None and len(accounts) > 0:
354+
return accounts[0]
355+
return None
356+
357+
356358
@curry
357359
async def async_fill_default(
358360
field: str, guess_func: Callable[..., Any], async_w3: "Web3", transaction: TxParams
@@ -368,14 +370,13 @@ async def async_fill_default(
368370
def default_transaction_fields_middleware(
369371
make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3"
370372
) -> Callable[[RPCEndpoint, Any], RPCResponse]:
371-
fill_default_from = fill_default("from", guess_from, w3)
372-
373373
def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
374374
if method in (
375375
"eth_call",
376376
"eth_estimateGas",
377377
"eth_sendTransaction",
378378
):
379+
fill_default_from = fill_default("from", guess_from, w3)
379380
filled_transaction = pipe(
380381
params[0],
381382
fill_default_from,

0 commit comments

Comments
 (0)