Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move hotkeys flag #1071

Merged
merged 6 commits into from
Jan 26, 2023
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
2 changes: 1 addition & 1 deletion bittensor/_cli/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def check_config( config: 'bittensor.Config' ):
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.wallet.get('all_hotkeys') and not config.wallet.get('hotkeys'):
if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down
26 changes: 23 additions & 3 deletions bittensor/_cli/commands/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def run( cli ):

# We are printing for a select number of hotkeys from all_hotkeys.

if cli.config.wallet.get('hotkeys', []):
if cli.config.get('hotkeys', []):
if not cli.config.get('all_hotkeys', False):
# We are only showing hotkeys that are specified.
all_hotkeys = [hotkey for hotkey in all_hotkeys if hotkey.hotkey_str in cli.config.wallet.hotkeys]
all_hotkeys = [hotkey for hotkey in all_hotkeys if hotkey.hotkey_str in cli.config.hotkeys]
else:
# We are excluding the specified hotkeys from all_hotkeys.
all_hotkeys = [hotkey for hotkey in all_hotkeys if hotkey.hotkey_str not in cli.config.wallet.hotkeys]
all_hotkeys = [hotkey for hotkey in all_hotkeys if hotkey.hotkey_str not in cli.config.hotkeys]

# Check we have keys to display.
if len(all_hotkeys) == 0:
Expand Down Expand Up @@ -281,6 +281,26 @@ def add_args( parser: argparse.ArgumentParser ):
type=str,
help='''Sort the hotkeys in the specified ordering. (ascending/asc or descending/desc/reverse)'''
)
overview_parser.add_argument(
'--hotkeys',
'--exclude_hotkeys',
'--wallet.hotkeys',
'--wallet.exclude_hotkeys',
required=False,
action='store',
default=[],
type=str,
nargs='*',
help='''Specify the hotkeys by name or ss58 address. (e.g. hk1 hk2 hk3)'''
)
overview_parser.add_argument(
'--all_hotkeys',
'--wallet.all_hotkeys',
required=False,
action='store_true',
default=False,
help='''To specify all hotkeys. Specifying hotkeys will exclude them from this all.'''
)
overview_parser.add_argument( '--no_version_checking', action='store_true', help='''Set false to stop cli version checking''', default = False )
bittensor.wallet.add_args( overview_parser )
bittensor.subtensor.add_args( overview_parser )
Expand Down
33 changes: 28 additions & 5 deletions bittensor/_cli/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ def run( cli ):

# Get the hotkey_names (if any) and the hotkey_ss58s.
hotkeys_to_stake_to: List[Tuple[Optional[str], str]] = []
if config.wallet.get('all_hotkeys'):
if config.get('all_hotkeys'):
# Stake to all hotkeys.
all_hotkeys: List[bittensor.wallet] = get_hotkey_wallets_for_wallet( wallet = wallet )
# Get the hotkeys to exclude. (d)efault to no exclusions.
hotkeys_to_exclude: List[str] = cli.config.get('hotkeys', d=[])
# Exclude hotkeys that are specified.
hotkeys_to_stake_to = [
(wallet.hotkey_str, wallet.hotkey.ss58_address) for wallet in all_hotkeys if wallet.hotkey_str not in config.wallet.get('hotkeys', [])
(wallet.hotkey_str, wallet.hotkey.ss58_address) for wallet in all_hotkeys
if wallet.hotkey_str not in hotkeys_to_exclude
] # definitely wallets

elif config.wallet.get('hotkeys'):
elif config.get('hotkeys'):
# Stake to specific hotkeys.
for hotkey_ss58_or_hotkey_name in config.wallet.get('hotkeys'):
for hotkey_ss58_or_hotkey_name in config.get('hotkeys'):
if bittensor.utils.is_valid_ss58_address( hotkey_ss58_or_hotkey_name ):
# If the hotkey is a valid ss58 address, we add it to the list.
hotkeys_to_stake_to.append( (None, hotkey_ss58_or_hotkey_name ) )
Expand Down Expand Up @@ -141,7 +144,7 @@ def check_config( cls, config: 'bittensor.Config' ):
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.wallet.get('all_hotkeys') and not config.wallet.get('hotkeys'):
if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.get('all_hotkeys') and not config.get('hotkeys'):
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down Expand Up @@ -202,5 +205,25 @@ def add_args( cls, parser: argparse.ArgumentParser ):
help='''Set true to avoid prompting the user.''',
default=False,
)
stake_parser.add_argument(
'--hotkeys',
'--exclude_hotkeys',
'--wallet.hotkeys',
'--wallet.exclude_hotkeys',
required=False,
action='store',
default=[],
type=str,
nargs='*',
help='''Specify the hotkeys by name or ss58 address. (e.g. hk1 hk2 hk3)'''
)
stake_parser.add_argument(
'--all_hotkeys',
'--wallet.all_hotkeys',
required=False,
action='store_true',
default=False,
help='''To specify all hotkeys. Specifying hotkeys will exclude them from this all.'''
)
bittensor.wallet.add_args( stake_parser )
bittensor.subtensor.add_args( stake_parser )
39 changes: 31 additions & 8 deletions bittensor/_cli/commands/unstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def check_config( cls, config: 'bittensor.Config' ):
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.wallet.get('all_hotkeys') and not config.wallet.get('hotkeys'):
if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.get('all_hotkeys') and not config.get('hotkeys'):
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

