bittensor-cli 8.1.1__py3-none-any.whl → 8.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bittensor_cli/__init__.py +1 -1
- bittensor_cli/cli.py +352 -181
- bittensor_cli/src/__init__.py +4 -2
- bittensor_cli/src/bittensor/async_substrate_interface.py +27 -17
- bittensor_cli/src/bittensor/extrinsics/registration.py +41 -24
- bittensor_cli/src/bittensor/extrinsics/root.py +10 -6
- bittensor_cli/src/bittensor/extrinsics/transfer.py +22 -5
- bittensor_cli/src/bittensor/subtensor_interface.py +16 -14
- bittensor_cli/src/bittensor/utils.py +78 -13
- bittensor_cli/src/commands/root.py +22 -8
- bittensor_cli/src/commands/stake/children_hotkeys.py +16 -8
- bittensor_cli/src/commands/stake/stake.py +7 -2
- bittensor_cli/src/commands/subnets.py +4 -2
- bittensor_cli/src/commands/sudo.py +1 -0
- bittensor_cli/src/commands/wallets.py +75 -65
- bittensor_cli/src/commands/weights.py +48 -45
- {bittensor_cli-8.1.1.dist-info → bittensor_cli-8.3.0.dist-info}/METADATA +2 -2
- bittensor_cli-8.3.0.dist-info/RECORD +31 -0
- bittensor_cli-8.1.1.dist-info/RECORD +0 -31
- {bittensor_cli-8.1.1.dist-info → bittensor_cli-8.3.0.dist-info}/WHEEL +0 -0
- {bittensor_cli-8.1.1.dist-info → bittensor_cli-8.3.0.dist-info}/entry_points.txt +0 -0
- {bittensor_cli-8.1.1.dist-info → bittensor_cli-8.3.0.dist-info}/top_level.txt +0 -0
@@ -11,9 +11,10 @@ from rich.prompt import Confirm
|
|
11
11
|
from rich.table import Column, Table
|
12
12
|
from rich.text import Text
|
13
13
|
from scalecodec import GenericCall, ScaleType
|
14
|
+
from substrateinterface.exceptions import SubstrateRequestException
|
14
15
|
import typer
|
15
16
|
|
16
|
-
from bittensor_cli.src import
|
17
|
+
from bittensor_cli.src import DelegatesDetails
|
17
18
|
from bittensor_cli.src.bittensor.balances import Balance
|
18
19
|
from bittensor_cli.src.bittensor.chain_data import (
|
19
20
|
DelegateInfo,
|
@@ -282,6 +283,7 @@ async def burned_register_extrinsic(
|
|
282
283
|
try:
|
283
284
|
wallet.unlock_coldkey()
|
284
285
|
except KeyFileError:
|
286
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
285
287
|
return False
|
286
288
|
|
287
289
|
with console.status(
|
@@ -538,6 +540,7 @@ async def delegate_extrinsic(
|
|
538
540
|
try:
|
539
541
|
wallet.unlock_coldkey()
|
540
542
|
except KeyFileError:
|
543
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
541
544
|
return False
|
542
545
|
|
543
546
|
print_verbose("Checking if hotkey is a delegate")
|
@@ -721,7 +724,7 @@ async def root_list(subtensor: SubtensorInterface):
|
|
721
724
|
|
722
725
|
rn: list[NeuronInfoLite] = await subtensor.neurons_lite(netuid=0)
|
723
726
|
if not rn:
|
724
|
-
return
|
727
|
+
return [], [], {}, {}
|
725
728
|
|
726
729
|
di: dict[str, DelegatesDetails] = await subtensor.get_delegate_identities()
|
727
730
|
ts: dict[str, ScaleType] = await subtensor.substrate.query_multiple(
|
@@ -1099,6 +1102,7 @@ async def senate_vote(
|
|
1099
1102
|
wallet.unlock_hotkey()
|
1100
1103
|
wallet.unlock_coldkey()
|
1101
1104
|
except KeyFileError:
|
1105
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
1102
1106
|
return False
|
1103
1107
|
|
1104
1108
|
console.print(f"Fetching proposals in [dark_orange]network: {subtensor.network}")
|
@@ -1322,6 +1326,7 @@ async def set_take(wallet: Wallet, subtensor: SubtensorInterface, take: float) -
|
|
1322
1326
|
wallet.unlock_hotkey()
|
1323
1327
|
wallet.unlock_coldkey()
|
1324
1328
|
except KeyFileError:
|
1329
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
1325
1330
|
return False
|
1326
1331
|
|
1327
1332
|
result_ = await _do_set_take()
|
@@ -1539,16 +1544,24 @@ async def list_delegates(subtensor: SubtensorInterface):
|
|
1539
1544
|
subtensor.get_delegates(block_hash=block_hash),
|
1540
1545
|
)
|
1541
1546
|
|
1542
|
-
# TODO keep an eye on this, was not working at one point
|
1543
1547
|
print_verbose("Fetching previous delegates info from chain", status)
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
+
|
1549
|
+
async def get_prev_delegates(fallback_offsets=(1200, 200)):
|
1550
|
+
for offset in fallback_offsets:
|
1551
|
+
try:
|
1552
|
+
prev_block_hash = await subtensor.substrate.get_block_hash(
|
1553
|
+
max(0, block_number - offset)
|
1554
|
+
)
|
1555
|
+
return await subtensor.get_delegates(block_hash=prev_block_hash)
|
1556
|
+
except SubstrateRequestException:
|
1557
|
+
continue
|
1558
|
+
return None
|
1559
|
+
|
1560
|
+
prev_delegates = await get_prev_delegates()
|
1548
1561
|
|
1549
1562
|
if prev_delegates is None:
|
1550
1563
|
err_console.print(
|
1551
|
-
":warning: [yellow]Could not fetch delegates history[/yellow]"
|
1564
|
+
":warning: [yellow]Could not fetch delegates history. [/yellow]"
|
1552
1565
|
)
|
1553
1566
|
|
1554
1567
|
delegates.sort(key=lambda d: d.total_stake, reverse=True)
|
@@ -1715,6 +1728,7 @@ async def nominate(wallet: Wallet, subtensor: SubtensorInterface, prompt: bool):
|
|
1715
1728
|
wallet.unlock_hotkey()
|
1716
1729
|
wallet.unlock_coldkey()
|
1717
1730
|
except KeyFileError:
|
1731
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
1718
1732
|
return False
|
1719
1733
|
|
1720
1734
|
print_verbose(f"Checking hotkey ({wallet.hotkey_str}) is a delegate")
|
@@ -18,6 +18,7 @@ from bittensor_cli.src.bittensor.utils import (
|
|
18
18
|
u16_to_float,
|
19
19
|
u64_to_float,
|
20
20
|
is_valid_ss58_address,
|
21
|
+
format_error_message,
|
21
22
|
)
|
22
23
|
|
23
24
|
|
@@ -208,8 +209,11 @@ async def set_childkey_take_extrinsic(
|
|
208
209
|
# )
|
209
210
|
return False, error_message
|
210
211
|
|
211
|
-
except
|
212
|
-
return
|
212
|
+
except SubstrateRequestException as e:
|
213
|
+
return (
|
214
|
+
False,
|
215
|
+
f"Exception occurred while setting childkey take: {format_error_message(e, subtensor.substrate)}",
|
216
|
+
)
|
213
217
|
|
214
218
|
|
215
219
|
async def get_childkey_take(subtensor, hotkey: str, netuid: int) -> Optional[int]:
|
@@ -232,7 +236,9 @@ async def get_childkey_take(subtensor, hotkey: str, netuid: int) -> Optional[int
|
|
232
236
|
return int(childkey_take_.value)
|
233
237
|
|
234
238
|
except SubstrateRequestException as e:
|
235
|
-
err_console.print(
|
239
|
+
err_console.print(
|
240
|
+
f"Error querying ChildKeys: {format_error_message(e, subtensor.substrate)}"
|
241
|
+
)
|
236
242
|
return None
|
237
243
|
|
238
244
|
|
@@ -488,6 +494,7 @@ async def set_children(
|
|
488
494
|
netuid: Optional[int] = None,
|
489
495
|
wait_for_inclusion: bool = True,
|
490
496
|
wait_for_finalization: bool = True,
|
497
|
+
prompt: bool = True,
|
491
498
|
):
|
492
499
|
"""Set children hotkeys."""
|
493
500
|
# Validate children SS58 addresses
|
@@ -514,7 +521,7 @@ async def set_children(
|
|
514
521
|
netuid=netuid,
|
515
522
|
hotkey=wallet.hotkey.ss58_address,
|
516
523
|
children_with_proportions=children_with_proportions,
|
517
|
-
prompt=
|
524
|
+
prompt=prompt,
|
518
525
|
wait_for_inclusion=wait_for_inclusion,
|
519
526
|
wait_for_finalization=wait_for_finalization,
|
520
527
|
)
|
@@ -543,7 +550,7 @@ async def set_children(
|
|
543
550
|
netuid=netuid,
|
544
551
|
hotkey=wallet.hotkey.ss58_address,
|
545
552
|
children_with_proportions=children_with_proportions,
|
546
|
-
prompt=
|
553
|
+
prompt=prompt,
|
547
554
|
wait_for_inclusion=True,
|
548
555
|
wait_for_finalization=False,
|
549
556
|
)
|
@@ -558,6 +565,7 @@ async def revoke_children(
|
|
558
565
|
netuid: Optional[int] = None,
|
559
566
|
wait_for_inclusion: bool = True,
|
560
567
|
wait_for_finalization: bool = True,
|
568
|
+
prompt: bool = True,
|
561
569
|
):
|
562
570
|
"""
|
563
571
|
Revokes the children hotkeys associated with a given network identifier (netuid).
|
@@ -569,7 +577,7 @@ async def revoke_children(
|
|
569
577
|
netuid=netuid,
|
570
578
|
hotkey=wallet.hotkey.ss58_address,
|
571
579
|
children_with_proportions=[],
|
572
|
-
prompt=
|
580
|
+
prompt=prompt,
|
573
581
|
wait_for_inclusion=wait_for_inclusion,
|
574
582
|
wait_for_finalization=wait_for_finalization,
|
575
583
|
)
|
@@ -598,7 +606,7 @@ async def revoke_children(
|
|
598
606
|
netuid=netuid,
|
599
607
|
hotkey=wallet.hotkey.ss58_address,
|
600
608
|
children_with_proportions=[],
|
601
|
-
prompt=
|
609
|
+
prompt=prompt,
|
602
610
|
wait_for_inclusion=True,
|
603
611
|
wait_for_finalization=False,
|
604
612
|
)
|
@@ -758,7 +766,7 @@ async def childkey_take(
|
|
758
766
|
netuid=netuid,
|
759
767
|
hotkey=wallet.hotkey.ss58_address,
|
760
768
|
take=take,
|
761
|
-
prompt=
|
769
|
+
prompt=prompt,
|
762
770
|
wait_for_inclusion=True,
|
763
771
|
wait_for_finalization=False,
|
764
772
|
)
|
@@ -106,6 +106,7 @@ async def add_stake_extrinsic(
|
|
106
106
|
try:
|
107
107
|
wallet.unlock_coldkey()
|
108
108
|
except KeyFileError:
|
109
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
109
110
|
return False
|
110
111
|
|
111
112
|
# Default to wallet's own hotkey if the value is not passed.
|
@@ -312,6 +313,7 @@ async def add_stake_multiple_extrinsic(
|
|
312
313
|
try:
|
313
314
|
wallet.unlock_coldkey()
|
314
315
|
except KeyFileError:
|
316
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
315
317
|
return False
|
316
318
|
|
317
319
|
with console.status(
|
@@ -493,6 +495,7 @@ async def unstake_extrinsic(
|
|
493
495
|
try:
|
494
496
|
wallet.unlock_coldkey()
|
495
497
|
except KeyFileError:
|
498
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
496
499
|
return False
|
497
500
|
|
498
501
|
if hotkey_ss58 is None:
|
@@ -523,7 +526,7 @@ async def unstake_extrinsic(
|
|
523
526
|
# Unstake it all.
|
524
527
|
unstaking_balance = old_stake
|
525
528
|
else:
|
526
|
-
unstaking_balance = amount
|
529
|
+
unstaking_balance = Balance.from_tao(amount)
|
527
530
|
|
528
531
|
# Check enough to unstake.
|
529
532
|
stake_on_uid = old_stake
|
@@ -561,7 +564,6 @@ async def unstake_extrinsic(
|
|
561
564
|
f":satellite: Unstaking from chain: [white]{subtensor}[/white] ...",
|
562
565
|
spinner="earth",
|
563
566
|
):
|
564
|
-
unstaking_balance = Balance.from_tao(unstaking_balance)
|
565
567
|
call = await subtensor.substrate.compose_call(
|
566
568
|
call_module="SubtensorModule",
|
567
569
|
call_function="remove_stake",
|
@@ -664,6 +666,7 @@ async def unstake_multiple_extrinsic(
|
|
664
666
|
try:
|
665
667
|
wallet.unlock_coldkey()
|
666
668
|
except KeyFileError:
|
669
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
667
670
|
return False
|
668
671
|
|
669
672
|
with console.status(
|
@@ -1179,6 +1182,7 @@ async def stake_add(
|
|
1179
1182
|
(wallet.hotkey_str, wallet.hotkey.ss58_address)
|
1180
1183
|
for wallet in all_hotkeys_
|
1181
1184
|
if wallet.hotkey_str not in exclude_hotkeys
|
1185
|
+
and wallet.hotkey.ss58_address not in exclude_hotkeys
|
1182
1186
|
] # definitely wallets
|
1183
1187
|
|
1184
1188
|
elif include_hotkeys:
|
@@ -1346,6 +1350,7 @@ async def unstake(
|
|
1346
1350
|
(wallet.hotkey_str, wallet.hotkey.ss58_address)
|
1347
1351
|
for wallet in all_hotkeys_
|
1348
1352
|
if wallet.hotkey_str not in exclude_hotkeys
|
1353
|
+
and wallet.hotkey.ss58_address not in hotkeys_to_unstake_from
|
1349
1354
|
] # definitely wallets
|
1350
1355
|
|
1351
1356
|
elif include_hotkeys:
|
@@ -103,6 +103,7 @@ async def register_subnetwork_extrinsic(
|
|
103
103
|
try:
|
104
104
|
wallet.unlock_coldkey()
|
105
105
|
except KeyFileError:
|
106
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
106
107
|
return False
|
107
108
|
|
108
109
|
with console.status(":satellite: Registering subnet...", spinner="earth"):
|
@@ -129,7 +130,7 @@ async def register_subnetwork_extrinsic(
|
|
129
130
|
await response.process_events()
|
130
131
|
if not await response.is_success:
|
131
132
|
err_console.print(
|
132
|
-
f":cross_mark: [red]Failed[/red]: {format_error_message(await response.error_message)}"
|
133
|
+
f":cross_mark: [red]Failed[/red]: {format_error_message(await response.error_message, substrate)}"
|
133
134
|
)
|
134
135
|
await asyncio.sleep(0.5)
|
135
136
|
return False
|
@@ -399,6 +400,7 @@ async def pow_register(
|
|
399
400
|
use_cuda,
|
400
401
|
dev_id,
|
401
402
|
threads_per_block,
|
403
|
+
prompt: bool,
|
402
404
|
):
|
403
405
|
"""Register neuron."""
|
404
406
|
|
@@ -406,7 +408,7 @@ async def pow_register(
|
|
406
408
|
subtensor,
|
407
409
|
wallet=wallet,
|
408
410
|
netuid=netuid,
|
409
|
-
prompt=
|
411
|
+
prompt=prompt,
|
410
412
|
tpb=threads_per_block,
|
411
413
|
update_interval=update_interval,
|
412
414
|
num_processes=processors,
|
@@ -4,10 +4,9 @@ import itertools
|
|
4
4
|
import os
|
5
5
|
import sys
|
6
6
|
from collections import defaultdict
|
7
|
-
from concurrent.futures import ProcessPoolExecutor
|
8
7
|
from functools import partial
|
9
8
|
from sys import getsizeof
|
10
|
-
from typing import
|
9
|
+
from typing import Collection, Generator, Optional
|
11
10
|
|
12
11
|
import aiohttp
|
13
12
|
from bittensor_wallet import Wallet
|
@@ -59,6 +58,13 @@ from bittensor_cli.src.bittensor.utils import (
|
|
59
58
|
)
|
60
59
|
|
61
60
|
|
61
|
+
class WalletLike:
|
62
|
+
def __init__(self, name=None, hotkey_ss58=None, hotkey_str=None):
|
63
|
+
self.name = name
|
64
|
+
self.hotkey_ss58 = hotkey_ss58
|
65
|
+
self.hotkey_str = hotkey_str
|
66
|
+
|
67
|
+
|
62
68
|
async def regen_coldkey(
|
63
69
|
wallet: Wallet,
|
64
70
|
mnemonic: Optional[str],
|
@@ -75,13 +81,21 @@ async def regen_coldkey(
|
|
75
81
|
with open(json_path, "r") as f:
|
76
82
|
json_str = f.read()
|
77
83
|
try:
|
78
|
-
wallet.regenerate_coldkey(
|
84
|
+
new_wallet = wallet.regenerate_coldkey(
|
79
85
|
mnemonic=mnemonic,
|
80
86
|
seed=seed,
|
81
87
|
json=(json_str, json_password) if all([json_str, json_password]) else None,
|
82
88
|
use_password=use_password,
|
83
89
|
overwrite=False,
|
84
90
|
)
|
91
|
+
|
92
|
+
if isinstance(new_wallet, Wallet):
|
93
|
+
console.print(
|
94
|
+
"\n✅ [dark_sea_green]Regenerated coldkey successfully!\n",
|
95
|
+
f"[dark_sea_green]Wallet name: ({new_wallet.name}), path: ({new_wallet.path}), coldkey ss58: ({new_wallet.coldkeypub.ss58_address})",
|
96
|
+
)
|
97
|
+
except ValueError:
|
98
|
+
print_error("Mnemonic phrase is invalid")
|
85
99
|
except KeyFileError:
|
86
100
|
print_error("KeyFileError: File is not writable")
|
87
101
|
|
@@ -93,11 +107,16 @@ async def regen_coldkey_pub(
|
|
93
107
|
):
|
94
108
|
"""Creates a new coldkeypub under this wallet."""
|
95
109
|
try:
|
96
|
-
wallet.regenerate_coldkeypub(
|
110
|
+
new_coldkeypub = wallet.regenerate_coldkeypub(
|
97
111
|
ss58_address=ss58_address,
|
98
112
|
public_key=public_key_hex,
|
99
113
|
overwrite=False,
|
100
114
|
)
|
115
|
+
if isinstance(new_coldkeypub, Wallet):
|
116
|
+
console.print(
|
117
|
+
"\n✅ [dark_sea_green]Regenerated coldkeypub successfully!\n",
|
118
|
+
f"[dark_sea_green]Wallet name: ({new_coldkeypub.name}), path: ({new_coldkeypub.path}), coldkey ss58: ({new_coldkeypub.coldkeypub.ss58_address})",
|
119
|
+
)
|
101
120
|
except KeyFileError:
|
102
121
|
print_error("KeyFileError: File is not writable")
|
103
122
|
|
@@ -120,13 +139,20 @@ async def regen_hotkey(
|
|
120
139
|
json_str = f.read()
|
121
140
|
|
122
141
|
try:
|
123
|
-
wallet.regenerate_hotkey(
|
142
|
+
new_hotkey = wallet.regenerate_hotkey(
|
124
143
|
mnemonic=mnemonic,
|
125
144
|
seed=seed,
|
126
145
|
json=(json_str, json_password) if all([json_str, json_password]) else None,
|
127
146
|
use_password=use_password,
|
128
147
|
overwrite=False,
|
129
148
|
)
|
149
|
+
if isinstance(new_hotkey, Wallet):
|
150
|
+
console.print(
|
151
|
+
"\n✅ [dark_sea_green]Regenerated hotkey successfully!\n",
|
152
|
+
f"[dark_sea_green]Wallet name: ({new_hotkey.name}), path: ({new_hotkey.path}), hotkey ss58: ({new_hotkey.hotkey.ss58_address})",
|
153
|
+
)
|
154
|
+
except ValueError:
|
155
|
+
print_error("Mnemonic phrase is invalid")
|
130
156
|
except KeyFileError:
|
131
157
|
print_error("KeyFileError: File is not writable")
|
132
158
|
|
@@ -221,16 +247,25 @@ def _get_coldkey_ss58_addresses_for_path(path: str) -> tuple[list[str], list[str
|
|
221
247
|
|
222
248
|
|
223
249
|
async def wallet_balance(
|
224
|
-
wallet: Wallet,
|
250
|
+
wallet: Optional[Wallet],
|
251
|
+
subtensor: SubtensorInterface,
|
252
|
+
all_balances: bool,
|
253
|
+
ss58_addresses: Optional[str] = None,
|
225
254
|
):
|
226
255
|
"""Retrieves the current balance of the specified wallet"""
|
227
|
-
if
|
256
|
+
if ss58_addresses:
|
257
|
+
coldkeys = ss58_addresses
|
258
|
+
wallet_names = [f"Provided Address {i + 1}" for i in range(len(ss58_addresses))]
|
259
|
+
|
260
|
+
elif not all_balances:
|
228
261
|
if not wallet.coldkeypub_file.exists_on_device():
|
229
262
|
err_console.print("[bold red]No wallets found.[/bold red]")
|
230
263
|
return
|
231
264
|
|
232
265
|
with console.status("Retrieving balances", spinner="aesthetic") as status:
|
233
|
-
if
|
266
|
+
if ss58_addresses:
|
267
|
+
print_verbose(f"Fetching data for ss58 address: {ss58_addresses}", status)
|
268
|
+
elif all_balances:
|
234
269
|
print_verbose("Fetching data for all wallets", status)
|
235
270
|
coldkeys, wallet_names = _get_coldkey_ss58_addresses_for_path(wallet.path)
|
236
271
|
else:
|
@@ -688,9 +723,11 @@ async def overview(
|
|
688
723
|
de_registered_neurons.append(de_registered_neuron)
|
689
724
|
|
690
725
|
# Add this hotkey to the wallets dict
|
691
|
-
wallet_ =
|
692
|
-
|
693
|
-
|
726
|
+
wallet_ = WalletLike(
|
727
|
+
name=wallet.name,
|
728
|
+
hotkey_ss58=hotkey_addr,
|
729
|
+
hotkey_str=hotkey_addr[:5],
|
730
|
+
)
|
694
731
|
# Indicates a hotkey not on local machine but exists in stake_info obj on-chain
|
695
732
|
if hotkey_coldkey_to_hotkey_wallet.get(hotkey_addr) is None:
|
696
733
|
hotkey_coldkey_to_hotkey_wallet[hotkey_addr] = {}
|
@@ -753,8 +790,7 @@ async def overview(
|
|
753
790
|
if not hotwallet:
|
754
791
|
# Indicates a mismatch between what the chain says the coldkey
|
755
792
|
# is for this hotkey and the local wallet coldkey-hotkey pair
|
756
|
-
hotwallet =
|
757
|
-
hotwallet.hotkey_str = nn.hotkey[:7]
|
793
|
+
hotwallet = WalletLike(name=nn.coldkey[:7], hotkey_str=nn.hotkey[:7])
|
758
794
|
|
759
795
|
nn: NeuronInfoLite
|
760
796
|
uid = nn.uid
|
@@ -1093,7 +1129,7 @@ def _map_hotkey_to_neurons(
|
|
1093
1129
|
|
1094
1130
|
async def _fetch_neuron_for_netuid(
|
1095
1131
|
netuid: int, subtensor: SubtensorInterface
|
1096
|
-
) -> tuple[int,
|
1132
|
+
) -> tuple[int, Optional[str]]:
|
1097
1133
|
"""
|
1098
1134
|
Retrieves all neurons for a specified netuid
|
1099
1135
|
|
@@ -1103,18 +1139,13 @@ async def _fetch_neuron_for_netuid(
|
|
1103
1139
|
:return: the original netuid, and a mapping of the neurons to their NeuronInfoLite objects
|
1104
1140
|
"""
|
1105
1141
|
|
1106
|
-
async def neurons_lite_for_uid(uid: int) ->
|
1107
|
-
call_definition = TYPE_REGISTRY["runtime_api"]["NeuronInfoRuntimeApi"][
|
1108
|
-
"methods"
|
1109
|
-
]["get_neurons_lite"]
|
1110
|
-
data = await subtensor.encode_params(
|
1111
|
-
call_definition=call_definition, params=[uid]
|
1112
|
-
)
|
1142
|
+
async def neurons_lite_for_uid(uid: int) -> Optional[str]:
|
1113
1143
|
block_hash = subtensor.substrate.last_block_hash
|
1114
|
-
hex_bytes_result = await subtensor.
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1144
|
+
hex_bytes_result = await subtensor.query_runtime_api(
|
1145
|
+
runtime_api="NeuronInfoRuntimeApi",
|
1146
|
+
method="get_neurons_lite",
|
1147
|
+
params=[uid],
|
1148
|
+
block_hash=block_hash,
|
1118
1149
|
)
|
1119
1150
|
|
1120
1151
|
return hex_bytes_result
|
@@ -1125,7 +1156,7 @@ async def _fetch_neuron_for_netuid(
|
|
1125
1156
|
|
1126
1157
|
async def _fetch_all_neurons(
|
1127
1158
|
netuids: list[int], subtensor
|
1128
|
-
) -> list[tuple[int,
|
1159
|
+
) -> list[tuple[int, Optional[str]]]:
|
1129
1160
|
"""Retrieves all neurons for each of the specified netuids"""
|
1130
1161
|
return list(
|
1131
1162
|
await asyncio.gather(
|
@@ -1134,50 +1165,21 @@ async def _fetch_all_neurons(
|
|
1134
1165
|
)
|
1135
1166
|
|
1136
1167
|
|
1137
|
-
def _partial_decode(args):
|
1138
|
-
"""
|
1139
|
-
Helper function for passing to ProcessPoolExecutor that decodes scale bytes based on a set return type and
|
1140
|
-
rpc type registry, passing this back to the Executor with its specified netuid for easier mapping
|
1141
|
-
|
1142
|
-
:param args: (return type, scale bytes object, custom rpc type registry, netuid)
|
1143
|
-
|
1144
|
-
:return: (original netuid, decoded object)
|
1145
|
-
"""
|
1146
|
-
return_type, as_scale_bytes, custom_rpc_type_registry_, netuid_ = args
|
1147
|
-
decoded = decode_scale_bytes(return_type, as_scale_bytes, custom_rpc_type_registry_)
|
1148
|
-
if decoded.startswith("0x"):
|
1149
|
-
bytes_result = bytes.fromhex(decoded[2:])
|
1150
|
-
else:
|
1151
|
-
bytes_result = bytes.fromhex(decoded)
|
1152
|
-
|
1153
|
-
return netuid_, NeuronInfoLite.list_from_vec_u8(bytes_result)
|
1154
|
-
|
1155
|
-
|
1156
1168
|
def _process_neurons_for_netuids(
|
1157
|
-
netuids_with_all_neurons_hex_bytes: list[tuple[int,
|
1169
|
+
netuids_with_all_neurons_hex_bytes: list[tuple[int, Optional[str]]],
|
1158
1170
|
) -> list[tuple[int, list[NeuronInfoLite]]]:
|
1159
1171
|
"""
|
1160
|
-
|
1172
|
+
Decode a list of hex-bytes neurons with their respective netuid
|
1161
1173
|
|
1162
1174
|
:param netuids_with_all_neurons_hex_bytes: netuids with hex-bytes neurons
|
1163
1175
|
:return: netuids mapped to decoded neurons
|
1164
1176
|
"""
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
return_type = TYPE_REGISTRY["runtime_api"]["NeuronInfoRuntimeApi"]["methods"][
|
1173
|
-
"get_neurons_lite"
|
1174
|
-
]["type"]
|
1175
|
-
|
1176
|
-
preprocessed = [make_map(r) for r in netuids_with_all_neurons_hex_bytes]
|
1177
|
-
with ProcessPoolExecutor() as executor:
|
1178
|
-
results = list(executor.map(_partial_decode, preprocessed))
|
1179
|
-
|
1180
|
-
all_results = [(netuid, result) for netuid, result in results]
|
1177
|
+
all_results = [
|
1178
|
+
(netuid, NeuronInfoLite.list_from_vec_u8(bytes.fromhex(result[2:])))
|
1179
|
+
if result
|
1180
|
+
else (netuid, [])
|
1181
|
+
for netuid, result in netuids_with_all_neurons_hex_bytes
|
1182
|
+
]
|
1181
1183
|
return all_results
|
1182
1184
|
|
1183
1185
|
|
@@ -1247,11 +1249,17 @@ async def transfer(
|
|
1247
1249
|
subtensor: SubtensorInterface,
|
1248
1250
|
destination: str,
|
1249
1251
|
amount: float,
|
1252
|
+
transfer_all: bool,
|
1250
1253
|
prompt: bool,
|
1251
1254
|
):
|
1252
1255
|
"""Transfer token of amount to destination."""
|
1253
1256
|
await transfer_extrinsic(
|
1254
|
-
subtensor,
|
1257
|
+
subtensor,
|
1258
|
+
wallet,
|
1259
|
+
destination,
|
1260
|
+
Balance.from_tao(amount),
|
1261
|
+
transfer_all,
|
1262
|
+
prompt=prompt,
|
1255
1263
|
)
|
1256
1264
|
|
1257
1265
|
|
@@ -1405,13 +1413,14 @@ async def faucet(
|
|
1405
1413
|
output_in_place: bool,
|
1406
1414
|
log_verbose: bool,
|
1407
1415
|
max_successes: int = 3,
|
1416
|
+
prompt: bool = True,
|
1408
1417
|
):
|
1409
1418
|
# TODO: - work out prompts to be passed through the cli
|
1410
1419
|
success = await run_faucet_extrinsic(
|
1411
1420
|
subtensor,
|
1412
1421
|
wallet,
|
1413
1422
|
tpb=threads_per_block,
|
1414
|
-
prompt=
|
1423
|
+
prompt=prompt,
|
1415
1424
|
update_interval=update_interval,
|
1416
1425
|
num_processes=processes,
|
1417
1426
|
cuda=use_cuda,
|
@@ -1610,6 +1619,7 @@ async def set_id(
|
|
1610
1619
|
try:
|
1611
1620
|
wallet.unlock_coldkey()
|
1612
1621
|
except KeyFileError:
|
1622
|
+
err_console.print("Error decrypting coldkey (possibly incorrect password)")
|
1613
1623
|
return False
|
1614
1624
|
|
1615
1625
|
with console.status(
|