def load_transactions(self): self.tx_transactions = {} for tx_hash, raw in self.transactions.items(): tx = Transaction(raw) self.tx_transactions[tx_hash] = tx if not self.txi.get(tx_hash) and not self.txo.get(tx_hash) and \ (tx_hash not in self.pruned_txo.values()): log.info("removing unreferenced tx: %s", tx_hash) self.tx_transactions.pop(tx_hash) self.transactions.pop(tx_hash) # add to claimtrie transactions if its a claimtrie transaction tx.deserialize() for n, txout in enumerate(tx.outputs()): if txout[0] & (TYPE_CLAIM | TYPE_UPDATE | TYPE_SUPPORT): key = tx_hash + ':' + str(n) self.claimtrie_transactions[key] = txout[0]
def tx_response(self, response): params, result = self.parse_response(response) if not params: return tx_hash, tx_height = params assert tx_hash == hash_encode(Hash(result.decode('hex'))) tx = Transaction(result) try: tx.deserialize() except Exception: log.info("cannot deserialize transaction, skipping: %s", tx_hash) return self.wallet.receive_tx_callback(tx_hash, tx, tx_height) self.requested_tx.remove((tx_hash, tx_height)) log.info("received tx %s height: %d bytes: %d", tx_hash, tx_height, len(tx.raw)) # callbacks self.network.trigger_callback('new_transaction', tx) if not self.requested_tx: self.network.trigger_callback('updated')
def on_qr(self, data): from uwallet.bitcoin import base_decode, is_address data = data.strip() if is_address(data): self.set_URI(data) return if data.startswith('bitcoin:'): self.set_URI(data) return # try to decode transaction from uwallet.transaction import Transaction try: text = base_decode(data, None, base=43).encode('hex') tx = Transaction(text) tx.deserialize() except: tx = None if tx: self.tx_dialog(tx) return # show error self.show_error("Unable to decode QR data")