Skip to content

Commit 52f0df5

Browse files
authored
Merge pull request #2146 from opentensor/feature/roman/migrate-delegate-info-to-onchain-indentities
`Migrate Delegate Info to onchain Indentities` implimentation.
2 parents 7d6bcad + 55a2a25 commit 52f0df5

File tree

12 files changed

+371
-97
lines changed

12 files changed

+371
-97
lines changed

bittensor/commands/delegates.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def _get_coldkey_wallets_for_path(path: str) -> List["bittensor.wallet"]:
4646

4747

4848
def show_delegates_lite(
49-
delegates_lite: List["bittensor.DelegateInfoLite"], width: Optional[int] = None
49+
subtensor: "bittensor.subtensor",
50+
delegates_lite: List["bittensor.DelegateInfoLite"],
51+
width: Optional[int] = None,
5052
):
5153
"""
5254
This method is a lite version of the :func:`show_delegates`. This method displays a formatted table of Bittensor network delegates with detailed statistics to the console.
@@ -57,6 +59,7 @@ def show_delegates_lite(
5759
This helper function is not intended to be used directly in user code unless specifically required.
5860
5961
Args:
62+
subtensor (bittensor.subtensor): The instance of the subtensor class.
6063
delegates_lite (List[bittensor.DelegateInfoLite]): A list of delegate information objects to be displayed.
6164
width (Optional[int]): The width of the console output table. Defaults to ``None``, which will make the table expand to the maximum width of the console.
6265
@@ -84,7 +87,7 @@ def show_delegates_lite(
8487
"""
8588

