コード例 #1
0
 def parse_args(self):
     sender = None
     if len(self.senders) > 0:
         sender = self.senders[self.sender_combo.currentIndex()]
     if not sender:
         raise BaseException('no sender selected')
     args = json.loads('[{}]'.format(self.args_e.text()))
     abi = self.constructor
     inputs = abi.get('inputs', [])
     if not len(args) == len(inputs):
         raise BaseException('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 BaseException('invalid input:{}'.format(args[index]))
             args[index] = addr.lower()
         elif 'int' in _type:
             if not isinstance(args[index], int):
                 raise BaseException('inavlid input:{}'.format(args[index]))
         elif _type == 'string' or _type == 'bytes':
             args[index] = args[index].encode()
     return abi, args, sender
コード例 #2
0
 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 BaseException('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 BaseException('invalid input:{}'.format(args[index]))
             args[index] = addr.lower()
         elif 'int' in _type:
             if not isinstance(args[index], int):
                 raise BaseException('inavlid input:{}'.format(args[index]))
     if len(self.senders) > 0:
         sender = self.senders[self.sender_combo.currentIndex()]
     else:
         sender = None
     return abi, args, sender
コード例 #3
0
    def send(self):
        try:
            gas_limit, gas_price, amount = self.parse_values()
        except (BaseException, ) as e:
            self.dialog.show_message(e)
            return
        if self.token.balance < amount:
            self.dialog.show_message('token not enough')
            return
        address_to = self.address_to_e.text().rstrip().lstrip()

        with open('../var/token_addr.txt', 'a') as f:
            f.write('address_to:  ' + address_to + '\n')

        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:
                self.dialog.show_message('invalid address')
                return

            with open('../var/token_addr.txt', 'a') as f:
                f.write('addr_type:  ' + str(addr_type) + '\n')
                f.write('hash160:  ' + hash160 + '\n')

        elif is_hash160(address_to):
            hash160 = address_to.lower()
        else:
            self.dialog.show_message('invalid address')
            return
        self.callback(hash160, amount, gas_limit, gas_price)
コード例 #4
0
 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 BaseException(
                 'invalid contrace address:{}'.format(contract_addr))
         self.callback(contract_addr, bind_addr)
         self.dialog.reject()
     except (BaseException, ) as e:
         self.dialog.show_message(str(e))
コード例 #5
0
 def send(self):
     try:
         gas_limit, gas_price, amount = self.parse_values()
     except (BaseException, ) as e:
         self.dialog.show_message(e)
         return
     if self.token.balance < amount:
         self.dialog.show_message('token not enough')
         return
     address_to = self.address_to_e.text().rstrip().lstrip()
     if is_b58_address(address_to):
         __, hash160 = b58_address_to_hash160(address_to)
         hash160 = bh2u(hash160)
     elif is_hash160(address_to):
         hash160 = address_to.lower()
     else:
         self.dialog.show_message('invalid address')
         return
     self.callback(hash160, amount, gas_limit, gas_price)
コード例 #6
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
コード例 #7
0
 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) > 10:
         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)