Skip to content

Commit

Permalink
psbt: rename receiver to match rest of code
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed May 2, 2022
1 parent a336854 commit a764afd
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions btcutil/psbt/updater.go
Expand Up @@ -14,9 +14,9 @@ import (
"bytes"
"crypto/sha256"

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcd/btcutil"
)

// Updater encapsulates the role 'Updater' as specified in BIP174; it accepts
Expand All @@ -40,14 +40,14 @@ func NewUpdater(p *Packet) (*Updater, error) {
// non-witness. This requires provision of a full transaction (which is the
// source of the corresponding prevOut), and the input index. If addition of
// this key-value pair to the Psbt fails, an error is returned.
func (p *Updater) AddInNonWitnessUtxo(tx *wire.MsgTx, inIndex int) error {
if inIndex > len(p.Upsbt.Inputs)-1 {
func (u *Updater) AddInNonWitnessUtxo(tx *wire.MsgTx, inIndex int) error {
if inIndex > len(u.Upsbt.Inputs)-1 {
return ErrInvalidPrevOutNonWitnessTransaction
}

p.Upsbt.Inputs[inIndex].NonWitnessUtxo = tx
u.Upsbt.Inputs[inIndex].NonWitnessUtxo = tx

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return ErrInvalidPsbtFormat
}

Expand All @@ -59,14 +59,14 @@ func (p *Updater) AddInNonWitnessUtxo(tx *wire.MsgTx, inIndex int) error {
// of the corresponding prevOut); not the full transaction because BIP143 means
// the output information is sufficient, and the input index. If addition of
// this key-value pair to the Psbt fails, an error is returned.
func (p *Updater) AddInWitnessUtxo(txout *wire.TxOut, inIndex int) error {
if inIndex > len(p.Upsbt.Inputs)-1 {
func (u *Updater) AddInWitnessUtxo(txout *wire.TxOut, inIndex int) error {
if inIndex > len(u.Upsbt.Inputs)-1 {
return ErrInvalidPsbtFormat
}

p.Upsbt.Inputs[inIndex].WitnessUtxo = txout
u.Upsbt.Inputs[inIndex].WitnessUtxo = txout

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return ErrInvalidPsbtFormat
}

Expand All @@ -81,7 +81,7 @@ func (p *Updater) AddInWitnessUtxo(txout *wire.TxOut, inIndex int) error {
// rules are not satisfied, an ErrInvalidSignatureForInput is returned.
//
// NOTE: This function does *not* validate the ECDSA signature itself.
func (p *Updater) addPartialSignature(inIndex int, sig []byte,
func (u *Updater) addPartialSignature(inIndex int, sig []byte,
pubkey []byte) error {

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

pInput := p.Upsbt.Inputs[inIndex]
pInput := u.Upsbt.Inputs[inIndex]

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

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

if pInput.NonWitnessUtxo.TxHash() !=
p.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Hash {
u.Upsbt.UnsignedTx.TxIn[inIndex].PreviousOutPoint.Hash {
return ErrInvalidSignatureForInput
}

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

Expand Down Expand Up @@ -212,11 +212,11 @@ func (p *Updater) addPartialSignature(inIndex int, sig []byte,
}
}

p.Upsbt.Inputs[inIndex].PartialSigs = append(
p.Upsbt.Inputs[inIndex].PartialSigs, &partialSig,
u.Upsbt.Inputs[inIndex].PartialSigs = append(
u.Upsbt.Inputs[inIndex].PartialSigs, &partialSig,
)

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return err
}

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

p.Upsbt.Inputs[inIndex].SighashType = sighashType
u.Upsbt.Inputs[inIndex].SighashType = sighashType

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

p.Upsbt.Inputs[inIndex].RedeemScript = redeemScript
u.Upsbt.Inputs[inIndex].RedeemScript = redeemScript

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return ErrInvalidPsbtFormat
}

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

p.Upsbt.Inputs[inIndex].WitnessScript = witnessScript
u.Upsbt.Inputs[inIndex].WitnessScript = witnessScript

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return err
}

Expand All @@ -279,7 +279,7 @@ func (p *Updater) AddInWitnessScript(witnessScript []byte,
//
// NOTE: This can be called multiple times for the same input. An error is
// returned if addition of this key-value pair to the Psbt fails.
func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
func (u *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
bip32Path []uint32, pubKeyData []byte, inIndex int) error {

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

// Don't allow duplicate keys
for _, x := range p.Upsbt.Inputs[inIndex].Bip32Derivation {
for _, x := range u.Upsbt.Inputs[inIndex].Bip32Derivation {
if bytes.Equal(x.PubKey, bip32Derivation.PubKey) {
return ErrDuplicateKey
}
}

p.Upsbt.Inputs[inIndex].Bip32Derivation = append(
p.Upsbt.Inputs[inIndex].Bip32Derivation, &bip32Derivation,
u.Upsbt.Inputs[inIndex].Bip32Derivation = append(
u.Upsbt.Inputs[inIndex].Bip32Derivation, &bip32Derivation,
)

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return err
}

Expand All @@ -317,7 +317,7 @@ func (p *Updater) AddInBip32Derivation(masterKeyFingerprint uint32,
//
// NOTE: That this can be called multiple times for the same output. An error
// is returned if addition of this key-value pair to the Psbt fails.
func (p *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
func (u *Updater) AddOutBip32Derivation(masterKeyFingerprint uint32,
bip32Path []uint32, pubKeyData []byte, outIndex int) error {

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

// Don't allow duplicate keys
for _, x := range p.Upsbt.Outputs[outIndex].Bip32Derivation {
for _, x := range u.Upsbt.Outputs[outIndex].Bip32Derivation {
if bytes.Equal(x.PubKey, bip32Derivation.PubKey) {
return ErrDuplicateKey
}
}

p.Upsbt.Outputs[outIndex].Bip32Derivation = append(
p.Upsbt.Outputs[outIndex].Bip32Derivation, &bip32Derivation,
u.Upsbt.Outputs[outIndex].Bip32Derivation = append(
u.Upsbt.Outputs[outIndex].Bip32Derivation, &bip32Derivation,
)

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return err
}

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

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

p.Upsbt.Outputs[outIndex].RedeemScript = redeemScript
u.Upsbt.Outputs[outIndex].RedeemScript = redeemScript

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return ErrInvalidPsbtFormat
}

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

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

p.Upsbt.Outputs[outIndex].WitnessScript = witnessScript
u.Upsbt.Outputs[outIndex].WitnessScript = witnessScript

if err := p.Upsbt.SanityCheck(); err != nil {
if err := u.Upsbt.SanityCheck(); err != nil {
return err
}

Expand Down

0 comments on commit a764afd

Please sign in to comment.