@@ -14,9 +14,9 @@ import (
14
14
"bytes"
15
15
"crypto/sha256"
16
16
17
+ "github.com/btcsuite/btcd/btcutil"
17
18
"github.com/btcsuite/btcd/txscript"
18
19
"github.com/btcsuite/btcd/wire"
19
- "github.com/btcsuite/btcd/btcutil"
20
20
)
21
21
22
22
// Updater encapsulates the role 'Updater' as specified in BIP174; it accepts
@@ -40,14 +40,14 @@ func NewUpdater(p *Packet) (*Updater, error) {
40
40
// non-witness. This requires provision of a full transaction (which is the
41
41
// source of the corresponding prevOut), and the input index. If addition of
42
42
// this key-value pair to the Psbt fails, an error is returned.
43
- func (p * Updater ) AddInNonWitnessUtxo (tx * wire.MsgTx , inIndex int ) error {
44
- if inIndex > len (p .Upsbt .Inputs )- 1 {
43
+ func (u * Updater ) AddInNonWitnessUtxo (tx * wire.MsgTx , inIndex int ) error {
44
+ if inIndex > len (u .Upsbt .Inputs )- 1 {
45
45
return ErrInvalidPrevOutNonWitnessTransaction
46
46
}
47
47
48
- p .Upsbt .Inputs [inIndex ].NonWitnessUtxo = tx
48
+ u .Upsbt .Inputs [inIndex ].NonWitnessUtxo = tx
49
49
50
- if err := p .Upsbt .SanityCheck (); err != nil {
50
+ if err := u .Upsbt .SanityCheck (); err != nil {
51
51
return ErrInvalidPsbtFormat
52
52
}
53
53
@@ -59,14 +59,14 @@ func (p *Updater) AddInNonWitnessUtxo(tx *wire.MsgTx, inIndex int) error {
59
59
// of the corresponding prevOut); not the full transaction because BIP143 means
60
60
// the output information is sufficient, and the input index. If addition of
61
61
// this key-value pair to the Psbt fails, an error is returned.
62
- func (p * Updater ) AddInWitnessUtxo (txout * wire.TxOut , inIndex int ) error {
63
- if inIndex > len (p .Upsbt .Inputs )- 1 {
62
+ func (u * Updater ) AddInWitnessUtxo (txout * wire.TxOut , inIndex int ) error {
63
+ if inIndex > len (u .Upsbt .Inputs )- 1 {
64
64
return ErrInvalidPsbtFormat
65
65
}
66
66
67
- p .Upsbt .Inputs [inIndex ].WitnessUtxo = txout
67
+ u .Upsbt .Inputs [inIndex ].WitnessUtxo = txout
68
68
69
- if err := p .Upsbt .SanityCheck (); err != nil {
69
+ if err := u .Upsbt .SanityCheck (); err != nil {
70
70
return ErrInvalidPsbtFormat
71
71
}
72
72
@@ -81,7 +81,7 @@ func (p *Updater) AddInWitnessUtxo(txout *wire.TxOut, inIndex int) error {
81
81
// rules are not satisfied, an ErrInvalidSignatureForInput is returned.
82
82
//
83
83
// NOTE: This function does *not* validate the ECDSA signature itself.
84
- func (p * Updater ) addPartialSignature (inIndex int , sig []byte ,
84
+ func (u * Updater ) addPartialSignature (inIndex int , sig []byte ,
85
85
pubkey []byte ) error {
86
86
87
87
partialSig := PartialSig {
@@ -93,7 +93,7 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
93
93
return ErrInvalidPsbtFormat
94
94
}
95
95
96
- pInput := p .Upsbt .Inputs [inIndex ]
96
+ pInput := u .Upsbt .Inputs [inIndex ]
97
97
98
98
// First check; don't add duplicates.
99
99
for _ , x := range pInput .PartialSigs {
@@ -109,12 +109,12 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
109
109
110
110
// Next, we perform a series of additional sanity checks.
111
111
if pInput .NonWitnessUtxo != nil {
112
- if len (p .Upsbt .UnsignedTx .TxIn ) < inIndex + 1 {
112
+ if len (u .Upsbt .UnsignedTx .TxIn ) < inIndex + 1 {
113
113
return ErrInvalidPrevOutNonWitnessTransaction
114
114
}
115
115
116
116
if pInput .NonWitnessUtxo .TxHash () !=
117
- p .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Hash {
117
+ u .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Hash {
118
118
return ErrInvalidSignatureForInput
119
119
}
120
120
@@ -123,7 +123,7 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
123
123
// that with the P2SH scriptPubKey that is generated by
124
124
// redeemScript.
125
125
if pInput .RedeemScript != nil {
126
- outIndex := p .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Index
126
+ outIndex := u .Upsbt .UnsignedTx .TxIn [inIndex ].PreviousOutPoint .Index
127
127
scriptPubKey := pInput .NonWitnessUtxo .TxOut [outIndex ].PkScript
128
128
scriptHash := btcutil .Hash160 (pInput .RedeemScript )
129
129
@@ -212,11 +212,11 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
212
212
}
213
213
}
214
214
215
- p .Upsbt .Inputs [inIndex ].PartialSigs = append (
216
- p .Upsbt .Inputs [inIndex ].PartialSigs , & partialSig ,
215
+ u .Upsbt .Inputs [inIndex ].PartialSigs = append (
216
+ u .Upsbt .Inputs [inIndex ].PartialSigs , & partialSig ,
217
217
)
218
218
219
- if err := p .Upsbt .SanityCheck (); err != nil {
219
+ if err := u .Upsbt .SanityCheck (); err != nil {
220
220
return err
221
221
}
222
222
@@ -229,12 +229,12 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
229
229
// sighash type is passed as a 32 bit unsigned integer, along with the index
230
230
// for the input. An error is returned if addition of this key-value pair to
231
231
// the Psbt fails.
232
- func (p * Updater ) AddInSighashType (sighashType txscript.SigHashType ,
232
+ func (u * Updater ) AddInSighashType (sighashType txscript.SigHashType ,
233
233
inIndex int ) error {
234
234
235
- p .Upsbt .Inputs [inIndex ].SighashType = sighashType
235
+ u .Upsbt .Inputs [inIndex ].SighashType = sighashType
236
236
237
- if err := p .Upsbt .SanityCheck (); err != nil {
237
+ if err := u .Upsbt .SanityCheck (); err != nil {
238
238
return err
239
239
}
240
240
return nil
@@ -244,12 +244,12 @@ func (p *Updater) AddInSighashType(sighashType txscript.SigHashType,
244
244
// redeem script is passed serialized, as a byte slice, along with the index of
245
245
// the input. An error is returned if addition of this key-value pair to the
246
246
// Psbt fails.
247
- func (p * Updater ) AddInRedeemScript (redeemScript []byte ,
247
+ func (u * Updater ) AddInRedeemScript (redeemScript []byte ,
248
248
inIndex int ) error {
249
249
250
- p .Upsbt .Inputs [inIndex ].RedeemScript = redeemScript
250
+ u .Upsbt .Inputs [inIndex ].RedeemScript = redeemScript
251
251
252
- if err := p .Upsbt .SanityCheck (); err != nil {
252
+ if err := u .Upsbt .SanityCheck (); err != nil {
253
253
return ErrInvalidPsbtFormat
254
254
}
255
255
@@ -260,12 +260,12 @@ func (p *Updater) AddInRedeemScript(redeemScript []byte,
260
260
// witness script is passed serialized, as a byte slice, along with the index
261
261
// of the input. An error is returned if addition of this key-value pair to the
262
262
// Psbt fails.
263
- func (p * Updater ) AddInWitnessScript (witnessScript []byte ,
263
+ func (u * Updater ) AddInWitnessScript (witnessScript []byte ,
264
264
inIndex int ) error {
265
265
266
- p .Upsbt .Inputs [inIndex ].WitnessScript = witnessScript
266
+ u .Upsbt .Inputs [inIndex ].WitnessScript = witnessScript
267
267
268
- if err := p .Upsbt .SanityCheck (); err != nil {
268
+ if err := u .Upsbt .SanityCheck (); err != nil {
269
269
return err
270
270
}
271
271
@@ -279,7 +279,7 @@ func (p *Updater) AddInWitnessScript(witnessScript []byte,
279
279
//
280
280
// NOTE: This can be called multiple times for the same input. An error is
281
281
// returned if addition of this key-value pair to the Psbt fails.
282
- func (p * Updater ) AddInBip32Derivation (masterKeyFingerprint uint32 ,
282
+ func (u * Updater ) AddInBip32Derivation (masterKeyFingerprint uint32 ,
283
283
bip32Path []uint32 , pubKeyData []byte , inIndex int ) error {
284
284
285
285
bip32Derivation := Bip32Derivation {
@@ -293,17 +293,17 @@ func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
293
293
}
294
294
295
295
// Don't allow duplicate keys
296
- for _ , x := range p .Upsbt .Inputs [inIndex ].Bip32Derivation {
296
+ for _ , x := range u .Upsbt .Inputs [inIndex ].Bip32Derivation {
297
297
if bytes .Equal (x .PubKey , bip32Derivation .PubKey ) {
298
298
return ErrDuplicateKey
299
299
}
300
300
}
301
301
302
- p .Upsbt .Inputs [inIndex ].Bip32Derivation = append (
303
- p .Upsbt .Inputs [inIndex ].Bip32Derivation , & bip32Derivation ,
302
+ u .Upsbt .Inputs [inIndex ].Bip32Derivation = append (
303
+ u .Upsbt .Inputs [inIndex ].Bip32Derivation , & bip32Derivation ,
304
304
)
305
305
306
- if err := p .Upsbt .SanityCheck (); err != nil {
306
+ if err := u .Upsbt .SanityCheck (); err != nil {
307
307
return err
308
308
}
309
309
@@ -317,7 +317,7 @@ func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
317
317
//
318
318
// NOTE: That this can be called multiple times for the same output. An error
319
319
// is returned if addition of this key-value pair to the Psbt fails.
320
- func (p * Updater ) AddOutBip32Derivation (masterKeyFingerprint uint32 ,
320
+ func (u * Updater ) AddOutBip32Derivation (masterKeyFingerprint uint32 ,
321
321
bip32Path []uint32 , pubKeyData []byte , outIndex int ) error {
322
322
323
323
bip32Derivation := Bip32Derivation {
@@ -331,17 +331,17 @@ func (p *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
331
331
}
332
332
333
333
// Don't allow duplicate keys
334
- for _ , x := range p .Upsbt .Outputs [outIndex ].Bip32Derivation {
334
+ for _ , x := range u .Upsbt .Outputs [outIndex ].Bip32Derivation {
335
335
if bytes .Equal (x .PubKey , bip32Derivation .PubKey ) {
336
336
return ErrDuplicateKey
337
337
}
338
338
}
339
339
340
- p .Upsbt .Outputs [outIndex ].Bip32Derivation = append (
341
- p .Upsbt .Outputs [outIndex ].Bip32Derivation , & bip32Derivation ,
340
+ u .Upsbt .Outputs [outIndex ].Bip32Derivation = append (
341
+ u .Upsbt .Outputs [outIndex ].Bip32Derivation , & bip32Derivation ,
342
342
)
343
343
344
- if err := p .Upsbt .SanityCheck (); err != nil {
344
+ if err := u .Upsbt .SanityCheck (); err != nil {
345
345
return err
346
346
}
347
347
@@ -350,12 +350,12 @@ func (p *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
350
350
351
351
// AddOutRedeemScript takes a redeem script as a byte slice and appends it to
352
352
// the output at index outIndex.
353
- func (p * Updater ) AddOutRedeemScript (redeemScript []byte ,
353
+ func (u * Updater ) AddOutRedeemScript (redeemScript []byte ,
354
354
outIndex int ) error {
355
355
356
- p .Upsbt .Outputs [outIndex ].RedeemScript = redeemScript
356
+ u .Upsbt .Outputs [outIndex ].RedeemScript = redeemScript
357
357
358
- if err := p .Upsbt .SanityCheck (); err != nil {
358
+ if err := u .Upsbt .SanityCheck (); err != nil {
359
359
return ErrInvalidPsbtFormat
360
360
}
361
361
@@ -364,12 +364,12 @@ func (p *Updater) AddOutRedeemScript(redeemScript []byte,
364
364
365
365
// AddOutWitnessScript takes a witness script as a byte slice and appends it to
366
366
// the output at index outIndex.
367
- func (p * Updater ) AddOutWitnessScript (witnessScript []byte ,
367
+ func (u * Updater ) AddOutWitnessScript (witnessScript []byte ,
368
368
outIndex int ) error {
369
369
370
- p .Upsbt .Outputs [outIndex ].WitnessScript = witnessScript
370
+ u .Upsbt .Outputs [outIndex ].WitnessScript = witnessScript
371
371
372
- if err := p .Upsbt .SanityCheck (); err != nil {
372
+ if err := u .Upsbt .SanityCheck (); err != nil {
373
373
return err
374
374
}
375
375
0 commit comments