@@ -70,6 +70,46 @@ func (b *AlonzoBlock) UnmarshalCBOR(cborData []byte) error {
7070 return nil
7171}
7272
73+ func (b * AlonzoBlock ) MarshalCBOR () ([]byte , error ) {
74+ // Return stored CBOR if available
75+ if b .Cbor () != nil {
76+ return b .Cbor (), nil
77+ }
78+
79+ // When encoding from scratch, we need to use indefinite-length encoding
80+ // for InvalidTransactions to match the original on-chain format
81+
82+ // Create a temporary block for encoding
83+ type tmpBlock struct {
84+ cbor.StructAsArray
85+ cbor.DecodeStoreCbor
86+ BlockHeader * AlonzoBlockHeader
87+ TransactionBodies []AlonzoTransactionBody
88+ TransactionWitnessSets []AlonzoTransactionWitnessSet
89+ TransactionMetadataSet map [uint ]* cbor.LazyValue
90+ InvalidTransactions cbor.IndefLengthList
91+ }
92+
93+ // Convert InvalidTransactions to IndefLengthList
94+ var invalidTx cbor.IndefLengthList
95+ if b .InvalidTransactions != nil {
96+ invalidTx = make (cbor.IndefLengthList , len (b .InvalidTransactions ))
97+ for i , tx := range b .InvalidTransactions {
98+ invalidTx [i ] = tx
99+ }
100+ }
101+
102+ temp := tmpBlock {
103+ BlockHeader : b .BlockHeader ,
104+ TransactionBodies : b .TransactionBodies ,
105+ TransactionWitnessSets : b .TransactionWitnessSets ,
106+ TransactionMetadataSet : b .TransactionMetadataSet ,
107+ InvalidTransactions : invalidTx ,
108+ }
109+
110+ return cbor .Encode (& temp )
111+ }
112+
73113func (AlonzoBlock ) Type () int {
74114 return BlockTypeAlonzo
75115}
0 commit comments