Skip to content

Commit e2ffabf

Browse files
Fix gas types (#2330)
* fix: correct type for effectiveGasPrice (Wei, not int) * fix: correct type for gas and gas_limit (int, not Wei) * lint: removed unused type imports of Wei * Add newsfragment for Wei/int typing fixes Co-authored-by: kclowes <[email protected]>
1 parent 1284329 commit e2ffabf

File tree

8 files changed

+69
-69
lines changed

8 files changed

+69
-69
lines changed

docs/middleware.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Buffered Gas Estimate
7878
This adds a gas estimate to transactions if ``gas`` is not present in the transaction
7979
parameters. Sets gas to:
8080
``min(w3.eth.estimate_gas + gas_buffer, gas_limit)``
81-
where the gas_buffer default is 100,000 Wei
81+
where the gas_buffer default is 100,000
8282

8383
HTTPRequestRetry
8484
~~~~~~~~~~~~~~~~~~

newsfragments/2330.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fix types for ``gas``, and ``gasLimit`` (``Wei`` to ``int``)
2+
- Fix types for ``effectiveGasPrice``, (``int`` to ``Wei``)

web3/_utils/async_transactions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from web3.types import (
88
BlockIdentifier,
99
TxParams,
10-
Wei,
1110
)
1211

1312
if TYPE_CHECKING:
@@ -17,16 +16,16 @@
1716

1817
async def get_block_gas_limit(
1918
web3_eth: "AsyncEth", block_identifier: Optional[BlockIdentifier] = None
20-
) -> Wei:
19+
) -> int:
2120
if block_identifier is None:
2221
block_identifier = await web3_eth.block_number
2322
block = await web3_eth.get_block(block_identifier)
2423
return block['gasLimit']
2524

2625

2726
async def get_buffered_gas_estimate(
28-
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
29-
) -> Wei:
27+
web3: "Web3", transaction: TxParams, gas_buffer: int = 100000
28+
) -> int:
3029
gas_estimate_transaction = cast(TxParams, dict(**transaction))
3130

3231
gas_estimate = await web3.eth.estimate_gas(gas_estimate_transaction) # type: ignore
@@ -40,4 +39,4 @@ async def get_buffered_gas_estimate(
4039
"limit: {1}".format(gas_estimate, gas_limit)
4140
)
4241

43-
return Wei(min(gas_limit, gas_estimate + gas_buffer))
42+
return min(gas_limit, gas_estimate + gas_buffer)

0 commit comments

Comments
 (0)