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
9 changes: 9 additions & 0 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (b *AllegraTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
type AllegraTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body AllegraTransactionBody
WitnessSet shelley.ShelleyTransactionWitnessSet
TxMetadata *cbor.LazyValue
Expand Down Expand Up @@ -264,6 +265,14 @@ func (t AllegraTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t AllegraTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t AllegraTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ func (w AlonzoTransactionWitnessSet) Redeemers() common.TransactionWitnessRedeem
type AlonzoTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body AlonzoTransactionBody
WitnessSet AlonzoTransactionWitnessSet
TxIsValid bool
Expand Down Expand Up @@ -616,6 +617,14 @@ func (t AlonzoTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t AlonzoTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t AlonzoTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func (w BabbageTransactionWitnessSet) Redeemers() common.TransactionWitnessRedee
type BabbageTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body BabbageTransactionBody
WitnessSet BabbageTransactionWitnessSet
TxIsValid bool
Expand Down Expand Up @@ -758,6 +759,14 @@ func (t BabbageTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t BabbageTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t BabbageTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ func (t *ByronTransaction) Metadata() *cbor.LazyValue {
return t.Attributes
}

func (t *ByronTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t *ByronTransaction) IsValid() bool {
return true
}
Expand Down
1 change: 1 addition & 0 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Transaction interface {
Type() int
Cbor() []byte
Hash() Blake2b256
LeiosHash() Blake2b256
Metadata() *cbor.LazyValue
IsValid() bool
Consumed() []TransactionInput
Expand Down
9 changes: 9 additions & 0 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ func (b *ConwayTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
type ConwayTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body ConwayTransactionBody
WitnessSet ConwayTransactionWitnessSet
TxIsValid bool
Expand Down Expand Up @@ -543,6 +544,14 @@ func (t ConwayTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t ConwayTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t ConwayTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
17 changes: 16 additions & 1 deletion ledger/leios/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@
package leios

import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/conway"
)

type (
LeiosTransaction = conway.ConwayTransaction
LeiosTransactionBody = conway.ConwayTransactionBody
LeiosTransactionWitnessSet = conway.ConwayTransactionWitnessSet
)

type LeiosTransaction struct {
conway.ConwayTransaction
hash *common.Blake2b256
Body LeiosTransactionBody
WitnessSet LeiosTransactionWitnessSet
}

func (t *LeiosTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}
9 changes: 9 additions & 0 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (b *MaryTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
type MaryTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body MaryTransactionBody
WitnessSet shelley.ShelleyTransactionWitnessSet
TxMetadata *cbor.LazyValue
Expand Down Expand Up @@ -272,6 +273,14 @@ func (t MaryTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t MaryTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t MaryTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func (w ShelleyTransactionWitnessSet) Redeemers() common.TransactionWitnessRedee
type ShelleyTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash *common.Blake2b256
Body ShelleyTransactionBody
WitnessSet ShelleyTransactionWitnessSet
TxMetadata *cbor.LazyValue
Expand Down Expand Up @@ -565,6 +566,14 @@ func (t ShelleyTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t ShelleyTransaction) LeiosHash() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
}
return *t.hash
}

func (t ShelleyTransaction) Inputs() []common.TransactionInput {
return t.Body.Inputs()
}
Expand Down
7 changes: 7 additions & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewTransactionFromCbor(txType uint, data []byte) (Transaction, error) {
return NewBabbageTransactionFromCbor(data)
case TxTypeConway:
return NewConwayTransactionFromCbor(data)
case TxTypeLeios:
return NewLeiosTransactionFromCbor(data)
}
return nil, fmt.Errorf("unknown transaction type: %d", txType)
}
Expand All @@ -69,6 +71,8 @@ func NewTransactionBodyFromCbor(
return NewBabbageTransactionBodyFromCbor(data)
case TxTypeConway:
return NewConwayTransactionBodyFromCbor(data)
case TxTypeLeios:
return NewLeiosTransactionBodyFromCbor(data)
}
return nil, fmt.Errorf("unknown transaction type: %d", txType)
}
Expand Down Expand Up @@ -116,5 +120,8 @@ func DetermineTransactionType(data []byte) (uint, error) {
if _, err := NewConwayTransactionFromCbor(data); err == nil {
return TxTypeConway, nil
}
if _, err := NewLeiosTransactionFromCbor(data); err == nil {
return TxTypeLeios, nil
}
return 0, errors.New("unknown transaction type")
}
Loading