Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class Options:
"--dashboard.path",
help="Path to save the dashboard HTML file. For example: `~/.bittensor/dashboard`.",
)
era: int = typer.Option(
3, help="Length (in blocks) for which the transaction should be valid."
)


def list_prompt(init_var: list, list_type: type, help_text: str) -> list:
Expand Down Expand Up @@ -1749,6 +1752,7 @@ def wallet_transfer(
transfer_all: bool = typer.Option(
False, "--all", prompt=False, help="Transfer all available balance."
),
era: int = Options.era,
wallet_name: str = Options.wallet_name,
wallet_path: str = Options.wallet_path,
wallet_hotkey: str = Options.wallet_hotkey,
Expand Down Expand Up @@ -1797,12 +1801,13 @@ def wallet_transfer(
amount = FloatPrompt.ask("Enter amount (in TAO) to transfer.")
return self._run_command(
wallets.transfer(
wallet,
subtensor,
destination_ss58_address,
amount,
transfer_all,
prompt,
wallet=wallet,
subtensor=subtensor,
destination=destination_ss58_address,
amount=amount,
transfer_all=transfer_all,
era=era,
prompt=prompt,
)
)

Expand Down Expand Up @@ -3112,6 +3117,7 @@ def stake_add(
rate_tolerance: Optional[float] = Options.rate_tolerance,
safe_staking: Optional[bool] = Options.safe_staking,
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
era: int = Options.era,
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -3305,6 +3311,7 @@ def stake_add(
safe_staking,
rate_tolerance,
allow_partial_stake,
era,
)
)

Expand Down Expand Up @@ -3356,6 +3363,7 @@ def stake_remove(
rate_tolerance: Optional[float] = Options.rate_tolerance,
safe_staking: Optional[bool] = Options.safe_staking,
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
era: int = Options.era,
prompt: bool = Options.prompt,
interactive: bool = typer.Option(
False,
Expand Down Expand Up @@ -3545,6 +3553,7 @@ def stake_remove(
include_hotkeys=include_hotkeys,
exclude_hotkeys=exclude_hotkeys,
prompt=prompt,
era=era,
)
)
elif (
Expand Down Expand Up @@ -3599,6 +3608,7 @@ def stake_remove(
safe_staking=safe_staking,
rate_tolerance=rate_tolerance,
allow_partial_stake=allow_partial_stake,
era=era,
)
)

Expand Down Expand Up @@ -3626,6 +3636,7 @@ def stake_move(
stake_all: bool = typer.Option(
False, "--stake-all", "--all", help="Stake all", prompt=False
),
era: int = Options.era,
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -3753,6 +3764,7 @@ def stake_move(
destination_hotkey=destination_hotkey,
amount=amount,
stake_all=stake_all,
era=era,
interactive_selection=interactive_selection,
prompt=prompt,
)
Expand Down Expand Up @@ -3790,6 +3802,7 @@ def stake_transfer(
stake_all: bool = typer.Option(
False, "--stake-all", "--all", help="Stake all", prompt=False
),
era: int = Options.era,
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -3910,6 +3923,7 @@ def stake_transfer(
dest_netuid=dest_netuid,
dest_coldkey_ss58=dest_ss58,
amount=amount,
era=era,
interactive_selection=interactive_selection,
stake_all=stake_all,
prompt=prompt,
Expand Down Expand Up @@ -3948,6 +3962,7 @@ def stake_swap(
"--all",
help="Swap all available stake",
),
era: int = Options.era,
prompt: bool = Options.prompt,
wait_for_inclusion: bool = Options.wait_for_inclusion,
wait_for_finalization: bool = Options.wait_for_finalization,
Expand Down Expand Up @@ -4010,6 +4025,7 @@ def stake_swap(
destination_netuid=dest_netuid,
amount=amount,
swap_all=swap_all,
era=era,
interactive_selection=interactive_selection,
prompt=prompt,
wait_for_inclusion=wait_for_inclusion,
Expand Down Expand Up @@ -5041,6 +5057,13 @@ def subnets_register(
wallet_hotkey: str = Options.wallet_hotkey,
network: Optional[list[str]] = Options.network,
netuid: int = Options.netuid,
era: Optional[
int
] = typer.Option( # Should not be Options.era bc this needs to be an Optional[int]
None,
help="Length (in blocks) for which the transaction should be valid. Note that it is possible that if you "
"use an era for this transaction that you may pay a different fee to register than the one stated.",
),
prompt: bool = Options.prompt,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -5069,6 +5092,7 @@ def subnets_register(
wallet,
self.initialize_chain(network),
netuid,
era,
prompt,
)
)
Expand Down
28 changes: 24 additions & 4 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ async def burned_register_extrinsic(
old_balance: Balance,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = True,
era: Optional[int] = None,
prompt: bool = False,
) -> bool:
"""Registers the wallet to chain by recycling TAO.
Expand Down Expand Up @@ -704,13 +705,32 @@ async def burned_register_extrinsic(
my_uid = await subtensor.query(
"SubtensorModule", "Uids", [netuid, wallet.hotkey.ss58_address]
)
block_hash = await subtensor.substrate.get_chain_head()

print_verbose("Checking if already registered", status)
neuron = await subtensor.neuron_for_uid(
uid=my_uid,
netuid=netuid,
block_hash=subtensor.substrate.last_block_hash,
uid=my_uid, netuid=netuid, block_hash=block_hash
)
if not era:
current_block, tempo, blocks_since_last_step = await asyncio.gather(
subtensor.substrate.get_block_number(block_hash=block_hash),
subtensor.get_hyperparameter(
"Tempo", netuid=netuid, block_hash=block_hash
),
subtensor.query(
"SubtensorModule",
"BlocksSinceLastStep",
[netuid],
block_hash=block_hash,
),
)
validity_period = tempo - blocks_since_last_step
era_ = {
"period": validity_period,
"current": current_block,
}
else:
era_ = {"period": era}

if not neuron.is_null:
console.print(
Expand All @@ -734,7 +754,7 @@ async def burned_register_extrinsic(
},
)
success, err_msg = await subtensor.sign_and_send_extrinsic(
call, wallet, wait_for_inclusion, wait_for_finalization
call, wallet, wait_for_inclusion, wait_for_finalization, era=era_
)

if not success:
Expand Down
3 changes: 2 additions & 1 deletion bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def transfer_extrinsic(
wallet: Wallet,
destination: str,
amount: Balance,
era: int = 3,
transfer_all: bool = False,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
Expand Down Expand Up @@ -84,7 +85,7 @@ async def do_transfer() -> tuple[bool, str, str]:
call_params={"dest": destination, "value": amount.rao},
)
extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
call=call, keypair=wallet.coldkey, era={"period": era}
)
response = await subtensor.substrate.submit_extrinsic(
extrinsic,
Expand Down
6 changes: 5 additions & 1 deletion bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ async def sign_and_send_extrinsic(
wallet: Wallet,
wait_for_inclusion: bool = True,
wait_for_finalization: bool = False,
era: Optional[dict[str, int]] = None,
) -> tuple[bool, str]:
"""
Helper method to sign and submit an extrinsic call to chain.
Expand All @@ -1059,8 +1060,11 @@ async def sign_and_send_extrinsic(

:return: (success, error message)
"""
call_args = {"call": call, "keypair": wallet.coldkey}
if era is not None:
call_args["era"] = era
extrinsic = await self.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
**call_args
) # sign with coldkey
try:
response = await self.substrate.submit_extrinsic(
Expand Down
10 changes: 7 additions & 3 deletions bittensor_cli/src/commands/stake/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def stake_add(
safe_staking: bool,
rate_tolerance: float,
allow_partial_stake: bool,
era: int,
):
"""
Args:
Expand All @@ -53,6 +54,7 @@ async def stake_add(
safe_staking: whether to use safe staking
rate_tolerance: rate tolerance percentage for stake operations
allow_partial_stake: whether to allow partial stake
era: Blocks for which the transaction should be valid.

Returns:
bool: True if stake operation is successful, False otherwise
Expand Down Expand Up @@ -86,7 +88,10 @@ async def safe_stake_extrinsic(
},
)
extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey, nonce=next_nonce
call=call,
keypair=wallet.coldkey,
nonce=next_nonce,
era={"period": era},
)
try:
response = await subtensor.substrate.submit_extrinsic(
Expand All @@ -105,7 +110,6 @@ async def safe_stake_extrinsic(
err_out(f"\n{failure_prelude} with error: {format_error_message(e)}")
return
else:
await response.process_events()
if not await response.is_success:
err_out(
f"\n{failure_prelude} with error: {format_error_message(await response.error_message)}"
Expand Down Expand Up @@ -166,7 +170,7 @@ async def stake_extrinsic(
},
)
extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey, nonce=next_nonce
call=call, keypair=wallet.coldkey, nonce=next_nonce, era={"period": era}
)
try:
response = await subtensor.substrate.submit_extrinsic(
Expand Down
9 changes: 6 additions & 3 deletions bittensor_cli/src/commands/stake/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ async def move_stake(
destination_hotkey: str,
amount: float,
stake_all: bool,
era: int,
interactive_selection: bool = False,
prompt: bool = True,
):
Expand Down Expand Up @@ -563,7 +564,7 @@ async def move_stake(
},
)
extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
call=call, keypair=wallet.coldkey, era={"period": era}
)
response = await subtensor.substrate.submit_extrinsic(
extrinsic, wait_for_inclusion=True, wait_for_finalization=False
Expand Down Expand Up @@ -622,6 +623,7 @@ async def transfer_stake(
origin_netuid: int,
dest_netuid: int,
dest_coldkey_ss58: str,
era: int,
interactive_selection: bool = False,
stake_all: bool = False,
prompt: bool = True,
Expand Down Expand Up @@ -747,7 +749,7 @@ async def transfer_stake(
)

extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
call=call, keypair=wallet.coldkey, era={"period": era}
)

response = await subtensor.substrate.submit_extrinsic(
Expand Down Expand Up @@ -798,6 +800,7 @@ async def swap_stake(
destination_netuid: int,
amount: float,
swap_all: bool = False,
era: int = 3,
interactive_selection: bool = False,
prompt: bool = True,
wait_for_inclusion: bool = True,
Expand Down Expand Up @@ -917,7 +920,7 @@ async def swap_stake(
)

extrinsic = await subtensor.substrate.create_signed_extrinsic(
call=call, keypair=wallet.coldkey
call=call, keypair=wallet.coldkey, era={"period": era}
)

response = await subtensor.substrate.submit_extrinsic(
Expand Down
Loading
Loading