Skip to content

Commit 0e59530

Browse files
authored
Merge pull request #411 from opentensor/feat/thewhaleking/cleanup
General code cleanup
2 parents bb28ab4 + 17902e5 commit 0e59530

File tree

11 files changed

+38
-31
lines changed

11 files changed

+38
-31
lines changed

bittensor_cli/cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,8 @@ def stake_swap(
40674067
"""
40684068
self.verbosity_handler(quiet, verbose, json_output)
40694069
console.print(
4070-
"[dim]This command moves stake from one subnet to another subnet while keeping the same coldkey-hotkey pair.[/dim]"
4070+
"[dim]This command moves stake from one subnet to another subnet while keeping "
4071+
"the same coldkey-hotkey pair.[/dim]"
40714072
)
40724073

40734074
wallet = self.wallet_ask(
@@ -4222,7 +4223,8 @@ def stake_set_children(
42224223
proportions = list_prompt(
42234224
proportions,
42244225
float,
4225-
"Enter comma-separated proportions equal to the number of children (sum not exceeding a total of 1.0)",
4226+
"Enter comma-separated proportions equal to the number of children "
4227+
"(sum not exceeding a total of 1.0)",
42264228
)
42274229

42284230
if len(proportions) != len(children):
@@ -4340,7 +4342,8 @@ def stake_childkey_take(
43404342
None,
43414343
"--take",
43424344
"-t",
4343-
help="Use to set the take value for your child hotkey. When not used, the command will fetch the current take value.",
4345+
help="Use to set the take value for your child hotkey. When not used, the command will fetch the current "
4346+
"take value.",
43444347
prompt=False,
43454348
),
43464349
wait_for_inclusion: bool = Options.wait_for_inclusion,

bittensor_cli/src/bittensor/chain_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ def tao_to_alpha_with_slippage(
749749
self, tao: Balance
750750
) -> tuple[Balance, Balance, float]:
751751
"""
752-
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool state.
752+
Returns an estimate of how much Alpha would a staker receive if they stake their tao using the current pool
753+
state.
754+
753755
Args:
754756
tao: Amount of TAO to stake.
755757
Returns:
@@ -792,7 +794,9 @@ def alpha_to_tao_with_slippage(
792794
self, alpha: Balance
793795
) -> tuple[Balance, Balance, float]:
794796
"""
795-
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool state.
797+
Returns an estimate of how much TAO would a staker receive if they unstake their alpha using the current pool
798+
state.
799+
796800
Args:
797801
alpha: Amount of Alpha to stake.
798802
Returns:

bittensor_cli/src/bittensor/extrinsics/registration.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ async def get_neuron_for_pubkey_and_subnet():
524524
if prompt:
525525
if not Confirm.ask(
526526
f"Continue Registration?\n"
527-
f" hotkey [{COLOR_PALETTE['GENERAL']['HOTKEY']}]({wallet.hotkey_str})[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]:\t[{COLOR_PALETTE['GENERAL']['HOTKEY']}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
528-
f" coldkey [{COLOR_PALETTE['GENERAL']['COLDKEY']}]({wallet.name})[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]:\t[{COLOR_PALETTE['GENERAL']['COLDKEY']}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]\n"
529-
f" network:\t\t[{COLOR_PALETTE['GENERAL']['LINKS']}]{subtensor.network}[/{COLOR_PALETTE['GENERAL']['LINKS']}]\n"
527+
f" hotkey [{COLOR_PALETTE.G.HK}]({wallet.hotkey_str})[/{COLOR_PALETTE.G.HK}]:"
528+
f"\t[{COLOR_PALETTE.G.HK}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE.G.HK}]\n"
529+
f" coldkey [{COLOR_PALETTE.G.CK}]({wallet.name})[/{COLOR_PALETTE.G.CK}]:"
530+
f"\t[{COLOR_PALETTE.G.CK}]{wallet.coldkeypub.ss58_address}[/{COLOR_PALETTE.G.CK}]\n"
531+
f" network:\t\t[{COLOR_PALETTE.G.LINKS}]{subtensor.network}[/{COLOR_PALETTE.G.LINKS}]\n"
530532
):
531533
return False
532534

@@ -611,7 +613,6 @@ async def get_neuron_for_pubkey_and_subnet():
611613
if not wait_for_finalization and not wait_for_inclusion:
612614
success, err_msg = True, ""
613615
else:
614-
await response.process_events()
615616
success = await response.is_success
616617
if not success:
617618
success, err_msg = (
@@ -689,6 +690,7 @@ async def burned_register_extrinsic(
689690
`False` if the extrinsic fails to enter the block within the timeout.
690691
:param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning `True`,
691692
or returns `False` if the extrinsic fails to be finalized within the timeout.
693+
:param era: the period (in blocks) for which the transaction should remain valid.
692694
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
693695
694696
:return: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
@@ -735,10 +737,10 @@ async def burned_register_extrinsic(
735737
if not neuron.is_null:
736738
console.print(
737739
":white_heavy_check_mark: [dark_sea_green3]Already Registered[/dark_sea_green3]:\n"
738-
f"uid: [{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]{neuron.uid}[/{COLOR_PALETTE['GENERAL']['NETUID_EXTRA']}]\n"
739-
f"netuid: [{COLOR_PALETTE['GENERAL']['NETUID']}]{neuron.netuid}[/{COLOR_PALETTE['GENERAL']['NETUID']}]\n"
740-
f"hotkey: [{COLOR_PALETTE['GENERAL']['HOTKEY']}]{neuron.hotkey}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}]\n"
741-
f"coldkey: [{COLOR_PALETTE['GENERAL']['COLDKEY']}]{neuron.coldkey}[/{COLOR_PALETTE['GENERAL']['COLDKEY']}]"
740+
f"uid: [{COLOR_PALETTE.G.NETUID_EXTRA}]{neuron.uid}[/{COLOR_PALETTE.G.NETUID_EXTRA}]\n"
741+
f"netuid: [{COLOR_PALETTE.G.NETUID}]{neuron.netuid}[/{COLOR_PALETTE.G.NETUID}]\n"
742+
f"hotkey: [{COLOR_PALETTE.G.HK}]{neuron.hotkey}[/{COLOR_PALETTE.G.HK}]\n"
743+
f"coldkey: [{COLOR_PALETTE.G.CK}]{neuron.coldkey}[/{COLOR_PALETTE.G.CK}]"
742744
)
743745
return True
744746

@@ -781,7 +783,8 @@ async def burned_register_extrinsic(
781783

782784
console.print(
783785
"Balance:\n"
784-
f" [blue]{old_balance}[/blue] :arrow_right: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_balance}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]"
786+
f" [blue]{old_balance}[/blue] :arrow_right: "
787+
f"[{COLOR_PALETTE.S.STAKE_AMOUNT}]{new_balance}[/{COLOR_PALETTE.S.STAKE_AMOUNT}]"
785788
)
786789

787790
if len(netuids_for_hotkey) > 0:
@@ -914,7 +917,6 @@ async def run_faucet_extrinsic(
914917
)
915918

916919
# process if registration successful, try again if pow is still valid
917-
await response.process_events()
918920
if not await response.is_success:
919921
err_console.print(
920922
f":cross_mark: [red]Failed[/red]: "
@@ -1757,7 +1759,8 @@ async def swap_hotkey_extrinsic(
17571759
)
17581760
if not len(netuids_registered) > 0:
17591761
err_console.print(
1760-
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. Please register and try again"
1762+
f"Destination hotkey [dark_orange]{new_wallet.hotkey.ss58_address}[/dark_orange] is not registered. "
1763+
f"Please register and try again"
17611764
)
17621765
return False
17631766

@@ -1774,7 +1777,8 @@ async def swap_hotkey_extrinsic(
17741777
):
17751778
return False
17761779
print_verbose(
1777-
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with {new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
1780+
f"Swapping {wallet.name}'s hotkey ({wallet.hotkey.ss58_address}) with "
1781+
f"{new_wallet.name}s hotkey ({new_wallet.hotkey.ss58_address})"
17781782
)
17791783
with console.status(":satellite: Swapping hotkeys...", spinner="aesthetic"):
17801784
call = await subtensor.substrate.compose_call(

bittensor_cli/src/bittensor/extrinsics/root.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ async def _do_set_weights():
410410
if not wait_for_finalization and not wait_for_inclusion:
411411
return True, "Not waiting for finalization or inclusion."
412412

413-
await response.process_events()
414413
if await response.is_success:
415414
return True, "Successfully set weights."
416415
else:

bittensor_cli/src/bittensor/extrinsics/transfer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async def transfer_extrinsic(
3737
:param wallet: Bittensor wallet object to make transfer from.
3838
:param destination: Destination public key address (ss58_address or ed25519) of recipient.
3939
:param amount: Amount to stake as Bittensor balance.
40+
:param era: Length (in blocks) for which the transaction should be valid.
4041
:param transfer_all: Whether to transfer all funds from this wallet to the destination address.
4142
:param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`,
4243
or returns `False` if the extrinsic fails to enter the block within the timeout.
@@ -97,7 +98,6 @@ async def do_transfer() -> tuple[bool, str, str]:
9798
return True, "", ""
9899

99100
# Otherwise continue with finalization.
100-
await response.process_events()
101101
if await response.is_success:
102102
block_hash_ = response.block_hash
103103
return True, block_hash_, ""
@@ -156,7 +156,8 @@ async def do_transfer() -> tuple[bool, str, str]:
156156
if not Confirm.ask(
157157
"Do you want to transfer:[bold white]\n"
158158
f" amount: [bright_cyan]{amount}[/bright_cyan]\n"
159-
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : [bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
159+
f" from: [light_goldenrod2]{wallet.name}[/light_goldenrod2] : "
160+
f"[bright_magenta]{wallet.coldkey.ss58_address}\n[/bright_magenta]"
160161
f" to: [bright_magenta]{destination}[/bright_magenta]\n for fee: [bright_cyan]{fee}[/bright_cyan]"
161162
):
162163
return False

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ async def sign_and_send_extrinsic(
10571057
:param wallet: the wallet whose coldkey will be used to sign the extrinsic
10581058
:param wait_for_inclusion: whether to wait until the extrinsic call is included on the chain
10591059
:param wait_for_finalization: whether to wait until the extrinsic call is finalized on the chain
1060+
:param era: The length (in blocks) for which a transaction should be valid.
10601061
10611062
:return: (success, error message)
10621063
"""
@@ -1075,7 +1076,6 @@ async def sign_and_send_extrinsic(
10751076
# We only wait here if we expect finalization.
10761077
if not wait_for_finalization and not wait_for_inclusion:
10771078
return True, ""
1078-
await response.process_events()
10791079
if await response.is_success:
10801080
return True, ""
10811081
else:
@@ -1372,11 +1372,11 @@ async def get_stake_for_coldkeys(
13721372
This function is useful for analyzing the stake distribution and delegation patterns of multiple
13731373
accounts simultaneously, offering a broader perspective on network participation and investment strategies.
13741374
"""
1375-
BATCH_SIZE = 60
1375+
batch_size = 60
13761376

13771377
tasks = []
1378-
for i in range(0, len(coldkey_ss58_list), BATCH_SIZE):
1379-
ss58_chunk = coldkey_ss58_list[i : i + BATCH_SIZE]
1378+
for i in range(0, len(coldkey_ss58_list), batch_size):
1379+
ss58_chunk = coldkey_ss58_list[i : i + batch_size]
13801380
tasks.append(
13811381
self.query_runtime_api(
13821382
runtime_api="StakeInfoRuntimeApi",

bittensor_cli/src/bittensor/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ def get_effective_network(config, network: Optional[list[str]]) -> str:
10531053
the configuration, and the default.
10541054
"""
10551055
if network:
1056+
network_ = ""
10561057
for item in network:
10571058
if item.startswith("ws"):
10581059
network_ = item
@@ -1309,7 +1310,8 @@ def print_linux_dependency_message():
13091310
"\tAdd this into the file and save: [green]deb http://archive.ubuntu.com/ubuntu jammy main universe[/green]"
13101311
)
13111312
console.print(
1312-
"\tUpdate the repository and install the webkit dependency: [green]sudo apt update && sudo apt install libwebkit2gtk-4.0-dev[/green]"
1313+
"\tUpdate the repository and install the webkit dependency: [green]sudo apt update && sudo apt install "
1314+
"libwebkit2gtk-4.0-dev[/green]"
13131315
)
13141316
console.print("\nFedora / CentOS / AlmaLinux:")
13151317
console.print("[green]sudo dnf install gtk3-devel webkit2gtk3-devel[/green]\n\n")

bittensor_cli/src/commands/stake/remove.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,6 @@ async def _unstake_all_extrinsic(
798798
wait_for_inclusion=True,
799799
wait_for_finalization=False,
800800
)
801-
await response.process_events()
802801

803802
if not await response.is_success:
804803
err_out(

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ async def _find_event_attributes_in_extrinsic_receipt(
178178
if not wait_for_finalization and not wait_for_inclusion:
179179
return True
180180

181-
await response.process_events()
182181
if not await response.is_success:
183182
err_console.print(
184183
f":cross_mark: [red]Failed[/red]: {format_error_message(await response.error_message)}"

bittensor_cli/src/commands/weights.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ async def _do_set_weights():
260260
if not self.wait_for_finalization and not self.wait_for_inclusion:
261261
return True, "Not waiting for finalization or inclusion."
262262

263-
await response.process_events()
264263
if await response.is_success:
265264
return True, "Successfully set weights."
266265
else:
@@ -316,7 +315,6 @@ async def reveal_weights_extrinsic(
316315
success, error_message = True, ""
317316

318317
else:
319-
await response.process_events()
320318
if await response.is_success:
321319
success, error_message = True, ""
322320
else:
@@ -354,7 +352,6 @@ async def do_commit_weights(self, commit_hash):
354352
if not self.wait_for_finalization and not self.wait_for_inclusion:
355353
return True, None
356354

357-
await response.process_events()
358355
if await response.is_success:
359356
return True, None
360357
else:

0 commit comments

Comments
 (0)