Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncify eth.mining #2252

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetized and grouped properties at the top of the class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big fan of this re-org... properties before methods, etc... ty 👍

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