@@ -110,20 +110,18 @@ func (u *Updater) addPartialSignature(inIndex int, sig []byte,
110110
111111 // Next, we perform a series of additional sanity checks.
112112 if pInput .NonWitnessUtxo != nil {
113- var numInputs int
114- if u .Upsbt .Version == 2 {
115- numInputs = len (u .Upsbt .Inputs )
116- } else {
113+ numInputs := len (u .Upsbt .Inputs )
114+ if u .Upsbt .Version < 2 {
117115 numInputs = len (u .Upsbt .UnsignedTx .TxIn )
118116 }
117+
119118 if numInputs < inIndex + 1 {
120119 return ErrInvalidPrevOutNonWitnessTransaction
121120 }
122121
123122 var prevHash chainhash.Hash
124- if u .Upsbt .Version == 2 {
125- copy (prevHash [:], pInput .PreviousTxid )
126- } else {
123+ copy (prevHash [:], pInput .PreviousTxid )
124+ if u .Upsbt .Version < 2 {
127125 prevHash = u .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Hash
128126 }
129127 if pInput .NonWitnessUtxo .TxHash () != prevHash {
@@ -135,10 +133,9 @@ func (u *Updater) addPartialSignature(inIndex int, sig []byte,
135133 // that with the P2SH scriptPubKey that is generated by
136134 // redeemScript.
137135 if pInput .RedeemScript != nil {
138- var outIndex uint32
139- if u .Upsbt .Version == 2 {
140- outIndex = pInput .OutputIndex
141- } else {
136+
137+ outIndex := pInput .OutputIndex
138+ if u .Upsbt .Version < 2 {
142139 outIndex = u .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Index
143140 }
144141 scriptPubKey := pInput .NonWitnessUtxo .TxOut [outIndex ].PkScript
0 commit comments