diff --git a/docs/providers.rst b/docs/providers.rst index fc7d62fa4f..2e9db94be6 100644 --- a/docs/providers.rst +++ b/docs/providers.rst @@ -404,6 +404,7 @@ Eth - :meth:`web3.eth.gas_price ` - :meth:`web3.eth.hashrate ` - :meth:`web3.eth.max_priority_fee ` +- :meth:`web3.eth.mining ` - :meth:`web3.eth.call() ` - :meth:`web3.eth.estimate_gas() ` - :meth:`web3.eth.generate_gas_price() ` diff --git a/newsfragments/2252.feature.rst b/newsfragments/2252.feature.rst new file mode 100644 index 0000000000..eec7e6f63c --- /dev/null +++ b/newsfragments/2252.feature.rst @@ -0,0 +1 @@ +Add async ``eth.mining`` method \ No newline at end of file diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index d76055b639..8840711027 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -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: diff --git a/web3/eth.py b/web3/eth.py index 0c2ddb7bf8..4deb398428 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -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, @@ -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], @@ -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: