1515package conway
1616
1717import (
18+ "errors"
1819 "fmt"
1920
2021 "github.com/blinklabs-io/gouroboros/cbor"
@@ -275,7 +276,8 @@ func (w ConwayTransactionWitnessSet) Redeemers() common.TransactionWitnessRedeem
275276}
276277
277278type ConwayTransactionInputSet struct {
278- items []shelley.ShelleyTransactionInput
279+ useSet bool
280+ items []shelley.ShelleyTransactionInput
279281}
280282
281283func NewConwayTransactionInputSet (
@@ -288,7 +290,16 @@ func NewConwayTransactionInputSet(
288290}
289291
290292func (s * ConwayTransactionInputSet ) UnmarshalCBOR (data []byte ) error {
291- // This overrides the Shelley behavior that explicitly disallowed tag-wrapped sets
293+ // Check if the set is wrapped in a CBOR tag
294+ // This is mostly needed so we can remember whether it was Set-wrapped for CBOR encoding
295+ var tmpTag cbor.RawTag
296+ if _ , err := cbor .Decode (data , & tmpTag ); err == nil {
297+ if tmpTag .Number != cbor .CborTagSet {
298+ return errors .New ("unexpected tag type" )
299+ }
300+ data = []byte (tmpTag .Content )
301+ s .useSet = true
302+ }
292303 var tmpData []shelley.ShelleyTransactionInput
293304 if _ , err := cbor .Decode (data , & tmpData ); err != nil {
294305 return err
@@ -297,6 +308,18 @@ func (s *ConwayTransactionInputSet) UnmarshalCBOR(data []byte) error {
297308 return nil
298309}
299310
311+ func (s * ConwayTransactionInputSet ) MarshalCBOR () ([]byte , error ) {
312+ tmpItems := make ([]any , len (s .items ))
313+ for i , item := range s .items {
314+ tmpItems [i ] = item
315+ }
316+ var tmpData any = tmpItems
317+ if s .useSet {
318+ tmpData = cbor .Set (tmpItems )
319+ }
320+ return cbor .Encode (tmpData )
321+ }
322+
300323func (s * ConwayTransactionInputSet ) Items () []shelley.ShelleyTransactionInput {
301324 return s .items
302325}
0 commit comments