Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package conway

import (
"errors"
"fmt"

"github.com/blinklabs-io/gouroboros/cbor"
Expand Down Expand Up @@ -275,7 +276,8 @@ func (w ConwayTransactionWitnessSet) Redeemers() common.TransactionWitnessRedeem
}

type ConwayTransactionInputSet struct {
items []shelley.ShelleyTransactionInput
useSet bool
items []shelley.ShelleyTransactionInput
}

func NewConwayTransactionInputSet(
Expand All @@ -288,7 +290,16 @@ func NewConwayTransactionInputSet(
}

func (s *ConwayTransactionInputSet) UnmarshalCBOR(data []byte) error {
// This overrides the Shelley behavior that explicitly disallowed tag-wrapped sets
// Check if the set is wrapped in a CBOR tag
// This is mostly needed so we can remember whether it was Set-wrapped for CBOR encoding
var tmpTag cbor.RawTag
if _, err := cbor.Decode(data, &tmpTag); err == nil {
if tmpTag.Number != cbor.CborTagSet {
return errors.New("unexpected tag type")
}
data = []byte(tmpTag.Content)
s.useSet = true
}
var tmpData []shelley.ShelleyTransactionInput
if _, err := cbor.Decode(data, &tmpData); err != nil {
return err
Expand All @@ -297,6 +308,18 @@ func (s *ConwayTransactionInputSet) UnmarshalCBOR(data []byte) error {
return nil
}

func (s *ConwayTransactionInputSet) MarshalCBOR() ([]byte, error) {
tmpItems := make([]any, len(s.items))
for i, item := range s.items {
tmpItems[i] = item
}
var tmpData any = tmpItems
if s.useSet {
tmpData = cbor.Set(tmpItems)
}
return cbor.Encode(tmpData)
}

func (s *ConwayTransactionInputSet) Items() []shelley.ShelleyTransactionInput {
return s.items
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ func (s *ShelleyTransactionInputSet) UnmarshalCBOR(data []byte) error {
return nil
}

func (s *ShelleyTransactionInputSet) MarshalCBOR() ([]byte, error) {
return cbor.Encode(s.items)
}

func (s *ShelleyTransactionInputSet) Items() []ShelleyTransactionInput {
return s.items
}
Expand Down
Loading