Base CLI entry point for contract upgrading

pull/1040/head
Kieran Prasch 2019-03-25 19:36:18 -07:00
parent 322137675a
commit 3538f2403d
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
1 changed files with 39 additions and 20 deletions

View File

@ -34,6 +34,7 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT
@click.argument('action') @click.argument('action')
@click.option('--force', is_flag=True) @click.option('--force', is_flag=True)
@click.option('--poa', help="Inject POA middleware", is_flag=True) @click.option('--poa', help="Inject POA middleware", is_flag=True)
@click.option('--upgrade', help="Upgrade an already deployed contract", is_flag=True)
@click.option('--no-compile', help="Disables solidity contract compilation", is_flag=True) @click.option('--no-compile', help="Disables solidity contract compilation", is_flag=True)
@click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING) @click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING)
@click.option('--config-root', help="Custom configuration directory", type=click.Path()) @click.option('--config-root', help="Custom configuration directory", type=click.Path())
@ -49,6 +50,7 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT
def deploy(click_config, def deploy(click_config,
action, action,
poa, poa,
upgrade,
provider_uri, provider_uri,
deployer_address, deployer_address,
contract_name, contract_name,
@ -88,8 +90,40 @@ def deploy(click_config,
click.confirm("Deployer Address is {} - Continue?".format(deployer_address), abort=True) click.confirm("Deployer Address is {} - Continue?".format(deployer_address), abort=True)
deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address) deployer = Deployer(blockchain=blockchain, deployer_address=deployer_address)
#
# Upgrade
#
if upgrade:
if not contract_name:
raise click.BadArgumentUsage(message="--contract-name is required when using --upgrade")
existing_secret = click.prompt('Enter existing contract upgrade secret', hide_input=True, confirmation_prompt=True)
new_secret = click.prompt('Enter new contract upgrade secret', hide_input=True, confirmation_prompt=True)
deployer.upgrade_contract(contract_name=contract_name, existing_secret=existing_secret, new_plaintext_secret=new_secret)
return
#
# Deploy Single Contract
#
if contract_name:
try:
deployer_func = deployer.deployers[contract_name]
except KeyError:
message = "No such contract {}. Available contracts are {}".format(contract_name, deployer.deployers.keys())
click.secho(message, fg='red', bold=True)
raise click.Abort()
else:
_txs, _agent = deployer_func()
return
# The Big Three # The Big Three
if action == "contracts": if action == "contracts":
secrets = click_config.collect_deployment_secrets() secrets = click_config.collect_deployment_secrets()
# Track tx hashes, and new agents # Track tx hashes, and new agents
@ -100,37 +134,22 @@ def deploy(click_config,
deployer.blockchain.interface.registry._destroy() deployer.blockchain.interface.registry._destroy()
try: try:
txhashes, agents = deployer.deploy_network_contracts(miner_secret=bytes(secrets.miner_secret, encoding='utf-8'), txhashes, deployers = deployer.deploy_network_contracts(miner_secret=secrets.miner_secret,
policy_secret=bytes(secrets.policy_secret, encoding='utf-8'), policy_secret=secrets.policy_secret,
adjudicator_secret=bytes(secrets.mining_adjudicator_secret, encoding='utf-8')) adjudicator_secret=secrets.mining_adjudicator_secret,
user_escrow_proxy_secret=secrets.escrow_proxy_secret)
except BlockchainInterface.InterfaceError: except BlockchainInterface.InterfaceError:
raise # TODO: Handle registry management here (contract may already exist) raise # TODO: Handle registry management here (contract may already exist)
else: else:
__deployment_transactions.update(txhashes) __deployment_transactions.update(txhashes)
# User Escrow Proxy
deployer.deploy_escrow_proxy(secret=bytes(secrets.escrow_proxy_secret, encoding='utf-8'))
click.secho("Deployed!", fg='green', bold=True) click.secho("Deployed!", fg='green', bold=True)
#
# Deploy Single Contract
#
if contract_name:
try:
deployer_func = deployer.deployers[contract_name]
except KeyError:
message = "No such contract {}. Available contracts are {}".format(contract_name, deployer.deployers.keys())
click.secho(message, fg='red', bold=True)
raise click.Abort()
else:
_txs, _agent = deployer_func()
registry_outfile = deployer.blockchain.interface.registry.filepath registry_outfile = deployer.blockchain.interface.registry.filepath
click.secho('\nDeployment Transaction Hashes for {}'.format(registry_outfile), bold=True, fg='blue') click.secho('\nDeployment Transaction Hashes for {}'.format(registry_outfile), bold=True, fg='blue')
for contract_name, transactions in __deployment_transactions.items(): for contract_name, transactions in __deployment_transactions.items():
heading = '\n{} ({})'.format(contract_name, agents[contract_name].contract_address) heading = '\n{} ({})'.format(contract_name, deployers[contract_name].contract_address)
click.secho(heading, bold=True) click.secho(heading, bold=True)
click.echo('*'*(42+3+len(contract_name))) click.echo('*'*(42+3+len(contract_name)))