mirror of https://github.com/nucypher/nucypher.git
Add Ursula installation flag, add docs and colors to CLI.
parent
aca657919b
commit
97dc8628e4
39
cli/main.py
39
cli/main.py
|
@ -231,15 +231,16 @@ def cli(config,
|
||||||
config.poa = poa
|
config.poa = poa
|
||||||
|
|
||||||
if config.verbose:
|
if config.verbose:
|
||||||
click.echo("Running in verbose mode...")
|
click.secho("Running in verbose mode...", fg='blue')
|
||||||
|
|
||||||
if not config.dev:
|
if not config.dev:
|
||||||
click.echo("WARNING: Development mode is disabled")
|
click.secho("WARNING: Development mode is disabled", fg='yellow', bold=True)
|
||||||
else:
|
else:
|
||||||
click.echo("Running in development mode")
|
click.secho("Running in development mode", fg='blue')
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@click.option('--ursula', help="Configure ursula", is_flag=True, default=False)
|
||||||
@click.option('--filesystem', is_flag=True, default=False)
|
@click.option('--filesystem', is_flag=True, default=False)
|
||||||
@click.option('--no-registry', help="Skip importing the default contract registry", is_flag=True)
|
@click.option('--no-registry', help="Skip importing the default contract registry", is_flag=True)
|
||||||
@click.option('--force', help="Ask confirm once; Do not generate wallet or certificate", is_flag=True)
|
@click.option('--force', help="Ask confirm once; Do not generate wallet or certificate", is_flag=True)
|
||||||
|
@ -248,6 +249,7 @@ def cli(config,
|
||||||
@uses_config
|
@uses_config
|
||||||
def configure(config,
|
def configure(config,
|
||||||
action,
|
action,
|
||||||
|
ursula,
|
||||||
filesystem,
|
filesystem,
|
||||||
no_registry,
|
no_registry,
|
||||||
checksum_address, # TODO: Clean by address
|
checksum_address, # TODO: Clean by address
|
||||||
|
@ -375,7 +377,7 @@ def accounts(config,
|
||||||
def __collect_transfer_details(denomination: str):
|
def __collect_transfer_details(denomination: str):
|
||||||
destination = click.prompt("Enter destination checksum_address")
|
destination = click.prompt("Enter destination checksum_address")
|
||||||
if not is_checksum_address(destination):
|
if not is_checksum_address(destination):
|
||||||
click.echo("{} is not a valid checksum checksum_address".format(destination))
|
click.secho("{} is not a valid checksum checksum_address".format(destination), fg='red', bold=True)
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
amount = click.prompt("Enter amount of {} to transfer".format(denomination), type=click.INT)
|
amount = click.prompt("Enter amount of {} to transfer".format(denomination), type=click.INT)
|
||||||
return destination, amount
|
return destination, amount
|
||||||
|
@ -385,7 +387,7 @@ def accounts(config,
|
||||||
#
|
#
|
||||||
if action == 'new':
|
if action == 'new':
|
||||||
new_address = config.create_account()
|
new_address = config.create_account()
|
||||||
click.echo("Created new ETH address {}".format(new_address))
|
click.secho("Created new ETH address {}".format(new_address), fg='blue')
|
||||||
if click.confirm("Set new address as the node's keying default account?".format(new_address)):
|
if click.confirm("Set new address as the node's keying default account?".format(new_address)):
|
||||||
config.blockchain.interface.w3.eth.defaultAccount = new_address
|
config.blockchain.interface.w3.eth.defaultAccount = new_address
|
||||||
click.echo("{} is now the node's default account.".format(config.blockchain.interface.w3.eth.defaultAccount))
|
click.echo("{} is now the node's default account.".format(config.blockchain.interface.w3.eth.defaultAccount))
|
||||||
|
@ -407,7 +409,7 @@ def accounts(config,
|
||||||
base_row_template = ' {address}\n Tokens: {tokens}\n ETH: {eth}\n '
|
base_row_template = ' {address}\n Tokens: {tokens}\n ETH: {eth}\n '
|
||||||
row_template = ('\netherbase |'+base_row_template) if not index else '{index} ....... |'+base_row_template
|
row_template = ('\netherbase |'+base_row_template) if not index else '{index} ....... |'+base_row_template
|
||||||
row = row_template.format(index=index, address=checksum_address, tokens=token_balance, eth=eth_balance)
|
row = row_template.format(index=index, address=checksum_address, tokens=token_balance, eth=eth_balance)
|
||||||
click.echo(row)
|
click.secho(row, fg='blue')
|
||||||
|
|
||||||
elif action == 'balance':
|
elif action == 'balance':
|
||||||
if not checksum_address:
|
if not checksum_address:
|
||||||
|
@ -415,7 +417,7 @@ def accounts(config,
|
||||||
click.echo('No checksum_address supplied, Using the default {}'.format(checksum_address))
|
click.echo('No checksum_address supplied, Using the default {}'.format(checksum_address))
|
||||||
token_balance = config.token_agent.get_balance(address=checksum_address)
|
token_balance = config.token_agent.get_balance(address=checksum_address)
|
||||||
eth_balance = config.token_agent.blockchain.interface.w3.eth.getBalance(checksum_address)
|
eth_balance = config.token_agent.blockchain.interface.w3.eth.getBalance(checksum_address)
|
||||||
click.echo("Balance of {} | Tokens: {} | ETH: {}".format(checksum_address, token_balance, eth_balance))
|
click.secho("Balance of {} | Tokens: {} | ETH: {}".format(checksum_address, token_balance, eth_balance), fg='blue')
|
||||||
|
|
||||||
elif action == "transfer-tokens":
|
elif action == "transfer-tokens":
|
||||||
destination, amount = __collect_transfer_details(denomination='tokens')
|
destination, amount = __collect_transfer_details(denomination='tokens')
|
||||||
|
@ -831,7 +833,7 @@ def deploy(config,
|
||||||
"""Manage contract and registry deployment"""
|
"""Manage contract and registry deployment"""
|
||||||
|
|
||||||
if not config.deployer:
|
if not config.deployer:
|
||||||
click.echo("The --deployer flag must be used to issue the deploy command.")
|
click.secho("The --deployer flag must be used to issue the deploy command.", fg='red', bold=True)
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
|
|
||||||
def __get_deployers():
|
def __get_deployers():
|
||||||
|
@ -900,7 +902,7 @@ def deploy(config,
|
||||||
secret = click.prompt("Enter secret hash for {}".format(__contract_name), hide_input=True, confirmation_prompt=True)
|
secret = click.prompt("Enter secret hash for {}".format(__contract_name), hide_input=True, confirmation_prompt=True)
|
||||||
secret_hash = hashlib.sha256(secret)
|
secret_hash = hashlib.sha256(secret)
|
||||||
if len(secret_hash) != 32:
|
if len(secret_hash) != 32:
|
||||||
click.echo("Deployer secret must be 32 bytes.")
|
click.secho("Deployer secret must be 32 bytes.", fg='yellow')
|
||||||
if click.prompt("Try again?"):
|
if click.prompt("Try again?"):
|
||||||
return __collect_secret_hash()
|
return __collect_secret_hash()
|
||||||
else:
|
else:
|
||||||
|
@ -920,7 +922,8 @@ def deploy(config,
|
||||||
is_armed, disqualifications = __deployer.arm(abort=False)
|
is_armed, disqualifications = __deployer.arm(abort=False)
|
||||||
if not is_armed:
|
if not is_armed:
|
||||||
disqualifications = ', '.join(disqualifications)
|
disqualifications = ', '.join(disqualifications)
|
||||||
click.echo("Failed to arm {}. Disqualifications: {}".format(__contract_name, disqualifications))
|
click.secho("Failed to arm {}. Disqualifications: {}".format(__contract_name, disqualifications),
|
||||||
|
fg='red', bold=True)
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -934,6 +937,9 @@ def deploy(config,
|
||||||
__agent = __deployer.make_agent()
|
__agent = __deployer.make_agent()
|
||||||
__deployment_agents[agent_name] = __agent
|
__deployment_agents[agent_name] = __agent
|
||||||
|
|
||||||
|
click.secho("Deployed {} - Contract Address: {}".format(contract_name, __agent.contract_address),
|
||||||
|
fg='green', bold=True)
|
||||||
|
|
||||||
return __transactions, __agent
|
return __transactions, __agent
|
||||||
|
|
||||||
if contract_name:
|
if contract_name:
|
||||||
|
@ -944,6 +950,7 @@ def deploy(config,
|
||||||
deployer_info = deployers[contract_name]
|
deployer_info = deployers[contract_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
click.echo("No such contract {}. Available contracts are {}".format(contract_name, available_deployers))
|
click.echo("No such contract {}. Available contracts are {}".format(contract_name, available_deployers))
|
||||||
|
raise click.Abort()
|
||||||
else:
|
else:
|
||||||
_txs, _agent = __deploy_contract(deployer_info.deployer_class,
|
_txs, _agent = __deploy_contract(deployer_info.deployer_class,
|
||||||
upgradeable=deployer_info.upgradeable,
|
upgradeable=deployer_info.upgradeable,
|
||||||
|
@ -968,7 +975,7 @@ def deploy(config,
|
||||||
if not force and click.confirm("Save transaction hashes to JSON file?"):
|
if not force and click.confirm("Save transaction hashes to JSON file?"):
|
||||||
file = click.prompt("Enter output filepath", type=click.File(mode='w')) # TODO
|
file = click.prompt("Enter output filepath", type=click.File(mode='w')) # TODO
|
||||||
file.write(json.dumps(__deployment_transactions))
|
file.write(json.dumps(__deployment_transactions))
|
||||||
click.echo("Successfully wrote transaction hashes file to {}".format(file.path))
|
click.secho("Successfully wrote transaction hashes file to {}".format(file.path), fg='green')
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@ -1038,7 +1045,7 @@ def status(config,
|
||||||
@click.option('--rest-port', type=click.IntRange(min=49151, max=65535, clamp=False))
|
@click.option('--rest-port', type=click.IntRange(min=49151, max=65535, clamp=False))
|
||||||
@click.option('--db-name', type=click.STRING)
|
@click.option('--db-name', type=click.STRING)
|
||||||
@click.option('--checksum-address', type=CHECKSUM_ADDRESS)
|
@click.option('--checksum-address', type=CHECKSUM_ADDRESS)
|
||||||
@click.option('--stake-amount', type=click.IntRange(min=MIN_ALLOWED_LOCKED, max=MIN_ALLOWED_LOCKED, clamp=False))
|
@click.option('--stake-amount', type=click.IntRange(min=MIN_ALLOWED_LOCKED, max=MAX_ALLOWED_LOCKED, clamp=False))
|
||||||
@click.option('--stake-periods', type=click.IntRange(min=MIN_LOCKED_PERIODS, max=MAX_MINTING_PERIODS, clamp=False))
|
@click.option('--stake-periods', type=click.IntRange(min=MIN_LOCKED_PERIODS, max=MAX_MINTING_PERIODS, clamp=False))
|
||||||
@click.option('--resume', help="Resume an existing stake", is_flag=True)
|
@click.option('--resume', help="Resume an existing stake", is_flag=True)
|
||||||
@click.option('--no-reactor', help="Development feature", is_flag=True)
|
@click.option('--no-reactor', help="Development feature", is_flag=True)
|
||||||
|
@ -1072,8 +1079,8 @@ def ursula(config,
|
||||||
if action == 'run': # 0
|
if action == 'run': # 0
|
||||||
if not config.federated_only:
|
if not config.federated_only:
|
||||||
if not all((stake_amount, stake_periods)) and not resume:
|
if not all((stake_amount, stake_periods)) and not resume:
|
||||||
click.echo("Either --stake-amount and --stake-periods options "
|
click.secho("Either --stake-amount and --stake-periods options "
|
||||||
"or the --resume flag is required to run a non-federated Ursula")
|
"or the --resume flag is required to run a non-federated Ursula", bold=True)
|
||||||
raise click.Abort()
|
raise click.Abort()
|
||||||
|
|
||||||
if config.config_file: # 1
|
if config.config_file: # 1
|
||||||
|
@ -1097,7 +1104,9 @@ def ursula(config,
|
||||||
abort_on_learning_error=config.dev)
|
abort_on_learning_error=config.dev)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
URSULA = ursula_config.produce(passphrase=password) # 2
|
URSULA = ursula_config.produce(passphrase=password) # 2
|
||||||
|
|
||||||
if not config.federated_only:
|
if not config.federated_only:
|
||||||
URSULA.stake(amount=stake_amount, # 3
|
URSULA.stake(amount=stake_amount, # 3
|
||||||
lock_periods=stake_periods)
|
lock_periods=stake_periods)
|
||||||
|
@ -1105,6 +1114,8 @@ def ursula(config,
|
||||||
if not no_reactor:
|
if not no_reactor:
|
||||||
URSULA.get_deployer().run() # 4
|
URSULA.get_deployer().run() # 4
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
click.secho("{} {}".format(e.__class__.__name__, str(e)), fg='red')
|
||||||
finally:
|
finally:
|
||||||
click.echo("Cleaning up.")
|
click.echo("Cleaning up.")
|
||||||
ursula_config.cleanup()
|
ursula_config.cleanup()
|
||||||
|
|
Loading…
Reference in New Issue