-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv9test.py
More file actions
50 lines (37 loc) · 1.36 KB
/
v9test.py
File metadata and controls
50 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import bittensor as bt
import asyncio
from bittensor.core.chain_data import (
decode_account_id,
)
from typing import cast
def extract_raw_data(data):
try:
fields = data.get('info', {}).get('fields', ())
if fields and isinstance(fields[0], tuple) and isinstance(fields[0][0], dict):
raw_dict = fields[0][0]
raw_key = next((k for k in raw_dict.keys() if k.startswith('Raw')), None)
if raw_key and raw_dict[raw_key]:
numbers = raw_dict[raw_key][0]
result = ''.join(chr(x) for x in numbers)
return result
except (IndexError, AttributeError):
pass
return None
async def main():
# Initialize subtensor
subtensor = bt.subtensor()
raw_commmitments = subtensor.query_map(
module="Commitments",
name="CommitmentOf",
params=[11])
for key, value in raw_commmitments:
try:
hotkey = decode_account_id(key[0])
body = cast(dict, value.value)
chain_str = extract_raw_data(body)
print(f"hotkey {hotkey} chain_str {chain_str} block {body['block']}")
except Exception as e:
print(e)
# Run the async function
if __name__ == "__main__":
asyncio.run(main())