Skip to content

Commit

Permalink
feat: function to get block/tx numeric type (#711)
Browse files Browse the repository at this point in the history
Fixes #205
  • Loading branch information
agaffney authored Sep 18, 2024
1 parent 65c63c6 commit 3436922
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (AllegraBlock) Type() int {
return BlockTypeAllegra
}

func (b *AllegraBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -160,6 +164,10 @@ type AllegraTransaction struct {
TxMetadata *cbor.LazyValue
}

func (AllegraTransaction) Type() int {
return TxTypeAllegra
}

func (t AllegraTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (b *AlonzoBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (AlonzoBlock) Type() int {
return BlockTypeAlonzo
}

func (b *AlonzoBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -317,6 +321,10 @@ type AlonzoTransaction struct {
TxMetadata *cbor.LazyValue
}

func (AlonzoTransaction) Type() int {
return TxTypeAlonzo
}

func (t AlonzoTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (b *BabbageBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (BabbageBlock) Type() int {
return BlockTypeBabbage
}

func (b *BabbageBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -491,6 +495,10 @@ type BabbageTransaction struct {
TxMetadata *cbor.LazyValue
}

func (BabbageTransaction) Type() int {
return TxTypeBabbage
}

func (t BabbageTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down
1 change: 1 addition & 0 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

type Block interface {
BlockHeader
Type() int
Transactions() []Transaction
Utxorpc() *utxorpc.Block
}
Expand Down
12 changes: 12 additions & 0 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (t *ByronTransaction) UnmarshalCBOR(data []byte) error {
return t.UnmarshalCbor(data, t)
}

func (ByronTransaction) Type() int {
return TxTypeByron
}

func (t *ByronTransaction) Hash() string {
if t.hash == "" {
tmpHash := common.Blake2b256Hash(t.Cbor())
Expand Down Expand Up @@ -516,6 +520,10 @@ func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (ByronMainBlock) Type() int {
return BlockTypeByronMain
}

func (b *ByronMainBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -566,6 +574,10 @@ func (b *ByronEpochBoundaryBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (ByronEpochBoundaryBlock) Type() int {
return BlockTypeByronEbb
}

func (b *ByronEpochBoundaryBlock) Hash() string {
return b.Header.Hash()
}
Expand Down
1 change: 1 addition & 0 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

type Transaction interface {
TransactionBody
Type() int
Metadata() *cbor.LazyValue
IsValid() bool
Consumed() []TransactionInput
Expand Down
8 changes: 8 additions & 0 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (b *ConwayBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (ConwayBlock) Type() int {
return BlockTypeConway
}

func (b *ConwayBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -307,6 +311,10 @@ type ConwayTransaction struct {
TxMetadata *cbor.LazyValue
}

func (ConwayTransaction) Type() int {
return TxTypeConway
}

func (t ConwayTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (b *MaryBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (MaryBlock) Type() int {
return BlockTypeMary
}

func (b *MaryBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -172,6 +176,10 @@ type MaryTransaction struct {
TxMetadata *cbor.LazyValue
}

func (MaryTransaction) Type() int {
return TxTypeMary
}

type MaryTransactionWitnessSet struct {
shelley.ShelleyTransactionWitnessSet
Script []interface{} `cbor:"4,keyasint,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (b *ShelleyBlock) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (ShelleyBlock) Type() int {
return BlockTypeShelley
}

func (b *ShelleyBlock) Hash() string {
return b.Header.Hash()
}
Expand Down Expand Up @@ -436,6 +440,10 @@ type ShelleyTransaction struct {
TxMetadata *cbor.LazyValue
}

func (ShelleyTransaction) Type() int {
return TxTypeShelley
}

func (t ShelleyTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down

0 comments on commit 3436922

Please sign in to comment.