-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark send_transaction and get_block
- Loading branch information
Showing
7 changed files
with
137 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Callable, | ||
Coroutine, | ||
) | ||
|
||
from eth_utils.toolz import ( | ||
assoc, | ||
) | ||
|
||
from web3._utils.transactions import ( | ||
async_get_buffered_gas_estimate, | ||
get_buffered_gas_estimate, | ||
) | ||
from web3.types import ( | ||
RPCEndpoint, | ||
RPCResponse, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from web3 import Web3 # noqa: F401 | ||
|
||
|
||
def buffered_gas_estimate_middleware( | ||
make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" | ||
) -> Callable[[RPCEndpoint, Any], RPCResponse]: | ||
def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: | ||
if method == 'eth_sendTransaction': | ||
transaction = params[0] | ||
if 'gas' not in transaction: | ||
transaction = assoc( | ||
transaction, | ||
'gas', | ||
hex(get_buffered_gas_estimate(web3.eth, transaction)), | ||
) | ||
return make_request(method, [transaction]) | ||
return make_request(method, params) | ||
return middleware | ||
|
||
|
||
async def async_buffered_gas_estimate_middleware( | ||
make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" | ||
) -> Callable[[RPCEndpoint, Any], Coroutine[Any, Any, RPCResponse]]: | ||
async def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: | ||
if method == 'eth_sendTransaction': | ||
transaction = params[0] | ||
if 'gas' not in transaction: | ||
gas_estimate = await async_get_buffered_gas_estimate(web3.async_eth, transaction) | ||
transaction = assoc( | ||
transaction, | ||
'gas', | ||
hex(gas_estimate) | ||
) | ||
return await make_request(method, [transaction]) | ||
return await make_request(method, params) | ||
return middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.