Skip to content

Commit a28ef88

Browse files
authored
feat: Support proper encoding/decoding of TX metadata (#1159)
Signed-off-by: Akhil Repala <[email protected]>
1 parent ce7a740 commit a28ef88

File tree

10 files changed

+401
-29
lines changed

10 files changed

+401
-29
lines changed

ledger/allegra/allegra.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type AllegraBlock struct {
4949
BlockHeader *AllegraBlockHeader
5050
TransactionBodies []AllegraTransactionBody
5151
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
52-
TransactionMetadataSet map[uint]*cbor.LazyValue
52+
TransactionMetadataSet common.TransactionMetadataSet
5353
}
5454

5555
func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
@@ -243,7 +243,7 @@ type AllegraTransaction struct {
243243
hash *common.Blake2b256
244244
Body AllegraTransactionBody
245245
WitnessSet shelley.ShelleyTransactionWitnessSet
246-
TxMetadata *cbor.LazyValue
246+
TxMetadata common.TransactionMetadatum
247247
}
248248

249249
func (t *AllegraTransaction) UnmarshalCBOR(cborData []byte) error {
@@ -353,7 +353,7 @@ func (t AllegraTransaction) Donation() uint64 {
353353
return t.Body.Donation()
354354
}
355355

356-
func (t AllegraTransaction) Metadata() *cbor.LazyValue {
356+
func (t AllegraTransaction) Metadata() common.TransactionMetadatum {
357357
return t.TxMetadata
358358
}
359359

@@ -415,7 +415,7 @@ func (t *AllegraTransaction) Cbor() []byte {
415415
cbor.RawMessage(t.WitnessSet.Cbor()),
416416
}
417417
if t.TxMetadata != nil {
418-
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
418+
tmpObj = append(tmpObj, t.TxMetadata)
419419
} else {
420420
tmpObj = append(tmpObj, nil)
421421
}

ledger/alonzo/alonzo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type AlonzoBlock struct {
5555
BlockHeader *AlonzoBlockHeader
5656
TransactionBodies []AlonzoTransactionBody
5757
TransactionWitnessSets []AlonzoTransactionWitnessSet
58-
TransactionMetadataSet map[uint]*cbor.LazyValue
58+
TransactionMetadataSet common.TransactionMetadataSet
5959
InvalidTransactions []uint
6060
}
6161

@@ -86,7 +86,7 @@ func (b *AlonzoBlock) MarshalCBOR() ([]byte, error) {
8686
BlockHeader *AlonzoBlockHeader
8787
TransactionBodies []AlonzoTransactionBody
8888
TransactionWitnessSets []AlonzoTransactionWitnessSet
89-
TransactionMetadataSet map[uint]*cbor.LazyValue
89+
TransactionMetadataSet common.TransactionMetadataSet
9090
InvalidTransactions cbor.IndefLengthList
9191
}
9292

@@ -639,7 +639,7 @@ type AlonzoTransaction struct {
639639
Body AlonzoTransactionBody
640640
WitnessSet AlonzoTransactionWitnessSet
641641
TxIsValid bool
642-
TxMetadata *cbor.LazyValue
642+
TxMetadata common.TransactionMetadatum
643643
}
644644

645645
func (t *AlonzoTransaction) UnmarshalCBOR(cborData []byte) error {
@@ -753,7 +753,7 @@ func (t AlonzoTransaction) Donation() uint64 {
753753
return t.Body.Donation()
754754
}
755755

756-
func (t AlonzoTransaction) Metadata() *cbor.LazyValue {
756+
func (t AlonzoTransaction) Metadata() common.TransactionMetadatum {
757757
return t.TxMetadata
758758
}
759759

@@ -813,7 +813,7 @@ func (t *AlonzoTransaction) Cbor() []byte {
813813
t.TxIsValid,
814814
}
815815
if t.TxMetadata != nil {
816-
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
816+
tmpObj = append(tmpObj, t.TxMetadata)
817817
} else {
818818
tmpObj = append(tmpObj, nil)
819819
}

ledger/babbage/babbage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type BabbageBlock struct {
5555
BlockHeader *BabbageBlockHeader
5656
TransactionBodies []BabbageTransactionBody
5757
TransactionWitnessSets []BabbageTransactionWitnessSet
58-
TransactionMetadataSet map[uint]*cbor.LazyValue
58+
TransactionMetadataSet common.TransactionMetadataSet
5959
InvalidTransactions []uint
6060
}
6161

@@ -846,7 +846,7 @@ type BabbageTransaction struct {
846846
Body BabbageTransactionBody
847847
WitnessSet BabbageTransactionWitnessSet
848848
TxIsValid bool
849-
TxMetadata *cbor.LazyValue
849+
TxMetadata common.TransactionMetadatum
850850
}
851851

852852
func (t *BabbageTransaction) UnmarshalCBOR(cborData []byte) error {
@@ -960,7 +960,7 @@ func (t BabbageTransaction) Donation() uint64 {
960960
return t.Body.Donation()
961961
}
962962

963-
func (t BabbageTransaction) Metadata() *cbor.LazyValue {
963+
func (t BabbageTransaction) Metadata() common.TransactionMetadatum {
964964
return t.TxMetadata
965965
}
966966

@@ -1027,7 +1027,7 @@ func (t *BabbageTransaction) Cbor() []byte {
10271027
t.TxIsValid,
10281028
}
10291029
if t.TxMetadata != nil {
1030-
tmpObj = append(tmpObj, cbor.RawMessage(t.TxMetadata.Cbor()))
1030+
tmpObj = append(tmpObj, t.TxMetadata)
10311031
} else {
10321032
tmpObj = append(tmpObj, nil)
10331033
}

ledger/byron/byron.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type ByronTransaction struct {
155155
hash *common.Blake2b256
156156
TxInputs []ByronTransactionInput
157157
TxOutputs []ByronTransactionOutput
158-
Attributes *cbor.LazyValue
158+
Attributes cbor.RawMessage
159159
}
160160

161161
func (t *ByronTransaction) UnmarshalCBOR(cborData []byte) error {
@@ -288,8 +288,8 @@ func (t *ByronTransaction) Donation() uint64 {
288288
return 0
289289
}
290290

291-
func (t *ByronTransaction) Metadata() *cbor.LazyValue {
292-
return t.Attributes
291+
func (t *ByronTransaction) Metadata() common.TransactionMetadatum {
292+
return nil
293293
}
294294

295295
func (t *ByronTransaction) LeiosHash() common.Blake2b256 {

0 commit comments

Comments
 (0)