Exemplo n.º 1
0
 def get_inputs(self):
     try:
         gas_limit, gas_price, amount = self.parse_values()
     except (BaseException, ) as e:
         raise e
     if self.token.balance < amount:
         raise Exception(_('token not enough'))
     address_to = self.address_to_e.text().rstrip().lstrip()
     if is_b58_address(address_to):
         addr_type, hash160 = b58_address_to_hash160(address_to)
         if addr_type == constants.net.ADDRTYPE_P2PKH:
             hash160 = bh2u(hash160)
         else:
             raise Exception(_('invalid address to send to'))
     elif is_hash160(address_to):
         hash160 = address_to.lower()
     else:
         raise Exception(_('invalid address to send to'))
     return hash160, amount, gas_limit, gas_price
Exemplo n.º 2
0
    def do(self):
        try:
            staker = self.staker_e.text()
            if not is_hash160(staker):
                addr_type, staker = b58_address_to_hash160(staker)
                if addr_type != constants.net.ADDRTYPE_P2PKH:
                    raise Exception('wrong staker address')
                staker = bh2u(staker)

            fee = int(self.fee_e.text())
            if fee < 0 or fee > 100:
                raise Exception('fee should between 0 and 100')

            addr = self.addresses[self.address_combo.currentIndex()]
            if not addr:
                raise Exception('please select a address')

            gas_limit, gas_price = self.parse_values()
            if gas_limit < 2250000:
                raise Exception('a minimum of 2,250,000 gas_limit is required')

            dele_exist = self.dele and self.dele.staker and self.dele.fee

            if self.mode == 'add' and dele_exist:
                self.dialog.parent().set_delegation(self.dele)
            elif self.mode in ['edit', 'add']:
                if dele_exist and self.staker_e.text(
                ) == self.dele.staker and fee == self.dele.fee:
                    return
                self.dialog.parent().call_add_delegation(
                    addr, staker, fee, gas_limit, gas_price, self.dialog)
            elif self.mode == 'undelegate':
                self.dialog.parent().call_remove_delegation(
                    addr, gas_limit, gas_price, self.dialog)

            self.dialog.reject()

        except (BaseException, ) as e:
            traceback.print_exc(file=sys.stderr)
            self.dialog.show_message(str(e))