Skip to content

Commit fda8a6d

Browse files
committed
tappsbt: support global Unknowns on Packet decode
1 parent 059352c commit fda8a6d

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

tappsbt/decode.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*VPacket, error) {
5252
// NewFromPsbt returns a new instance of a VPacket struct created by reading the
5353
// custom fields on the given PSBT packet.
5454
func NewFromPsbt(packet *psbt.Packet) (*VPacket, error) {
55-
// Make sure we have the correct markers for a virtual transaction.
56-
if len(packet.Unknowns) != 3 {
57-
return nil, fmt.Errorf("expected 3 global unknown fields, "+
58-
"got %d", len(packet.Unknowns))
59-
}
60-
6155
// We want an explicit "isVirtual" boolean marker.
6256
isVirtual, err := findCustomFieldsByKeyPrefix(
6357
packet.Unknowns, PsbtKeyTypeGlobalTapIsVirtualTx,
@@ -83,16 +77,16 @@ func NewFromPsbt(packet *psbt.Packet) (*VPacket, error) {
8377
"params HRP: %w", err)
8478
}
8579

86-
// The version is currently optional. An unset version implies a V0
87-
// VPacket.
88-
var version uint8
80+
// We also need the VPacket version.
8981
versionField, err := findCustomFieldsByKeyPrefix(
9082
packet.Unknowns, PsbtKeyTypeGlobalTapPsbtVersion,
9183
)
92-
if err == nil {
93-
version = versionField.Value[0]
84+
if err != nil {
85+
return nil, fmt.Errorf("error finding virtual tx version: %w",
86+
err)
9487
}
9588

89+
version := versionField.Value[0]
9690
switch version {
9791
case uint8(V0), uint8(V1):
9892
default:

0 commit comments

Comments
 (0)