Skip to content

Commit

Permalink
Use web3_eth where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jun 4, 2021
1 parent 21a1553 commit 85bb477
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions web3/_utils/async_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if TYPE_CHECKING:
from web3 import Web3 # noqa: F401
from web3.eth import AsyncEth, Eth # noqa: F401
from web3.eth import AsyncEth # noqa: F401


async def get_block_gas_limit(
Expand All @@ -25,13 +25,13 @@ async def get_block_gas_limit(


async def get_buffered_gas_estimate(
web3_eth: "Eth", transaction: TxParams, gas_buffer: Wei = Wei(100000)
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
) -> Wei:
gas_estimate_transaction = cast(TxParams, dict(**transaction))

gas_estimate = await web3_eth.estimate_gas(gas_estimate_transaction) # type: ignore
gas_estimate = await web3.eth.estimate_gas(gas_estimate_transaction) # type: ignore

gas_limit = await get_block_gas_limit(web3_eth) # type: ignore
gas_limit = await get_block_gas_limit(web3.eth) # type: ignore

if gas_estimate > gas_limit:
raise ValueError(
Expand Down
13 changes: 6 additions & 7 deletions web3/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

if TYPE_CHECKING:
from web3 import Web3 # noqa: F401
from web3.eth import Eth # noqa: F401


@curry
Expand Down Expand Up @@ -113,21 +112,21 @@ def wait_for_transaction_receipt(
return txn_receipt


def get_block_gas_limit(web3_eth: "Eth", block_identifier: Optional[BlockIdentifier] = None) -> Wei:
def get_block_gas_limit(web3: "Web3", block_identifier: Optional[BlockIdentifier] = None) -> Wei:
if block_identifier is None:
block_identifier = web3_eth.block_number
block = web3_eth.get_block(block_identifier)
block_identifier = web3.eth.block_number
block = web3.eth.get_block(block_identifier)
return block['gasLimit']


def get_buffered_gas_estimate(
web3_eth: "Eth", transaction: TxParams, gas_buffer: Wei = Wei(100000)
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
) -> Wei:
gas_estimate_transaction = cast(TxParams, dict(**transaction))

gas_estimate = web3_eth.estimate_gas(gas_estimate_transaction)
gas_estimate = web3.eth.estimate_gas(gas_estimate_transaction)

gas_limit = get_block_gas_limit(web3_eth)
gas_limit = get_block_gas_limit(web3)

if gas_estimate > gas_limit:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions web3/middleware/buffered_gas_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
transaction = assoc(
transaction,
'gas',
hex(get_buffered_gas_estimate(web3.eth, transaction)),
hex(get_buffered_gas_estimate(web3, transaction)),
)
return make_request(method, [transaction])
return make_request(method, params)
Expand All @@ -48,7 +48,7 @@ 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.eth, transaction)
gas_estimate = await async_get_buffered_gas_estimate(web3, transaction)
transaction = assoc(
transaction,
'gas',
Expand Down

0 comments on commit 85bb477

Please sign in to comment.