tSeparate out get_input_tx. - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit b752e91dae3a1ea4519e2299bd595cdf85d179aa DIR parent 9729f5b6d3ccc42ac02c04e3614cfb3bfd1ea42f HTML Author: Neil Booth <kyuupichan@gmail.com> Date: Sat, 23 Jan 2016 21:49:07 +0900 Separate out get_input_tx. Diffstat: M plugins/trezor/plugin.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) --- DIR diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py t@@ -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 t@@ -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