def parse_args(self):
     sender = None
     if len(self.senders) > 0:
         sender = self.senders[self.sender_combo.currentIndex()]
     if not sender:
         raise ParseArgsException('no sender selected')
     args = json.loads('[{}]'.format(self.args_e.text()))
     constructor = self.constructor
     inputs = constructor.get('inputs', [])
     if not len(args) == len(inputs):
         raise ParseArgsException('invalid input count,expect {} got {}'.format(len(inputs), len(args)))
     for index, _input in enumerate(inputs):
         _type = _input.get('type', '')
         if _type == 'address':
             addr = args[index]
             if is_address(addr):
                 __, hash160 = b58_address_to_hash160(addr)
                 addr = bh2u(hash160)
             if not is_hash160(addr):
                 raise ParseArgsException('invalid input:{}'.format(args[index]))
             args[index] = addr.lower()
         elif 'int' in _type:
             if not isinstance(args[index], int):
                 raise ParseArgsException('invalid input:{}'.format(args[index]))
         elif _type == 'bytes':
             args[index] = args[index].encode()
     return constructor, args, sender
 def parse_args(self):
     args = json.loads('[{}]'.format(self.args_e.text()))
     abi_index = self.abi_signatures[self.abi_combo.currentIndex()][0]
     if abi_index == -1:
         return None, []
     abi = self.contract['interface'][abi_index]
     inputs = abi.get('inputs', [])
     if not len(args) == len(inputs):
         raise ParseArgsException('invalid input count,expect {} got {}'.format(len(inputs), len(args)))
     for index, _input in enumerate(inputs):
         _type = _input.get('type', '')
         if _type == 'address':
             addr = args[index]
             if is_address(addr):
                 __, hash160 = b58_address_to_hash160(addr)
                 addr = bh2u(hash160)
             if not is_hash160(addr):
                 raise ParseArgsException('invalid input:{}'.format(args[index]))
             args[index] = addr.lower()
         elif 'int' in _type:
             if not isinstance(args[index], int):
                 raise ParseArgsException('inavlid input:{}'.format(args[index]))
     if len(self.senders) > 0:
         sender = self.senders[self.sender_combo.currentIndex()]
     else:
         sender = ''
     return abi, args, sender
 def save_input(self):
     try:
         contract_addr = self.contract_addr_e.text()
         bind_addr = self.addresses[self.address_combo.currentIndex()]
         if not is_hash160(contract_addr):
             raise Exception(
                 'invalid contrace address:{}'.format(contract_addr))
         self.callback(contract_addr, bind_addr)
         self.dialog.reject()
     except (BaseException, ) as e:
         import traceback, sys
         traceback.print_exc(file=sys.stderr)
         self.dialog.show_message(str(e))
 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
 def save_input(self):
     interface_text = self.interface_e.text()
     try:
         interface = json.loads(interface_text)
     except json.JSONDecodeError as e:
         self.dialog.show_message(_('invalid interface') + ' {}'.format(e))
         return
     address = self.address_e.text()
     address = address.rstrip().lstrip()
     if not is_hash160(address):
         self.dialog.show_message(_('invalid contract address'))
         return
     name = self.name_e.text()
     name = name.rstrip().lstrip()
     if len(name) > 32:
         self.dialog.show_message(_('name too long'))
         return
     if not name:
         self.dialog.show_message(_('empty name not allowed'))
         return
     self.contract['interface'] = interface
     self.contract['address'] = address
     self.contract['name'] = name
     self.callback(self.contract)