From b752e91dae3a1ea4519e2299bd595cdf85d179aa Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 23 Jan 2016 21:49:07 +0900 Subject: [PATCH] Separate out get_input_tx. --- plugins/trezor/plugin.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index c1069d533..842e8150a 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -138,6 +138,17 @@ class TrezorCompatibleWallet(BIP44_Wallet): msg_sig = client.sign_message('Bitcoin', address_n, message) return msg_sig.signature + def get_input_tx(self, tx_hash): + # First look up an input transaction in the wallet where it + # will likely be. If co-signing a transaction it may not have + # all the input txs, in which case we ask the network. + tx = self.transactions.get(tx_hash) + if not tx: + request = ('blockchain.transaction.get', [tx_hash]) + # FIXME: what if offline? + tx = Transaction(self.network.synchronous_get(request)) + return tx + def sign_transaction(self, tx, password): if tx.is_complete(): return @@ -147,13 +158,7 @@ class TrezorCompatibleWallet(BIP44_Wallet): xpub_path = {} for txin in tx.inputs(): tx_hash = txin['prevout_hash'] - - ptx = self.transactions.get(tx_hash) - if ptx is None: - ptx = self.network.synchronous_get(('blockchain.transaction.get', [tx_hash])) - ptx = Transaction(ptx) - prev_tx[tx_hash] = ptx - + prev_tx[tx_hash] = self.get_input_tx(tx_hash) for x_pubkey in txin['x_pubkeys']: if not is_extended_pubkey(x_pubkey): continue