Skip to content

Commit

Permalink
psbt: use pointer slice for global unknowns
Browse files Browse the repository at this point in the history
To unify the way the unknown fields are handled, we change the global
ones to a slice of pointers as well. This makes it easier to add
generic handler code for unknown fields, if they are uniform across the
levels (global, input, output).
  • Loading branch information
guggero committed Jan 27, 2023
1 parent 5ebbb1b commit 6c81c66
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions btcutil/psbt/psbt.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type Unknown struct {
Value []byte
}

// Packet is the actual psbt repreesntation. It is a is a set of 1 + N + M
// Packet is the actual psbt representation. It is a set of 1 + N + M
// key-value pair lists, 1 global, defining the unsigned transaction structure
// with N inputs and M outputs. These key-value pairs can contain scripts,
// signatures, key derivations and other transaction-defining data.
Expand All @@ -130,7 +130,7 @@ type Packet struct {
Outputs []POutput

// Unknowns are the set of custom types (global only) within this PSBT.
Unknowns []Unknown
Unknowns []*Unknown
}

// validateUnsignedTx returns true if the transaction is unsigned. Note that
Expand All @@ -155,7 +155,7 @@ func NewFromUnsignedTx(tx *wire.MsgTx) (*Packet, error) {

inSlice := make([]PInput, len(tx.TxIn))
outSlice := make([]POutput, len(tx.TxOut))
unknownSlice := make([]Unknown, 0)
unknownSlice := make([]*Unknown, 0)

return &Packet{
UnsignedTx: tx,
Expand Down Expand Up @@ -224,7 +224,7 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*Packet, error) {

// Next we parse any unknowns that may be present, making sure that we
// break at the separator.
var unknownSlice []Unknown
var unknownSlice []*Unknown
for {
keyint, keydata, err := getKey(r)
if err != nil {
Expand All @@ -244,7 +244,7 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*Packet, error) {
keyintanddata := []byte{byte(keyint)}
keyintanddata = append(keyintanddata, keydata...)

newUnknown := Unknown{
newUnknown := &Unknown{
Key: keyintanddata,
Value: value,
}
Expand Down

0 comments on commit 6c81c66

Please sign in to comment.