From 4ba72f36aae1a00d6619c68cf6ea24da88a41fa5 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 4 Jun 2020 16:02:21 -0400 Subject: [PATCH] trezor: handle when psbt has both types of UTXOs --- hwilib/devices/trezor.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hwilib/devices/trezor.py b/hwilib/devices/trezor.py index f728fd683..aaa27df95 100644 --- a/hwilib/devices/trezor.py +++ b/hwilib/devices/trezor.py @@ -164,12 +164,7 @@ def sign_tx(self, tx): # Detrermine spend type scriptcode = b'' - if psbt_in.non_witness_utxo: - utxo = psbt_in.non_witness_utxo.vout[txin.prevout.n] - txinputtype.script_type = proto.InputScriptType.SPENDADDRESS - scriptcode = utxo.scriptPubKey - txinputtype.amount = psbt_in.non_witness_utxo.vout[txin.prevout.n].nValue - elif psbt_in.witness_utxo: + if psbt_in.witness_utxo: utxo = psbt_in.witness_utxo # Check if the output is p2sh if psbt_in.witness_utxo.is_p2sh(): @@ -178,6 +173,11 @@ def sign_tx(self, tx): txinputtype.script_type = proto.InputScriptType.SPENDWITNESS scriptcode = psbt_in.witness_utxo.scriptPubKey txinputtype.amount = psbt_in.witness_utxo.nValue + elif psbt_in.non_witness_utxo: + utxo = psbt_in.non_witness_utxo.vout[txin.prevout.n] + txinputtype.script_type = proto.InputScriptType.SPENDADDRESS + scriptcode = utxo.scriptPubKey + txinputtype.amount = psbt_in.non_witness_utxo.vout[txin.prevout.n].nValue # Set the script if psbt_in.witness_script: @@ -197,7 +197,7 @@ def ignore_input(): if is_ms: # Add to txinputtype txinputtype.multisig = multisig - if psbt_in.non_witness_utxo: + if not psbt_in.witness_utxo: if utxo.is_p2sh: txinputtype.script_type = proto.InputScriptType.SPENDMULTISIG else: