Skip to content

Commit 0c76b1e

Browse files
authored
Fix delegate info type (#36)
* Fix delegate info type * Add bt-decode
1 parent b37ccfe commit 0c76b1e

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

bittensor_cli/src/bittensor/chain_data.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def get_null_neuron() -> "NeuronInfo":
248248
def from_vec_u8(cls, vec_u8: bytes) -> "NeuronInfo":
249249
n = bt_decode.NeuronInfo.decode(vec_u8)
250250
stake_dict = process_stake_data(n.stake)
251-
total_stake = sum(stake_dict.values())
251+
total_stake = sum(stake_dict.values()) if stake_dict else Balance(0)
252252
axon_info = n.axon_info
253253
coldkey = decode_account_id(n.coldkey)
254254
hotkey = decode_account_id(n.hotkey)
@@ -368,7 +368,7 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["NeuronInfoLite"]:
368368
pruning_score = item.pruning_score
369369
rank = item.rank
370370
stake_dict = process_stake_data(item.stake)
371-
stake = sum(stake_dict.values())
371+
stake = sum(stake_dict.values()) if stake_dict else Balance(0)
372372
trust = item.trust
373373
uid = item.uid
374374
validator_permit = item.validator_permit
@@ -452,8 +452,10 @@ def from_vec_u8(cls, vec_u8: bytes) -> Optional["DelegateInfo"]:
452452
decoded = bt_decode.DelegateInfo.decode(vec_u8)
453453
hotkey = decode_account_id(decoded.delegate_ss58)
454454
owner = decode_account_id(decoded.owner_ss58)
455-
nominators = process_stake_data(decoded.nominators)
456-
total_stake = sum(nominators.values())
455+
nominators = [
456+
(decode_account_id(x), Balance.from_rao(y)) for x, y in decoded.nominators
457+
]
458+
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
457459
return DelegateInfo(
458460
hotkey_ss58=hotkey,
459461
total_stake=total_stake,
@@ -473,8 +475,10 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["DelegateInfo"]:
473475
for d in decoded:
474476
hotkey = decode_account_id(d.delegate_ss58)
475477
owner = decode_account_id(d.owner_ss58)
476-
nominators = process_stake_data(d.nominators)
477-
total_stake = sum(nominators.values())
478+
nominators = [
479+
(decode_account_id(x), Balance.from_rao(y)) for x, y in d.nominators
480+
]
481+
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
478482
results.append(
479483
DelegateInfo(
480484
hotkey_ss58=hotkey,
@@ -497,10 +501,13 @@ def delegated_list_from_vec_u8(
497501
decoded = bt_decode.DelegateInfo.decode_delegated(vec_u8)
498502
results = []
499503
for d, b in decoded:
500-
nominators = process_stake_data(d.nominators)
504+
nominators = [
505+
(decode_account_id(x), Balance.from_rao(y)) for x, y in d.nominators
506+
]
507+
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
501508
delegate = DelegateInfo(
502509
hotkey_ss58=decode_account_id(d.delegate_ss58),
503-
total_stake=sum(nominators.values()),
510+
total_stake=total_stake,
504511
nominators=nominators,
505512
owner_ss58=decode_account_id(d.owner_ss58),
506513
take=d.take,

bittensor_cli/src/bittensor/minigraph.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,11 @@ async def get_total_subnets():
186186
return getattr(_result, "value", 0)
187187

188188
async def get_subnets():
189-
_result = await self.subtensor.substrate.query_map(
189+
_result = await self.subtensor.substrate.query(
190190
module="SubtensorModule",
191-
storage_function="NetworksAdded",
192-
params=[],
193-
reuse_block_hash=True,
194-
)
195-
return (
196-
[network[0].value for network in _result.records]
197-
if _result and hasattr(_result, "records")
198-
else []
191+
storage_function="TotalNetworks",
199192
)
193+
return [i for i in range(_result)]
200194

201195
data_array = []
202196
n_subnets, subnets = await asyncio.gather(get_total_subnets(), get_subnets())

bittensor_cli/src/commands/root.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -1474,13 +1474,11 @@ async def list_delegates(subtensor: SubtensorInterface):
14741474
block_hash=block_hash
14751475
)
14761476

1477-
try:
1478-
prev_block_hash = await subtensor.substrate.get_block_hash(
1479-
max(0, block_number - 1200)
1480-
)
1481-
prev_delegates = await subtensor.get_delegates(block_hash=prev_block_hash)
1482-
except SubstrateRequestException:
1483-
prev_delegates = None
1477+
# TODO keep an eye on this, was not working at one point
1478+
prev_block_hash = await subtensor.substrate.get_block_hash(
1479+
max(0, block_number - 1200)
1480+
)
1481+
prev_delegates = await subtensor.get_delegates(block_hash=prev_block_hash)
14841482

14851483
if prev_delegates is None:
14861484
err_console.print(
@@ -1592,7 +1590,6 @@ async def list_delegates(subtensor: SubtensorInterface):
15921590
rate_change_in_stake_str = "[grey0]0%[/grey0]"
15931591
else:
15941592
rate_change_in_stake_str = "[grey0]NA[/grey0]"
1595-
15961593
table.add_row(
15971594
# INDEX
15981595
str(i),

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ substrate-interface~=1.7.9
1515
typer~=0.12
1616
websockets>=12.0
1717
git+ssh://[email protected]/opentensor/btwallet.git@main#egg=bittensor-wallet
18-
# bt_decode # TODO get this from github
18+
bt-decode

0 commit comments

Comments
 (0)