8689
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
87-
get_delegates_details(url=bittensor.__delegates_details_url__)
90+
get_delegates_details(subtensor=subtensor)
8891
)
8992
if registered_delegate_info is None:
9093
bittensor.__console__.print(
@@ -120,14 +123,17 @@ def show_delegates_lite(
120123
table.add_column("[overline white]Desc", style="rgb(50,163,219)")
121124

122125
for i, d in enumerate(delegates_lite):
126+
delegate_name = ""
127+
delegate_url = ""
128+
delegate_description = ""
123129
if d.delegate_ss58 in registered_delegate_info:
124-
delegate_name = registered_delegate_info[d.delegate_ss58].name
125-
delegate_url = registered_delegate_info[d.delegate_ss58].url
126-
delegate_description = registered_delegate_info[d.delegate_ss58].description
127-
else:
128-
delegate_name = ""
129-
delegate_url = ""
130-
delegate_description = ""
130+
delegate = registered_delegate_info[d.delegate_ss58]
131+
132+
delegate_name = delegate.display
133+
delegate_url = delegate.web
134+
135+
if len(delegate.additional) > 0 and len(delegate.additional[0]) == 2:
136+
delegate_description = delegate.additional[0][1]
131137

132138
table.add_row(
133139
# `INDEX` column
@@ -153,6 +159,7 @@ def show_delegates_lite(
153159

154160
# Uses rich console to pretty print a table of delegates.
155161
def show_delegates(
162+
subtensor: "bittensor.subtensor",
156163
delegates: List["bittensor.DelegateInfo"],
157164
prev_delegates: Optional[List["bittensor.DelegateInfo"]],
158165
width: Optional[int] = None,
@@ -167,6 +174,7 @@ def show_delegates(
167174
to be used directly in user code unless specifically required.
168175
169176
Args:
177+
subtensor (bittensor.subtensor): The instance of the subtensor class.
170178
delegates (List[bittensor.DelegateInfo]): A list of delegate information objects to be displayed.
171179
prev_delegates (Optional[List[bittensor.DelegateInfo]]): A list of delegate information objects from a previous state, used to calculate changes in stake. Defaults to ``None``.
172180
width (Optional[int]): The width of the console output table. Defaults to ``None``, which will make the table expand to the maximum width of the console.
@@ -207,7 +215,7 @@ def show_delegates(
207215
prev_delegates_dict[prev_delegate.hotkey_ss58] = prev_delegate
208216

209217
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
210-
get_delegates_details(url=bittensor.__delegates_details_url__)
218+
get_delegates_details(subtensor=subtensor)
211219
)
212220
if registered_delegate_info is None:
213221
bittensor.__console__.print(
@@ -265,16 +273,17 @@ def show_delegates(
265273
),
266274
bittensor.Balance.from_rao(0), # default to 0 if no owner stake.
267275
)
276+
277+
delegate_name = ""
278+
delegate_url = ""
279+
delegate_description = ""
280+
268281
if delegate.hotkey_ss58 in registered_delegate_info:
269-
delegate_name = registered_delegate_info[delegate.hotkey_ss58].name
270-
delegate_url = registered_delegate_info[delegate.hotkey_ss58].url
271-
delegate_description = registered_delegate_info[
272-
delegate.hotkey_ss58
273-
].description
274-
else:
275-
delegate_name = ""
276-
delegate_url = ""
277-
delegate_description = ""
282+
delegate_ = registered_delegate_info[delegate.hotkey_ss58]
283+
delegate_name = delegate_.display
284+
delegate_url = delegate_.web
285+
if len(delegate_.additional) > 0 and len(delegate_.additional[1]) == 2:
286+
delegate_description = delegate_.additional[0][1]
278287

279288
if delegate.hotkey_ss58 in prev_delegates_dict:
280289
prev_stake = prev_delegates_dict[delegate.hotkey_ss58].total_stake
@@ -431,7 +440,9 @@ def check_config(config: "bittensor.config"):
431440
sys.exit(1)
432441

433442
delegates.sort(key=lambda delegate: delegate.total_stake, reverse=True)
434-
show_delegates(delegates, prev_delegates=prev_delegates)
443+
show_delegates(
444+
subtensor=subtensor, delegates=delegates, prev_delegates=prev_delegates
445+
)
435446
delegate_index = Prompt.ask("Enter delegate index")
436447
config.delegate_ss58key = str(delegates[int(delegate_index)].hotkey_ss58)
437448
console.print(
@@ -576,7 +587,9 @@ def check_config(config: "bittensor.config"):
576587
sys.exit(1)
577588

578589
delegates.sort(key=lambda delegate: delegate.total_stake, reverse=True)
579-
show_delegates(delegates, prev_delegates=prev_delegates)
590+
show_delegates(
591+
subtensor=subtensor, delegates=delegates, prev_delegates=prev_delegates
592+
)
580593
delegate_index = Prompt.ask("Enter delegate index")
581594
config.delegate_ss58key = str(delegates[int(delegate_index)].hotkey_ss58)
582595
console.print(
@@ -682,7 +695,8 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
682695
)
683696

684697
show_delegates(
685-
delegates,
698+
subtensor=subtensor,
699+
delegates=delegates,
686700
prev_delegates=prev_delegates,
687701
width=cli.config.get("width", None),
688702
)
@@ -955,7 +969,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
955969
total_delegated += sum(my_delegates.values())
956970

957971
registered_delegate_info: Optional[DelegatesDetails] = (
958-
get_delegates_details(url=bittensor.__delegates_details_url__)
972+
get_delegates_details(subtensor=subtensor)
959973
)
960974
if registered_delegate_info is None:
961975
bittensor.__console__.print(

bittensor/commands/inspect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
139139
bittensor.logging.debug(f"Netuids to check: {netuids}")
140140

141141
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
142-
get_delegates_details(url=bittensor.__delegates_details_url__)
142+
get_delegates_details(subtensor=subtensor)
143143
)
144144
if registered_delegate_info is None:
145145
bittensor.__console__.print(
@@ -190,7 +190,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
190190
table.add_row(wallet.name, str(cold_balance), "", "", "", "", "", "", "")
191191
for dele, staked in delegates:
192192
if dele.hotkey_ss58 in registered_delegate_info:
193-
delegate_name = registered_delegate_info[dele.hotkey_ss58].name
193+
delegate_name = registered_delegate_info[dele.hotkey_ss58].display
194194
else:
195195
delegate_name = dele.hotkey_ss58
196196
table.add_row(
@@ -249,7 +249,7 @@ def check_config(config: "bittensor.config"):
249249
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
250250
config.wallet.name = str(wallet_name)
251251

252-
if config.netuids != [] and config.netuids != None:
252+
if config.netuids != [] and config.netuids is not None:
253253
if not isinstance(config.netuids, list):
254254
config.netuids = [int(config.netuids)]
255255
else:

bittensor/commands/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
248248
rows = []
249249
total_neurons = 0
250250
delegate_info: Optional[Dict[str, DelegatesDetails]] = get_delegates_details(
251-
url=bittensor.__delegates_details_url__
251+
subtensor=subtensor
252252
)
253253

254254
for subnet in subnets:
@@ -262,7 +262,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
262262
str(subnet.tempo),
263263
f"{subnet.burn!s:8.8}",
264264
str(bittensor.utils.formatting.millify(subnet.difficulty)),
265-
f"{delegate_info[subnet.owner_ss58].name if subnet.owner_ss58 in delegate_info else subnet.owner_ss58}",
265+
f"{delegate_info[subnet.owner_ss58].display if subnet.owner_ss58 in delegate_info else subnet.owner_ss58}",
266266
)
267267
)
268268
table = Table(

bittensor/commands/root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
149149
netuid=0
150150
)
151151
delegate_info: Optional[Dict[str, DelegatesDetails]] = get_delegates_details(
152-
url=bittensor.__delegates_details_url__
152+
subtensor=subtensor
153153
)
154154

155155
table = Table(show_footer=False)
@@ -191,7 +191,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
191191
table.add_row(
192192
str(neuron_data.uid),
193193
(
194-
delegate_info[neuron_data.hotkey].name
194+
delegate_info[neuron_data.hotkey].display
195195
if neuron_data.hotkey in delegate_info
196196
else ""
197197
),

bittensor/commands/senate.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
7171

7272
senate_members = subtensor.get_senate_members()
7373
delegate_info: Optional[Dict[str, DelegatesDetails]] = get_delegates_details(
74-
url=bittensor.__delegates_details_url__
74+
subtensor=subtensor
7575
)
7676

7777
table = Table(show_footer=False)
@@ -93,7 +93,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
9393
for ss58_address in senate_members:
9494
table.add_row(
9595
(
96-
delegate_info[ss58_address].name
96+
delegate_info[ss58_address].display
9797
if ss58_address in delegate_info
9898
else ""
9999
),
@@ -143,22 +143,23 @@ def format_call_data(call_data: "bittensor.ProposalCallData") -> str:
143143

144144

145145
def display_votes(
146-
vote_data: "bittensor.ProposalVoteData", delegate_info: "bittensor.DelegateInfo"
146+
vote_data: "bittensor.ProposalVoteData",
147+
delegate_info: "Dict[str, DelegatesDetails]",
147148
) -> str:
148149
vote_list = list()
149150

150151
for address in vote_data["ayes"]:
151152
vote_list.append(
152153
"{}: {}".format(
153-
delegate_info[address].name if address in delegate_info else address,
154+
delegate_info[address].display if address in delegate_info else address,
154155
"[bold green]Aye[/bold green]",
155156
)
156157
)
157158

158159
for address in vote_data["nays"]:
159160
vote_list.append(
160161
"{}: {}".format(
161-
delegate_info[address].name if address in delegate_info else address,
162+
delegate_info[address].display if address in delegate_info else address,
162163
"[bold red]Nay[/bold red]",
163164
)
164165
)
@@ -212,7 +213,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
212213
proposals = subtensor.get_proposals()
213214

214215
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
215-
get_delegates_details(url=bittensor.__delegates_details_url__)
216+
get_delegates_details(subtensor=subtensor)
216217
)
217218

218219
table = Table(show_footer=False)
@@ -338,12 +339,12 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
338339
return
339340

340341
proposal_vote_data = subtensor.get_vote_data(proposal_hash)
341-
if proposal_vote_data == None:
342+
if proposal_vote_data is None:
342343
console.print(":cross_mark: [red]Failed[/red]: Proposal not found.")
343344
return
344345

345346
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
346-
get_delegates_details(url=bittensor.__delegates_details_url__)
347+
get_delegates_details(subtensor=subtensor)
347348
)
348349

349350
table = Table(show_footer=False)

bittensor/commands/stake.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ def run(cli: "bittensor.cli"):
425425

426426
@staticmethod
427427
def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
428-
r"""Show all stake accounts."""
429-
if cli.config.get("all", d=False) == True:
428+
"""Show all stake accounts."""
429+
if cli.config.get("all", d=False) is True:
430430
wallets = _get_coldkey_wallets_for_path(cli.config.wallet.path)
431431
else:
432432
wallets = [bittensor.wallet(config=cli.config)]
433433
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
434-
get_delegates_details(url=bittensor.__delegates_details_url__)
434+
get_delegates_details(subtensor=subtensor)
435435
)
436436

437437
def get_stake_accounts(
@@ -515,7 +515,7 @@ def get_stakes_from_delegates(
515515
for nom in dele.nominators:
516516
if nom[0] == wallet.coldkeypub.ss58_address:
517517
delegate_name = (
518-
registered_delegate_info[dele.hotkey_ss58].name
518+
registered_delegate_info[dele.hotkey_ss58].display
519519
if dele.hotkey_ss58 in registered_delegate_info
520520
else dele.hotkey_ss58
521521
)

0 commit comments

Comments
 (0)