Skip to content

Commit a764afd

Browse files
committed
psbt: rename receiver to match rest of code
1 parent a336854 commit a764afd

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

Diff for: btcutil/psbt/updater.go

+42-42
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"bytes"
1515
"crypto/sha256"
1616

17+
"github.com/btcsuite/btcd/btcutil"
1718
"github.com/btcsuite/btcd/txscript"
1819
"github.com/btcsuite/btcd/wire"
19-
"github.com/btcsuite/btcd/btcutil"
2020
)
2121

2222
// Updater encapsulates the role 'Updater' as specified in BIP174; it accepts
@@ -40,14 +40,14 @@ func NewUpdater(p *Packet) (*Updater, error) {
4040
// non-witness. This requires provision of a full transaction (which is the
4141
// source of the corresponding prevOut), and the input index. If addition of
4242
// 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 {
4545
return ErrInvalidPrevOutNonWitnessTransaction
4646
}
4747

48-
p.Upsbt.Inputs[inIndex].NonWitnessUtxo = tx
48+
u.Upsbt.Inputs[inIndex].NonWitnessUtxo = tx
4949

50-
if err := p.Upsbt.SanityCheck(); err != nil {
50+
if err := u.Upsbt.SanityCheck(); err != nil {
5151
return ErrInvalidPsbtFormat
5252
}
5353

@@ -59,14 +59,14 @@ func (p *Updater) AddInNonWitnessUtxo(tx *wire.MsgTx, inIndex int) error {
5959
// of the corresponding prevOut); not the full transaction because BIP143 means
6060
// the output information is sufficient, and the input index. If addition of
6161
// 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 {
6464
return ErrInvalidPsbtFormat
6565
}
6666

67-
p.Upsbt.Inputs[inIndex].WitnessUtxo = txout
67+
u.Upsbt.Inputs[inIndex].WitnessUtxo = txout
6868

69-
if err := p.Upsbt.SanityCheck(); err != nil {
69+
if err := u.Upsbt.SanityCheck(); err != nil {
7070
return ErrInvalidPsbtFormat
7171
}
7272

@@ -81,7 +81,7 @@ func (p *Updater) AddInWitnessUtxo(txout *wire.TxOut, inIndex int) error {
8181
// rules are not satisfied, an ErrInvalidSignatureForInput is returned.
8282
//
8383
// 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,
8585
pubkey []byte) error {
8686

8787
partialSig := PartialSig{
@@ -93,7 +93,7 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
9393
return ErrInvalidPsbtFormat
9494
}
9595

96-
pInput := p.Upsbt.Inputs[inIndex]
96+
pInput := u.Upsbt.Inputs[inIndex]
9797

9898
// First check; don't add duplicates.
9999
for _, x := range pInput.PartialSigs {
@@ -109,12 +109,12 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
109109

110110
// Next, we perform a series of additional sanity checks.
111111
if pInput.NonWitnessUtxo != nil {
112-
if len(p.Upsbt.UnsignedTx.TxIn) < inIndex+1 {
112+
if len(u.Upsbt.UnsignedTx.TxIn) < inIndex+1 {
113113
return ErrInvalidPrevOutNonWitnessTransaction
114114
}
115115

116116
if pInput.NonWitnessUtxo.TxHash() !=
117-
p.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Hash {
117+
u.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Hash {
118118
return ErrInvalidSignatureForInput
119119
}
120120

@@ -123,7 +123,7 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
123123
// that with the P2SH scriptPubKey that is generated by
124124
// redeemScript.
125125
if pInput.RedeemScript != nil {
126-
outIndex := p.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Index
126+
outIndex := u.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Index
127127
scriptPubKey := pInput.NonWitnessUtxo.TxOut[outIndex].PkScript
128128
scriptHash := btcutil.Hash160(pInput.RedeemScript)
129129

@@ -212,11 +212,11 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
212212
}
213213
}
214214

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,
217217
)
218218

219-
if err := p.Upsbt.SanityCheck(); err != nil {
219+
if err := u.Upsbt.SanityCheck(); err != nil {
220220
return err
221221
}
222222

@@ -229,12 +229,12 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
229229
// sighash type is passed as a 32 bit unsigned integer, along with the index
230230
// for the input. An error is returned if addition of this key-value pair to
231231
// the Psbt fails.
232-
func (p *Updater) AddInSighashType(sighashType txscript.SigHashType,
232+
func (u *Updater) AddInSighashType(sighashType txscript.SigHashType,
233233
inIndex int) error {
234234

235-
p.Upsbt.Inputs[inIndex].SighashType = sighashType
235+
u.Upsbt.Inputs[inIndex].SighashType = sighashType
236236

237-
if err := p.Upsbt.SanityCheck(); err != nil {
237+
if err := u.Upsbt.SanityCheck(); err != nil {
238238
return err
239239
}
240240
return nil
@@ -244,12 +244,12 @@ func (p *Updater) AddInSighashType(sighashType txscript.SigHashType,
244244
// redeem script is passed serialized, as a byte slice, along with the index of
245245
// the input. An error is returned if addition of this key-value pair to the
246246
// Psbt fails.
247-
func (p *Updater) AddInRedeemScript(redeemScript []byte,
247+
func (u *Updater) AddInRedeemScript(redeemScript []byte,
248248
inIndex int) error {
249249

250-
p.Upsbt.Inputs[inIndex].RedeemScript = redeemScript
250+
u.Upsbt.Inputs[inIndex].RedeemScript = redeemScript
251251

252-
if err := p.Upsbt.SanityCheck(); err != nil {
252+
if err := u.Upsbt.SanityCheck(); err != nil {
253253
return ErrInvalidPsbtFormat
254254
}
255255

@@ -260,12 +260,12 @@ func (p *Updater) AddInRedeemScript(redeemScript []byte,
260260
// witness script is passed serialized, as a byte slice, along with the index
261261
// of the input. An error is returned if addition of this key-value pair to the
262262
// Psbt fails.
263-
func (p *Updater) AddInWitnessScript(witnessScript []byte,
263+
func (u *Updater) AddInWitnessScript(witnessScript []byte,
264264
inIndex int) error {
265265

266-
p.Upsbt.Inputs[inIndex].WitnessScript = witnessScript
266+
u.Upsbt.Inputs[inIndex].WitnessScript = witnessScript
267267

268-
if err := p.Upsbt.SanityCheck(); err != nil {
268+
if err := u.Upsbt.SanityCheck(); err != nil {
269269
return err
270270
}
271271

@@ -279,7 +279,7 @@ func (p *Updater) AddInWitnessScript(witnessScript []byte,
279279
//
280280
// NOTE: This can be called multiple times for the same input. An error is
281281
// 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,
283283
bip32Path []uint32, pubKeyData []byte, inIndex int) error {
284284

285285
bip32Derivation := Bip32Derivation{
@@ -293,17 +293,17 @@ func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
293293
}
294294

295295
// Don't allow duplicate keys
296-
for _, x := range p.Upsbt.Inputs[inIndex].Bip32Derivation {
296+
for _, x := range u.Upsbt.Inputs[inIndex].Bip32Derivation {
297297
if bytes.Equal(x.PubKey, bip32Derivation.PubKey) {
298298
return ErrDuplicateKey
299299
}
300300
}
301301

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,
304304
)
305305

306-
if err := p.Upsbt.SanityCheck(); err != nil {
306+
if err := u.Upsbt.SanityCheck(); err != nil {
307307
return err
308308
}
309309

@@ -317,7 +317,7 @@ func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
317317
//
318318
// NOTE: That this can be called multiple times for the same output. An error
319319
// 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,
321321
bip32Path []uint32, pubKeyData []byte, outIndex int) error {
322322

323323
bip32Derivation := Bip32Derivation{
@@ -331,17 +331,17 @@ func (p *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
331331
}
332332

333333
// Don't allow duplicate keys
334-
for _, x := range p.Upsbt.Outputs[outIndex].Bip32Derivation {
334+
for _, x := range u.Upsbt.Outputs[outIndex].Bip32Derivation {
335335
if bytes.Equal(x.PubKey, bip32Derivation.PubKey) {
336336
return ErrDuplicateKey
337337
}
338338
}
339339

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,
342342
)
343343

344-
if err := p.Upsbt.SanityCheck(); err != nil {
344+
if err := u.Upsbt.SanityCheck(); err != nil {
345345
return err
346346
}
347347

@@ -350,12 +350,12 @@ func (p *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
350350

351351
// AddOutRedeemScript takes a redeem script as a byte slice and appends it to
352352
// the output at index outIndex.
353-
func (p *Updater) AddOutRedeemScript(redeemScript []byte,
353+
func (u *Updater) AddOutRedeemScript(redeemScript []byte,
354354
outIndex int) error {
355355

356-
p.Upsbt.Outputs[outIndex].RedeemScript = redeemScript
356+
u.Upsbt.Outputs[outIndex].RedeemScript = redeemScript
357357

358-
if err := p.Upsbt.SanityCheck(); err != nil {
358+
if err := u.Upsbt.SanityCheck(); err != nil {
359359
return ErrInvalidPsbtFormat
360360
}
361361

@@ -364,12 +364,12 @@ func (p *Updater) AddOutRedeemScript(redeemScript []byte,
364364

365365
// AddOutWitnessScript takes a witness script as a byte slice and appends it to
366366
// the output at index outIndex.
367-
func (p *Updater) AddOutWitnessScript(witnessScript []byte,
367+
func (u *Updater) AddOutWitnessScript(witnessScript []byte,
368368
outIndex int) error {
369369

370-
p.Upsbt.Outputs[outIndex].WitnessScript = witnessScript
370+
u.Upsbt.Outputs[outIndex].WitnessScript = witnessScript
371371

372-
if err := p.Upsbt.SanityCheck(); err != nil {
372+
if err := u.Upsbt.SanityCheck(); err != nil {
373373
return err
374374
}
375375

0 commit comments

Comments
 (0)