Fail better in the CLI when using the ChecksumAddress type

Also, clarify that account selection prompt is based on index
pull/1655/head
David Núñez 2020-02-07 17:04:49 +01:00 committed by Kieran R. Prasch
parent 1a1d7f5289
commit 5c781f31a1
2 changed files with 6 additions and 3 deletions

View File

@ -449,7 +449,7 @@ def select_client_account(emitter,
emitter.echo(tabulate(rows, headers=headers, showindex='always'))
# Prompt the user for selection, and return
prompt = prompt or "Select Account"
prompt = prompt or "Select index of account"
account_range = click.IntRange(min=0, max=len(enumerated_accounts)-1)
choice = click.prompt(prompt, type=account_range, default=default)
chosen_account = enumerated_accounts[choice]
@ -485,7 +485,7 @@ def handle_client_account_for_staking(emitter,
if staking_address:
client_account = staking_address
else:
client_account = select_client_account(prompt="Select staking account",
client_account = select_client_account(prompt="Select index of staking account",
emitter=emitter,
registry=stakeholder.registry,
network=stakeholder.network,

View File

@ -27,7 +27,10 @@ class ChecksumAddress(click.ParamType):
name = 'checksum_address'
def convert(self, value, param, ctx):
return to_checksum_address(value=value) # TODO: More robust validation here?
try:
return to_checksum_address(value=value)
except ValueError as e:
self.fail(str(e))
class IPv4Address(click.ParamType):