Skip to content

Commit 691e7ec

Browse files
authored
Merge pull request #377 from blinklabs-io/feat/tx-metadata-pointer
feat: use pointer for TX metadata to better handle nil value
2 parents 9928195 + f2e5943 commit 691e7ec

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

cmd/block-fetch/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func main() {
8989
fmt.Printf("\nTransactions:\n")
9090
for _, tx := range block.Transactions() {
9191
fmt.Printf(" Hash: %s\n", tx.Hash())
92-
if tx.Metadata().Value() != nil {
92+
if tx.Metadata() != nil {
9393
fmt.Printf(" Metadata:\n %#v (%x)\n", tx.Metadata().Value(), tx.Metadata().Cbor())
9494
}
9595
fmt.Printf(" Inputs:\n")

ledger/allegra.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type AllegraBlock struct {
3636
Header *AllegraBlockHeader
3737
TransactionBodies []AllegraTransactionBody
3838
TransactionWitnessSets []ShelleyTransactionWitnessSet
39-
TransactionMetadataSet map[uint]cbor.Value
39+
TransactionMetadataSet map[uint]*cbor.Value
4040
}
4141

4242
func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
@@ -94,7 +94,7 @@ type AllegraTransaction struct {
9494
cbor.DecodeStoreCbor
9595
Body AllegraTransactionBody
9696
WitnessSet ShelleyTransactionWitnessSet
97-
TxMetadata cbor.Value
97+
TxMetadata *cbor.Value
9898
}
9999

100100
func (t AllegraTransaction) Hash() string {
@@ -109,7 +109,7 @@ func (t AllegraTransaction) Outputs() []TransactionOutput {
109109
return t.Body.Outputs()
110110
}
111111

112-
func (t AllegraTransaction) Metadata() cbor.Value {
112+
func (t AllegraTransaction) Metadata() *cbor.Value {
113113
return t.TxMetadata
114114
}
115115

ledger/alonzo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type AlonzoBlock struct {
3737
Header *AlonzoBlockHeader
3838
TransactionBodies []AlonzoTransactionBody
3939
TransactionWitnessSets []AlonzoTransactionWitnessSet
40-
TransactionMetadataSet map[uint]cbor.Value
40+
TransactionMetadataSet map[uint]*cbor.Value
4141
InvalidTransactions []uint
4242
}
4343

@@ -182,7 +182,7 @@ type AlonzoTransaction struct {
182182
Body AlonzoTransactionBody
183183
WitnessSet AlonzoTransactionWitnessSet
184184
IsValid bool
185-
TxMetadata cbor.Value
185+
TxMetadata *cbor.Value
186186
}
187187

188188
func (t AlonzoTransaction) Hash() string {
@@ -197,7 +197,7 @@ func (t AlonzoTransaction) Outputs() []TransactionOutput {
197197
return t.Body.Outputs()
198198
}
199199

200-
func (t AlonzoTransaction) Metadata() cbor.Value {
200+
func (t AlonzoTransaction) Metadata() *cbor.Value {
201201
return t.TxMetadata
202202
}
203203

ledger/babbage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type BabbageBlock struct {
3737
Header *BabbageBlockHeader
3838
TransactionBodies []BabbageTransactionBody
3939
TransactionWitnessSets []BabbageTransactionWitnessSet
40-
TransactionMetadataSet map[uint]cbor.Value
40+
TransactionMetadataSet map[uint]*cbor.Value
4141
InvalidTransactions []uint
4242
}
4343

@@ -295,7 +295,7 @@ type BabbageTransaction struct {
295295
Body BabbageTransactionBody
296296
WitnessSet BabbageTransactionWitnessSet
297297
IsValid bool
298-
TxMetadata cbor.Value
298+
TxMetadata *cbor.Value
299299
}
300300

301301
func (t BabbageTransaction) Hash() string {
@@ -310,7 +310,7 @@ func (t BabbageTransaction) Outputs() []TransactionOutput {
310310
return t.Body.Outputs()
311311
}
312312

313-
func (t BabbageTransaction) Metadata() cbor.Value {
313+
func (t BabbageTransaction) Metadata() *cbor.Value {
314314
return t.TxMetadata
315315
}
316316

ledger/byron.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type ByronTransaction struct {
105105
// TODO: flesh these out
106106
TxInputs []any
107107
TxOutputs []any
108-
Attributes cbor.Value
108+
Attributes *cbor.Value
109109
}
110110

111111
func (t *ByronTransaction) Hash() string {
@@ -123,7 +123,7 @@ func (t *ByronTransaction) Outputs() []TransactionOutput {
123123
return nil
124124
}
125125

126-
func (t *ByronTransaction) Metadata() cbor.Value {
126+
func (t *ByronTransaction) Metadata() *cbor.Value {
127127
return t.Attributes
128128
}
129129

ledger/mary.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type MaryBlock struct {
3737
Header *MaryBlockHeader
3838
TransactionBodies []MaryTransactionBody
3939
TransactionWitnessSets []ShelleyTransactionWitnessSet
40-
TransactionMetadataSet map[uint]cbor.Value
40+
TransactionMetadataSet map[uint]*cbor.Value
4141
}
4242

4343
func (b *MaryBlock) UnmarshalCBOR(cborData []byte) error {
@@ -104,7 +104,7 @@ type MaryTransaction struct {
104104
cbor.DecodeStoreCbor
105105
Body MaryTransactionBody
106106
WitnessSet ShelleyTransactionWitnessSet
107-
TxMetadata cbor.Value
107+
TxMetadata *cbor.Value
108108
}
109109

110110
func (t MaryTransaction) Hash() string {
@@ -119,7 +119,7 @@ func (t MaryTransaction) Outputs() []TransactionOutput {
119119
return t.Body.Outputs()
120120
}
121121

122-
func (t MaryTransaction) Metadata() cbor.Value {
122+
func (t MaryTransaction) Metadata() *cbor.Value {
123123
return t.TxMetadata
124124
}
125125

ledger/shelley.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ShelleyBlock struct {
3636
Header *ShelleyBlockHeader
3737
TransactionBodies []ShelleyTransactionBody
3838
TransactionWitnessSets []ShelleyTransactionWitnessSet
39-
TransactionMetadataSet map[uint]cbor.Value
39+
TransactionMetadataSet map[uint]*cbor.Value
4040
}
4141

4242
func (b *ShelleyBlock) UnmarshalCBOR(cborData []byte) error {
@@ -227,7 +227,7 @@ type ShelleyTransaction struct {
227227
cbor.DecodeStoreCbor
228228
Body ShelleyTransactionBody
229229
WitnessSet ShelleyTransactionWitnessSet
230-
TxMetadata cbor.Value
230+
TxMetadata *cbor.Value
231231
}
232232

233233
func (t ShelleyTransaction) Hash() string {
@@ -242,7 +242,7 @@ func (t ShelleyTransaction) Outputs() []TransactionOutput {
242242
return t.Body.Outputs()
243243
}
244244

245-
func (t ShelleyTransaction) Metadata() cbor.Value {
245+
func (t ShelleyTransaction) Metadata() *cbor.Value {
246246
return t.TxMetadata
247247
}
248248

ledger/tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
type Transaction interface {
2626
TransactionBody
27-
Metadata() cbor.Value
27+
Metadata() *cbor.Value
2828
}
2929

3030
type TransactionBody interface {

0 commit comments

Comments
 (0)