Beispiel #1
0
 def wallet_default(address):
     """ Set the default ADDRESS to operate """
     if address not in wallet:
         raise cli.BadParameter(red('Address not found'))
     try:
         wallet.default = address
     except ValueError as e:
         raise cli.BadParameter(red(e))
     print(white('{} has been marked as default.'.format(address)))
Beispiel #2
0
        def wallet_token_balance(address, token):
            """ Show the TOKEN balance off an ADDRESS """

            token = tokens(token)
            if token == None:
                raise cli.BadParameter(red("Token not found."))

            try:
                address = wallet.Address(address)
            except ValueError as e:
                raise cli.BadParameter(red(e))

            print(
                white('{} = {} {}').format(address, token.balance(address),
                                           token.symbol))
Beispiel #3
0
    def wallet_del(address):
        """ Delete ADDRESS from the Wallet """

        if address not in wallet:
            raise cli.BadParameter(red('Address not found'))

        del wallet[address]
Beispiel #4
0
    def network_default(network):
        """ Set the default NETWORK to operate """

        if network not in network_conf.network_profiles:
            raise BadParameter(red('Network not found'))

        network_conf.selected_profile = network

        print(white('{} has been marked as default.'.format(repr(network))))
Beispiel #5
0
    def wallet_balance(address):
        """ Show the balance off an ADDRESS """

        try:
            address = wallet.Address(address)
        except ValueError as e:
            raise cli.BadParameter(red(e))

        print(
            white('{} = {}').format(address,
                                    wei_to_str(network.balance(address))))
Beispiel #6
0
 def wallet_add(private_key, name=None, encrypt=True):
     """ Add an address to the Wallet with its PRIVATE_KEY """
     if name:
         name = ' '.join(list(name))
     else:
         name = None
     try:
         address = wallet.add_priv_key(private_key,
                                       encrypt=encrypt,
                                       name=name)
     except ValueError as e:
         raise cli.BadParameter(red(e))
     print(white('{} has been added.'.format(address)))
Beispiel #7
0
    def wallet_transfer(to_address, value, unit='wei'):
        """
        Transfers VALUE [UNIT] from the default account to TO_ADDRESS

        By default UNIT is wei
        """

        try:
            to_address = wallet.Address(to_address)
        except ValueError as e:
            raise cli.BadParameter(red(e))

        try:
            transaction = network.transfer(sign_callback=wallet.sign,
                                           from_address=wallet.default,
                                           to_address=to_address,
                                           value=value,
                                           unit=unit)
        except BadPassword:
            raise cli.ClickException(red('Bad private key password'))

        show_transaction(network, transaction)
Beispiel #8
0
        def wallet_token_transfer(token, to_address, value):
            """
            Transfers TOKEN VALUE from the default account to TO_ADDRESS
            """

            token = tokens(token)
            if token == None:
                raise cli.BadParameter(red("Token not found."))

            try:
                to_address = wallet.Address(to_address)
            except ValueError as e:
                raise cli.BadParameter(red(e))

            try:
                transaction = token.transfer(sign_callback=wallet.sign,
                                             from_address=wallet.default,
                                             to_address=to_address,
                                             value=value,
                                             gas_limit=70000)
            except BadPassword:
                raise cli.ClickException(red('Bad private key password'))

            show_transaction(network, transaction)