Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use pointer for TX metadata to better handle nil value #377

Merged
merged 1 commit into from
Aug 21, 2023
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
2 changes: 1 addition & 1 deletion cmd/block-fetch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func main() {
fmt.Printf("\nTransactions:\n")
for _, tx := range block.Transactions() {
fmt.Printf(" Hash: %s\n", tx.Hash())
if tx.Metadata().Value() != nil {
if tx.Metadata() != nil {
fmt.Printf(" Metadata:\n %#v (%x)\n", tx.Metadata().Value(), tx.Metadata().Cbor())
}
fmt.Printf(" Inputs:\n")
Expand Down
6 changes: 3 additions & 3 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type AllegraBlock struct {
Header *AllegraBlockHeader
TransactionBodies []AllegraTransactionBody
TransactionWitnessSets []ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]cbor.Value
TransactionMetadataSet map[uint]*cbor.Value
}

func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -94,7 +94,7 @@ type AllegraTransaction struct {
cbor.DecodeStoreCbor
Body AllegraTransactionBody
WitnessSet ShelleyTransactionWitnessSet
TxMetadata cbor.Value
TxMetadata *cbor.Value
}

func (t AllegraTransaction) Hash() string {
Expand All @@ -109,7 +109,7 @@ func (t AllegraTransaction) Outputs() []TransactionOutput {
return t.Body.Outputs()
}

func (t AllegraTransaction) Metadata() cbor.Value {
func (t AllegraTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}

Expand Down
6 changes: 3 additions & 3 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type AlonzoBlock struct {
Header *AlonzoBlockHeader
TransactionBodies []AlonzoTransactionBody
TransactionWitnessSets []AlonzoTransactionWitnessSet
TransactionMetadataSet map[uint]cbor.Value
TransactionMetadataSet map[uint]*cbor.Value
InvalidTransactions []uint
}

Expand Down Expand Up @@ -182,7 +182,7 @@ type AlonzoTransaction struct {
Body AlonzoTransactionBody
WitnessSet AlonzoTransactionWitnessSet
IsValid bool
TxMetadata cbor.Value
TxMetadata *cbor.Value
}

func (t AlonzoTransaction) Hash() string {
Expand All @@ -197,7 +197,7 @@ func (t AlonzoTransaction) Outputs() []TransactionOutput {
return t.Body.Outputs()
}

func (t AlonzoTransaction) Metadata() cbor.Value {
func (t AlonzoTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}

Expand Down
6 changes: 3 additions & 3 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type BabbageBlock struct {
Header *BabbageBlockHeader
TransactionBodies []BabbageTransactionBody
TransactionWitnessSets []BabbageTransactionWitnessSet
TransactionMetadataSet map[uint]cbor.Value
TransactionMetadataSet map[uint]*cbor.Value
InvalidTransactions []uint
}

Expand Down Expand Up @@ -295,7 +295,7 @@ type BabbageTransaction struct {
Body BabbageTransactionBody
WitnessSet BabbageTransactionWitnessSet
IsValid bool
TxMetadata cbor.Value
TxMetadata *cbor.Value
}

func (t BabbageTransaction) Hash() string {
Expand All @@ -310,7 +310,7 @@ func (t BabbageTransaction) Outputs() []TransactionOutput {
return t.Body.Outputs()
}

func (t BabbageTransaction) Metadata() cbor.Value {
func (t BabbageTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}

Expand Down
4 changes: 2 additions & 2 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type ByronTransaction struct {
// TODO: flesh these out
TxInputs []any
TxOutputs []any
Attributes cbor.Value
Attributes *cbor.Value
}

func (t *ByronTransaction) Hash() string {
Expand All @@ -123,7 +123,7 @@ func (t *ByronTransaction) Outputs() []TransactionOutput {
return nil
}

func (t *ByronTransaction) Metadata() cbor.Value {
func (t *ByronTransaction) Metadata() *cbor.Value {
return t.Attributes
}

Expand Down
6 changes: 3 additions & 3 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MaryBlock struct {
Header *MaryBlockHeader
TransactionBodies []MaryTransactionBody
TransactionWitnessSets []ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]cbor.Value
TransactionMetadataSet map[uint]*cbor.Value
}

func (b *MaryBlock) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -104,7 +104,7 @@ type MaryTransaction struct {
cbor.DecodeStoreCbor
Body MaryTransactionBody
WitnessSet ShelleyTransactionWitnessSet
TxMetadata cbor.Value
TxMetadata *cbor.Value
}

func (t MaryTransaction) Hash() string {
Expand All @@ -119,7 +119,7 @@ func (t MaryTransaction) Outputs() []TransactionOutput {
return t.Body.Outputs()
}

func (t MaryTransaction) Metadata() cbor.Value {
func (t MaryTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}

Expand Down
6 changes: 3 additions & 3 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ShelleyBlock struct {
Header *ShelleyBlockHeader
TransactionBodies []ShelleyTransactionBody
TransactionWitnessSets []ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]cbor.Value
TransactionMetadataSet map[uint]*cbor.Value
}

func (b *ShelleyBlock) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -227,7 +227,7 @@ type ShelleyTransaction struct {
cbor.DecodeStoreCbor
Body ShelleyTransactionBody
WitnessSet ShelleyTransactionWitnessSet
TxMetadata cbor.Value
TxMetadata *cbor.Value
}

func (t ShelleyTransaction) Hash() string {
Expand All @@ -242,7 +242,7 @@ func (t ShelleyTransaction) Outputs() []TransactionOutput {
return t.Body.Outputs()
}

func (t ShelleyTransaction) Metadata() cbor.Value {
func (t ShelleyTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}

Expand Down
2 changes: 1 addition & 1 deletion ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type Transaction interface {
TransactionBody
Metadata() cbor.Value
Metadata() *cbor.Value
}

type TransactionBody interface {
Expand Down
Loading