# Get amount.
if not config.get('amount') and not config.get('unstake_all') and not config.get('max_stake'):
hotkeys: str = ''
if config.wallet.get('all_hotkeys'):
if config.get('all_hotkeys'):
hotkeys = "all hotkeys"
elif config.wallet.get('hotkeys'):
hotkeys = str(config.wallet.hotkeys).replace('[', '').replace(']', '')
elif config.get('hotkeys'):
hotkeys = str(config.hotkeys).replace('[', '').replace(']', '')
else:
hotkeys = str(config.wallet.hotkey)
if not Confirm.ask("Unstake all Tao from: [bold]'{}'[/bold]?".format(hotkeys)):
Expand Down Expand Up @@ -99,6 +99,26 @@ def add_args( command_parser ):
help='''Set true to avoid prompting the user.''',
default=False,
)
unstake_parser.add_argument(
'--hotkeys',
'--exclude_hotkeys',
'--wallet.hotkeys',
'--wallet.exclude_hotkeys',
required=False,
action='store',
default=[],
type=str,
nargs='*',
help='''Specify the hotkeys by name or ss58 address. (e.g. hk1 hk2 hk3)'''
)
unstake_parser.add_argument(
'--all_hotkeys',
'--wallet.all_hotkeys',
required=False,
action='store_true',
default=False,
help='''To specify all hotkeys. Specifying hotkeys will exclude them from this all.'''
)
bittensor.wallet.add_args( unstake_parser )
bittensor.subtensor.add_args( unstake_parser )

Expand All @@ -112,17 +132,20 @@ def run( cli ):

# Get the hotkey_names (if any) and the hotkey_ss58s.
hotkeys_to_unstake_from: List[Tuple[Optional[str], str]] = []
if cli.config.wallet.get('all_hotkeys'):
if cli.config.get('all_hotkeys'):
# Stake to all hotkeys.
all_hotkeys: List[bittensor.wallet] = get_hotkey_wallets_for_wallet( wallet = wallet )
# Get the hotkeys to exclude. (d)efault to no exclusions.
hotkeys_to_exclude: List[str] = cli.config.get('hotkeys', d=[])
# Exclude hotkeys that are specified.
hotkeys_to_unstake_from = [
(wallet.hotkey_str, wallet.hotkey.ss58_address) for wallet in all_hotkeys if wallet.hotkey_str not in cli.config.wallet.get('hotkeys', [])
(wallet.hotkey_str, wallet.hotkey.ss58_address) for wallet in all_hotkeys
if wallet.hotkey_str not in hotkeys_to_exclude
] # definitely wallets

elif cli.config.wallet.get('hotkeys'):
elif cli.config.get('hotkeys'):
# Stake to specific hotkeys.
for hotkey_ss58_or_hotkey_name in cli.config.wallet.get('hotkeys'):
for hotkey_ss58_or_hotkey_name in cli.config.get('hotkeys'):
if bittensor.utils.is_valid_ss58_address( hotkey_ss58_or_hotkey_name ):
# If the hotkey is a valid ss58 address, we add it to the list.
hotkeys_to_unstake_from.append( (None, hotkey_ss58_or_hotkey_name ) )
Expand Down
9 changes: 1 addition & 8 deletions bittensor/_wallet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None ):
parser.add_argument('--' + prefix_str + 'wallet.hotkey', required=False, default=bittensor.defaults.wallet.hotkey, help='''The name of wallet's hotkey.''')
parser.add_argument('--' + prefix_str + 'wallet.path', required=False, default=bittensor.defaults.wallet.path, help='''The path to your bittensor wallets''')
parser.add_argument('--' + prefix_str + 'wallet._mock', action='store_true', default=bittensor.defaults.wallet._mock, help='To turn on wallet mocking for testing purposes.')

parser.add_argument('--' + prefix_str + 'wallet.hotkeys', '--' + prefix_str + 'wallet.exclude_hotkeys', required=False, action='store', default=bittensor.defaults.wallet.hotkeys, type=str, nargs='*', help='''Specify the hotkeys by name. (e.g. hk1 hk2 hk3)''')
parser.add_argument('--' + prefix_str + 'wallet.all_hotkeys', required=False, action='store_true', default=bittensor.defaults.wallet.all_hotkeys, help='''To specify all hotkeys. Specifying hotkeys will exclude them from this all.''')

parser.add_argument('--' + prefix_str + 'wallet.reregister', required=False, action='store', default=bittensor.defaults.wallet.reregister, type=strtobool, help='''Whether to reregister the wallet if it is not already registered.''')

except argparse.ArgumentError as e:
Expand All @@ -130,9 +128,6 @@ def add_defaults(cls, defaults):
defaults.wallet.hotkey = os.getenv('BT_WALLET_HOTKEY') if os.getenv('BT_WALLET_HOTKEY') != None else 'default'
defaults.wallet.path = os.getenv('BT_WALLET_PATH') if os.getenv('BT_WALLET_PATH') != None else '~/.bittensor/wallets/'
defaults.wallet._mock = os.getenv('BT_WALLET_MOCK') if os.getenv('BT_WALLET_MOCK') != None else False
# CLI defaults for Overview
defaults.wallet.hotkeys = []
defaults.wallet.all_hotkeys = False
# Defaults for registration
defaults.wallet.reregister = True

Expand All @@ -144,6 +139,4 @@ def check_config(cls, config: 'bittensor.Config' ):
assert isinstance(config.wallet.get('name', bittensor.defaults.wallet.name), str)
assert isinstance(config.wallet.get('hotkey', bittensor.defaults.wallet.hotkey), str ) or config.wallet.get('hotkey', bittensor.defaults.wallet.hotkey) == None
assert isinstance(config.wallet.path, str)
assert isinstance(config.wallet.hotkeys, list)
assert isinstance(config.wallet.reregister, bool)
assert isinstance(config.wallet.all_hotkeys, bool)
Loading