Skip to content

Commit

Permalink
trezor: handle when psbt has both types of UTXOs
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Jun 6, 2020
1 parent 2f40d0f commit 4ba72f3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hwilib/devices/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 4ba72f3

Please sign in to comment.