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
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
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)
def __init__(self, dialog, callback): """ :type dialog: QDialog :type callback: func """ QGridLayout.__init__(self) self.setSpacing(8) self.setColumnStretch(3, 1) self.callback = callback self.dialog = dialog if isinstance(self.dialog.parent().wallet.keystore, TrezorKeyStore): self.dialog.show_message( 'Trezor does not support QRC20 Token for now') self.dialog.reject() return self.addresses = self.dialog.parent( ).wallet.get_addresses_sort_by_balance() addr_type, __ = b58_address_to_hash160(self.addresses[0]) if not addr_type == ADDRTYPE_P2PKH: self.dialog.show_message('only P2PKH address supports QRC20 Token') self.dialog.reject() return address_lb = QLabel(_("Contract Address:")) self.contract_addr_e = ButtonsLineEdit() self.addWidget(address_lb, 1, 0) self.addWidget(self.contract_addr_e, 1, 1, 1, -1) address_lb = QLabel(_("My Address:")) self.address_combo = QComboBox() self.address_combo.setMinimumWidth(300) self.address_combo.addItems(self.addresses) self.addWidget(address_lb, 2, 0) self.addWidget(self.address_combo, 2, 1, 1, -1) self.cancel_btn = CancelButton(dialog) self.save_btn = QPushButton(_('Save')) self.save_btn.setDefault(True) self.save_btn.clicked.connect(self.save_input) buttons = Buttons(*[self.cancel_btn, self.save_btn]) buttons.addStretch() self.addLayout(buttons, 3, 2, 2, -1)
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)
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