Skip to content

Commit

Permalink
asyncify eth.mining
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed Dec 14, 2021
1 parent e6cfe86 commit ce1f4b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ Eth
- :meth:`web3.eth.gas_price <web3.eth.Eth.gas_price>`
- :meth:`web3.eth.hashrate <web3.eth.Eth.hashrate>`
- :meth:`web3.eth.max_priority_fee <web3.eth.Eth.max_priority_fee>`
- :meth:`web3.eth.mining <web3.eth.Eth.mining>`
- :meth:`web3.eth.call() <web3.eth.Eth.call>`
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2252.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add async ``eth.mining`` method
8 changes: 8 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,14 @@ async def test_async_eth_chain_id(
# chain id value from geth fixture genesis file
assert chain_id == 131277322940537

@pytest.mark.asyncio
async def test_async_eth_mining(
self,
async_w3: "Web3"
) -> None:
mining = await async_w3.eth.mining # type: ignore
assert is_boolean(mining)


class EthModuleTest:
def test_eth_protocol_version(self, web3: "Web3") -> None:
Expand Down
52 changes: 28 additions & 24 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,46 @@ def call_munger(
mungers=None,
)

_is_mining: Method[Callable[[], bool]] = Method(
RPC.eth_mining,
mungers=None,
)


class AsyncEth(BaseEth):
is_async = True

@property
async def block_number(self) -> BlockNumber:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_block_number() # type: ignore

@property
async def chain_id(self) -> int:
return await self._chain_id() # type: ignore

@property
async def coinbase(self) -> ChecksumAddress:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_coinbase() # type: ignore

@property
async def gas_price(self) -> Wei:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._gas_price() # type: ignore

@property
async def hashrate(self) -> int:
return await self._get_hashrate() # type: ignore

@property
async def max_priority_fee(self) -> Wei:
return await self._max_priority_fee() # type: ignore

@property
async def mining(self) -> bool:
return await self._is_mining() # type: ignore

async def fee_history(
self,
block_count: int,
Expand Down Expand Up @@ -335,24 +362,6 @@ async def get_block(
# types ignored b/c mypy conflict with BlockingEth properties
return await self._get_block(block_identifier, full_transactions) # type: ignore

@property
async def block_number(self) -> BlockNumber:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_block_number() # type: ignore

@property
async def coinbase(self) -> ChecksumAddress:
# types ignored b/c mypy conflict with BlockingEth properties
return await self.get_coinbase() # type: ignore

@property
async def hashrate(self) -> int:
return await self._get_hashrate() # type: ignore

@property
async def chain_id(self) -> int:
return await self._chain_id() # type: ignore

_get_balance: Method[Callable[..., Awaitable[Wei]]] = Method(
RPC.eth_getBalance,
mungers=[BaseEth.block_id_munger],
Expand Down Expand Up @@ -448,14 +457,9 @@ def syncing(self) -> Union[SyncStatus, bool]:
def coinbase(self) -> ChecksumAddress:
return self.get_coinbase()

is_mining: Method[Callable[[], bool]] = Method(
RPC.eth_mining,
mungers=None,
)

@property
def mining(self) -> bool:
return self.is_mining()
return self._is_mining()

@property
def hashrate(self) -> int:
Expand Down

0 comments on commit ce1f4b0

Please sign in to comment.