From b0118ccef41853be2f503990722b0f503543bc84 Mon Sep 17 00:00:00 2001 From: Jonathan Harvey-Buschel Date: Thu, 31 Oct 2024 15:13:02 -0400 Subject: [PATCH] tappsbt: support global Unknowns on Packet decode --- tappsbt/decode.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/tappsbt/decode.go b/tappsbt/decode.go index 96a233a2c..edd9e2a60 100644 --- a/tappsbt/decode.go +++ b/tappsbt/decode.go @@ -52,12 +52,6 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*VPacket, error) { // NewFromPsbt returns a new instance of a VPacket struct created by reading the // custom fields on the given PSBT packet. func NewFromPsbt(packet *psbt.Packet) (*VPacket, error) { - // Make sure we have the correct markers for a virtual transaction. - if len(packet.Unknowns) != 3 { - return nil, fmt.Errorf("expected 3 global unknown fields, "+ - "got %d", len(packet.Unknowns)) - } - // We want an explicit "isVirtual" boolean marker. isVirtual, err := findCustomFieldsByKeyPrefix( packet.Unknowns, PsbtKeyTypeGlobalTapIsVirtualTx, @@ -83,16 +77,16 @@ func NewFromPsbt(packet *psbt.Packet) (*VPacket, error) { "params HRP: %w", err) } - // The version is currently optional. An unset version implies a V0 - // VPacket. - var version uint8 + // We also need the VPacket version. versionField, err := findCustomFieldsByKeyPrefix( packet.Unknowns, PsbtKeyTypeGlobalTapPsbtVersion, ) - if err == nil { - version = versionField.Value[0] + if err != nil { + return nil, fmt.Errorf("error finding virtual tx version: %w", + err) } + version := versionField.Value[0] switch version { case uint8(V0), uint8(V1): default: