|
3 | 3 | from typing import Optional, Any, Union, TypedDict, Iterable |
4 | 4 |
|
5 | 5 | import aiohttp |
| 6 | +from async_substrate_interface.utils.storage import StorageKey |
6 | 7 | from bittensor_wallet import Wallet |
7 | 8 | from bittensor_wallet.utils import SS58_FORMAT |
8 | 9 | from scalecodec import GenericCall |
@@ -881,9 +882,10 @@ async def query_all_identities( |
881 | 882 | storage_function="IdentitiesV2", |
882 | 883 | block_hash=block_hash, |
883 | 884 | reuse_block_hash=reuse_block, |
| 885 | + fully_exhaust=True, |
884 | 886 | ) |
885 | 887 | all_identities = {} |
886 | | - async for ss58_address, identity in identities: |
| 888 | + for ss58_address, identity in identities.records: |
887 | 889 | all_identities[decode_account_id(ss58_address[0])] = decode_hex_identity( |
888 | 890 | identity.value |
889 | 891 | ) |
@@ -939,22 +941,22 @@ async def fetch_coldkey_hotkey_identities( |
939 | 941 | :param reuse_block: Whether to reuse the last-used blockchain block hash. |
940 | 942 | :return: Dict with 'coldkeys' and 'hotkeys' as keys. |
941 | 943 | """ |
942 | | - |
943 | | - coldkey_identities = await self.query_all_identities() |
| 944 | + if block_hash is None: |
| 945 | + block_hash = await self.substrate.get_chain_head() |
| 946 | + coldkey_identities = await self.query_all_identities(block_hash=block_hash) |
944 | 947 | identities = {"coldkeys": {}, "hotkeys": {}} |
945 | | - if not coldkey_identities: |
946 | | - return identities |
947 | | - query = await self.substrate.query_multiple( # TODO probably more efficient to do this with query_multi |
948 | | - params=list(coldkey_identities.keys()), |
949 | | - module="SubtensorModule", |
950 | | - storage_function="OwnedHotkeys", |
951 | | - block_hash=block_hash, |
952 | | - reuse_block_hash=reuse_block, |
953 | | - ) |
| 948 | + sks = [ |
| 949 | + await self.substrate.create_storage_key( |
| 950 | + "SubtensorModule", "OwnedHotkeys", [ck], block_hash=block_hash |
| 951 | + ) |
| 952 | + for ck in coldkey_identities.keys() |
| 953 | + ] |
| 954 | + query = await self.substrate.query_multi(sks, block_hash=block_hash) |
954 | 955 |
|
955 | | - for coldkey_ss58, hotkeys in query.items(): |
| 956 | + storage_key: StorageKey |
| 957 | + for storage_key, hotkeys in query: |
| 958 | + coldkey_ss58 = storage_key.params[0] |
956 | 959 | coldkey_identity = coldkey_identities.get(coldkey_ss58) |
957 | | - hotkeys = [decode_account_id(hotkey[0]) for hotkey in hotkeys or []] |
958 | 960 |
|
959 | 961 | identities["coldkeys"][coldkey_ss58] = { |
960 | 962 | "identity": coldkey_identity, |
|
0 commit comments