def send_transaction(to, value, password, token):
    """Sends transaction."""

    configuration = Configuration().load_configuration()
    api = get_api()

    try:
        if token is None:
            # send ETH transaction
            tx_hash, tx_cost_eth = api.send_transaction(
                configuration, password, to, value)
        else:
            # send erc20 transaction
            tx_hash, tx_cost_eth = api.send_transaction(
                configuration, password, to, value, token)

        click.echo('Hash of the transaction: %s' % str(tx_hash.hex()))
        click.echo('Transaction cost was: %sETH' % str(tx_cost_eth))

    except InsufficientFundsException:
        click.echo('Insufficient ETH funds! Check balance on your address.')
    except InsufficientERC20FundsException:
        click.echo(
            'Insufficient ERC20 token funds! Check balance on your address.')
    except InvalidAddress:
        click.echo('Invalid recipient(to) address!')
    except InvalidValueException:
        click.echo('Invalid value to send!')
    except InvalidPasswordException:
        click.echo('Incorrect password!')
    except InfuraErrorException:
        click.echo('Wallet is not connected to Ethereum network!')
    except ERC20NotExistsException:
        click.echo('This token is not added to the wallet!')
Esempio n. 2
0
def list_tokens():
    """List all added tokens."""
    configuration = Configuration().load_configuration()
    api = get_api()

    tokens = api.list_tokens(configuration)
    click.echo('ETH')
    for token in tokens:
        click.echo('%s' % token)
Esempio n. 3
0
def network():
    """Get connected network (Mainnet, Ropsten) defined in EIP155."""
    configuration = Configuration().load_configuration()
    api = get_api()
    chain_id = api.get_network(configuration)
    if chain_id == 1:
        click.echo('You are connected to the Mainnet network!')
    if chain_id == 3:
        click.echo('You are connected to the Ropsten network!')
Esempio n. 4
0
def get_wallet():
    """Get wallet account from encrypted keystore."""
    configuration = Configuration().load_configuration()
    api = get_api()

    address, pub_key = api.get_wallet(configuration)

    click.echo('Account address: %s' % str(address))
    click.echo('Account pub key: %s' % str(pub_key))
Esempio n. 5
0
def reveal_seed(password):
    """Reveals private key from encrypted keystore."""

    configuration = Configuration().load_configuration()
    api = get_api()

    try:
        wallet = api.get_private_key(configuration, password)
        click.echo('Account prv key: %s' % str(wallet.get_private_key().hex()))

    except InvalidPasswordException:
        click.echo('Incorrect password!')
Esempio n. 6
0
def reveal_seed():
    """Reveals private key from encrypted keystore."""
    password = getpass.getpass('Password from keystore: ')  # Prompt the user for a password of keystore file

    configuration = Configuration().load_configuration()
    api = get_api()

    try:
        wallet = api.get_private_key(configuration, password)
        click.echo('Account prv key: %s' % str(wallet.get_private_key().hex()))

    except InvalidPasswordException:
        click.echo('Incorrect password!')
Esempio n. 7
0
def get_wallet():
    """Get wallet account from encrypted keystore."""
    configuration = Configuration().load_configuration()
    api = get_api()

    try:
        address, pub_key = api.get_wallet(configuration)

        click.echo('Account address: %s' % str(address))
        click.echo('Account pub key: %s' % str(pub_key))

    except ValueError:
        click.echo('Incorrect password!')
Esempio n. 8
0
def add_token(contract, symbol):
    """Add new ERC20 contract."""
    configuration = Configuration().load_configuration()
    api = get_api()

    # fitcoin_address = '0x19896cB57Bc5B4cb92dbC7D389DBa6290AF505Ce'
    try:
        api.add_contract(configuration, symbol, contract)
        click.echo('New coin was added! %s %s' % (symbol, contract))
    except InvalidAddress:
        click.echo('Invalid address or wallet does not exist!')
    except InfuraErrorException:
        click.echo('Wallet is not connected to Ethereum network!')
Esempio n. 9
0
def new_wallet():
    """Creates new wallet and store encrypted keystore file."""
    password = getpass.getpass('Passphrase from keystore: ')  # Prompt the user for a password of keystore file

    configuration = Configuration().load_configuration()

    api = get_api()
    wallet = api.new_wallet(configuration, password)

    click.echo('Account address: %s' % str(wallet.get_address()))
    click.echo('Account pub key: %s' % str(wallet.get_public_key()))
    click.echo('Keystore path: %s' % configuration.keystore_location + configuration.keystore_filename)
    click.echo('Remember these words to restore eth-wallet: %s' % wallet.get_mnemonic())
Esempio n. 10
0
def add_token(contract, symbol):
    """Add new ERC20 contract."""
    configuration = Configuration().load_configuration()
    api = get_api()

    # TODO: test with bad contract and wallet address
    # fitcoin_address = '0x19896cB57Bc5B4cb92dbC7D389DBa6290AF505Ce'
    # binancecoin_address = '0x64BBF67A8251F7482330C33E65b08B835125e018'
    try:
        api.add_contract(configuration, symbol, contract)
        click.echo('New coin was added! %s %s' % (symbol, contract))
    except InvalidAddress:
        click.echo('Invalid address or wallet does not exist!')
    except InfuraErrorException:
        click.echo('Wallet is not connected to Ethereum network!')
Esempio n. 11
0
def get_balance(token):
    """Get address balance."""
    configuration = Configuration().load_configuration()
    api = get_api()
    try:
        if token is None:
            eth_balance, address = api.get_balance(configuration)
            click.echo('Balance on address %s is: %sETH' % (address, eth_balance))
        else:
            # TODO keyerror when token doesnt' exists
            token_balance, address = api.get_balance(configuration, token)
            click.echo('Balance on address %s is: %s%s' % (address, token_balance, token))
    except InvalidAddress:
        click.echo('Invalid address or wallet does not exist!')
    except InfuraErrorException:
        click.echo('Wallet is not connected to Ethereum network!')
Esempio n. 12
0
def send_transaction(to, value, token):
    """Sends transaction."""
    password = getpass.getpass(
        'Password from keystore: '
    )  # Prompt the user for a password of keystore file

    configuration = Configuration().load_configuration()
    api = get_api()

    # TODO: check if token symbol exists
    try:
        if token is None:
            # send ETH transaction
            tx_hash, tx_cost_eth = api.send_transaction(
                configuration, password, to, value)
        else:
            # send erc20 transaction
            tx_hash, tx_cost_eth = api.send_transaction(
                configuration, password, to, value, token)

        click.echo('Hash of the transaction: %s' % str(tx_hash.hex()))
        click.echo('Transaction cost was: %sETH' % str(tx_cost_eth))

    except InsufficientFundsException:
        click.echo('Insufficient ETH funds! Check balance on your address.')
    except InsufficientERC20FundsException:
        click.echo(
            'Insufficient ERC20 token funds! Check balance on your address.')
    except InvalidAddress:
        click.echo('Invalid recipient(to) address!')
    except InvalidValueException:
        click.echo('Invalid value to send!')
    except InvalidPasswordException:
        click.echo('Incorrect password!')
    except InfuraErrorException:
        click.echo('Wallet is not connected to Ethereum network!')