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.accounts #2284

Merged
merged 1 commit into from
Jan 4, 2022
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 @@ -398,6 +398,7 @@ Supported Methods

Eth
***
- :meth:`web3.eth.accounts <web3.eth.Eth.accounts>`
- :meth:`web3.eth.block_number <web3.eth.Eth.block_number>`
- :meth:`web3.eth.chain_id <web3.eth.Eth.chain_id>`
- :meth:`web3.eth.coinbase <web3.eth.Eth.coinbase>`
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2284.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add async `eth.accounts` method
12 changes: 12 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,18 @@ async def test_async_eth_wait_for_transaction_receipt_with_log_entry(
assert log_entry['transactionIndex'] == 0
assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log)

@pytest.mark.asyncio
async def test_async_eth_accounts(self, async_w3: "Web3") -> None:
accounts = await async_w3.eth.accounts # type: ignore
assert is_list_like(accounts)
assert len(accounts) != 0
assert all((
is_checksum_address(account)
for account
in accounts
))
assert await async_w3.eth.coinbase in accounts # type: ignore


class EthModuleTest:
def test_eth_protocol_version(self, web3: "Web3") -> None:
Expand Down
16 changes: 10 additions & 6 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ def call_munger(
else:
return (transaction, block_identifier, state_override)

_get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
RPC.eth_accounts,
mungers=None,
)

_get_hashrate: Method[Callable[[], int]] = Method(
RPC.eth_hashrate,
mungers=None,
Expand All @@ -287,6 +292,10 @@ def call_munger(
class AsyncEth(BaseEth):
is_async = True

@property
async def accounts(self) -> Tuple[ChecksumAddress]:
return await self._get_accounts() # type: ignore

@property
async def block_number(self) -> BlockNumber:
# types ignored b/c mypy conflict with BlockingEth properties
Expand Down Expand Up @@ -514,14 +523,9 @@ def gasPrice(self) -> Wei:
)
return self.gas_price

get_accounts: Method[Callable[[], Tuple[ChecksumAddress]]] = Method(
RPC.eth_accounts,
mungers=None,
)

@property
def accounts(self) -> Tuple[ChecksumAddress]:
return self.get_accounts()
return self._get_accounts()

@property
def block_number(self) -> BlockNumber:
Expand Down