mirror of https://github.com/nucypher/nucypher.git
deprecate nucypher accounts
parent
367c4e6c63
commit
58d279448c
|
@ -228,120 +228,6 @@ def status(config):
|
|||
node.timestamp), fg=color_index[node_type])
|
||||
|
||||
|
||||
@nucypher_cli.command()
|
||||
@click.option('--dev', '-d', help="Enable development mode", is_flag=True)
|
||||
@click.option('--provider-uri', help="Blockchain provider's URI", type=click.STRING)
|
||||
@click.option('--federated-only', help="Connect only to federated nodes", is_flag=True, default=True)
|
||||
@click.option('--checksum-address', help="The account to lock/unlock instead of the default", type=CHECKSUM_ADDRESS)
|
||||
@click.argument('action', default='list', required=False)
|
||||
@uses_config
|
||||
def accounts(config,
|
||||
action,
|
||||
dev,
|
||||
provider_uri,
|
||||
federated_only,
|
||||
checksum_address):
|
||||
"""Manage local and hosted node accounts"""
|
||||
|
||||
#
|
||||
# Initialize
|
||||
#
|
||||
ursula_config = get_ursula_configuration(dev_mode=dev,
|
||||
federated_only=federated_only,
|
||||
checksum_address=checksum_address,
|
||||
provider_uri=provider_uri)
|
||||
|
||||
if not ursula_config.federated_only:
|
||||
connect_to_blockchain(config)
|
||||
connect_to_contracts(config)
|
||||
|
||||
if not checksum_address:
|
||||
checksum_address = ursula_config.blockchain.interface.w3.eth.coinbase
|
||||
click.echo("WARNING: No checksum address specified - Using the node's default account.")
|
||||
|
||||
def __collect_transfer_details(denomination: str):
|
||||
destination = click.prompt("Enter destination checksum_address")
|
||||
if not is_checksum_address(destination):
|
||||
click.secho("{} is not a valid checksum checksum_address".format(destination), fg='red', bold=True)
|
||||
raise click.Abort()
|
||||
amount = click.prompt("Enter amount of {} to transfer".format(denomination), type=click.INT)
|
||||
return destination, amount
|
||||
|
||||
#
|
||||
# Action Switch
|
||||
#
|
||||
if action == 'new':
|
||||
new_address = create_account(config)
|
||||
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)):
|
||||
ursula_config.blockchain.interface.w3.eth.defaultAccount = new_address
|
||||
click.echo(
|
||||
"{} is now the node's default account.".format(ursula_config.blockchain.interface.w3.eth.defaultAccount))
|
||||
|
||||
if action == 'set-default':
|
||||
ursula_config.blockchain.interface.w3.eth.defaultAccount = checksum_address # TODO: is there a better way to do this?
|
||||
click.echo("{} is now the node's default account.".format(ursula_config.blockchain.interface.w3.eth.defaultAccount))
|
||||
|
||||
elif action == 'export':
|
||||
keyring = NucypherKeyring(account=checksum_address)
|
||||
click.confirm(
|
||||
"Export local private key for {} to node's keyring: {}?".format(checksum_address, ursula_config.provider_uri),
|
||||
abort=True)
|
||||
|
||||
password = click.prompt("Enter password to decrypt account",
|
||||
type=click.STRING,
|
||||
hide_input=True,
|
||||
confirmation_prompt=True)
|
||||
|
||||
keyring._export_wallet_to_node(blockchain=ursula_config.blockchain, password=password)
|
||||
|
||||
elif action == 'list':
|
||||
accounts = ursula_config.blockchain.interface.w3.eth.accounts
|
||||
if not accounts:
|
||||
click.echo('No account found.')
|
||||
raise click.Abort()
|
||||
|
||||
for index, checksum_address in enumerate(accounts):
|
||||
token_balance = ursula_config.token_agent.get_balance(address=checksum_address)
|
||||
eth_balance = ursula_config.blockchain.interface.w3.eth.getBalance(checksum_address)
|
||||
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 = row_template.format(index=index, address=checksum_address, tokens=token_balance, eth=eth_balance)
|
||||
click.secho(row, fg='blue')
|
||||
|
||||
elif action == 'balance':
|
||||
if not checksum_address:
|
||||
checksum_address = ursula_config.blockchain.interface.w3.eth.etherbase
|
||||
click.echo('No checksum_address supplied, Using the default {}'.format(checksum_address))
|
||||
token_balance = ursula_config.token_agent.get_balance(address=checksum_address)
|
||||
eth_balance = ursula_config.token_agent.blockchain.interface.w3.eth.getBalance(checksum_address)
|
||||
click.secho("Balance of {} | Tokens: {} | ETH: {}".format(checksum_address, token_balance, eth_balance),
|
||||
fg='blue')
|
||||
|
||||
elif action == "transfer-tokens":
|
||||
destination, amount = __collect_transfer_details(denomination='tokens')
|
||||
click.confirm("Are you sure you want to send {} tokens to {}?".format(amount, destination), abort=True)
|
||||
txhash = ursula_config.token_agent.transfer(amount=amount, target_address=destination, sender_address=checksum_address)
|
||||
ursula_config.blockchain.wait_for_receipt(txhash)
|
||||
click.echo("Sent {} tokens to {} | {}".format(amount, destination, txhash))
|
||||
|
||||
elif action == "transfer-eth":
|
||||
destination, amount = __collect_transfer_details(denomination='ETH')
|
||||
tx = {'to': destination, 'from': checksum_address, 'value': amount}
|
||||
click.confirm("Are you sure you want to send {} tokens to {}?".format(tx['value'], tx['to']), abort=True)
|
||||
txhash = ursula_config.blockchain.interface.w3.eth.sendTransaction(tx)
|
||||
ursula_config.blockchain.wait_for_receipt(txhash)
|
||||
click.echo("Sent {} ETH to {} | {}".format(amount, destination, str(txhash)))
|
||||
|
||||
else:
|
||||
raise click.BadArgumentUsage("No such argument {}".format(action))
|
||||
|
||||
|
||||
#
|
||||
# Ursula CLI
|
||||
#
|
||||
|
||||
@nucypher_cli.command()
|
||||
@click.argument('action')
|
||||
@click.option('--debug', '-D', help="Enable debugging mode", is_flag=True)
|
||||
|
|
|
@ -24,8 +24,6 @@ import maya
|
|||
from twisted.internet import reactor
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
|
||||
from nucypher.config.constants import SEEDNODES
|
||||
|
||||
|
||||
class UrsulaCommandProtocol(LineReceiver):
|
||||
|
||||
|
|
Loading…
Reference in New Issue