Skip to content

Commit 3436922

Browse files
authored
feat: function to get block/tx numeric type (#711)
Fixes #205
1 parent 65c63c6 commit 3436922

File tree

9 files changed

+62
-0
lines changed

9 files changed

+62
-0
lines changed

ledger/allegra/allegra.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func (b *AllegraBlock) UnmarshalCBOR(cborData []byte) error {
6060
return b.UnmarshalCbor(cborData, b)
6161
}
6262

63+
func (AllegraBlock) Type() int {
64+
return BlockTypeAllegra
65+
}
66+
6367
func (b *AllegraBlock) Hash() string {
6468
return b.Header.Hash()
6569
}
@@ -160,6 +164,10 @@ type AllegraTransaction struct {
160164
TxMetadata *cbor.LazyValue
161165
}
162166

167+
func (AllegraTransaction) Type() int {
168+
return TxTypeAllegra
169+
}
170+
163171
func (t AllegraTransaction) Hash() string {
164172
return t.Body.Hash()
165173
}

ledger/alonzo/alonzo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (b *AlonzoBlock) UnmarshalCBOR(cborData []byte) error {
6363
return b.UnmarshalCbor(cborData, b)
6464
}
6565

66+
func (AlonzoBlock) Type() int {
67+
return BlockTypeAlonzo
68+
}
69+
6670
func (b *AlonzoBlock) Hash() string {
6771
return b.Header.Hash()
6872
}
@@ -317,6 +321,10 @@ type AlonzoTransaction struct {
317321
TxMetadata *cbor.LazyValue
318322
}
319323

324+
func (AlonzoTransaction) Type() int {
325+
return TxTypeAlonzo
326+
}
327+
320328
func (t AlonzoTransaction) Hash() string {
321329
return t.Body.Hash()
322330
}

ledger/babbage/babbage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (b *BabbageBlock) UnmarshalCBOR(cborData []byte) error {
6464
return b.UnmarshalCbor(cborData, b)
6565
}
6666

67+
func (BabbageBlock) Type() int {
68+
return BlockTypeBabbage
69+
}
70+
6771
func (b *BabbageBlock) Hash() string {
6872
return b.Header.Hash()
6973
}
@@ -491,6 +495,10 @@ type BabbageTransaction struct {
491495
TxMetadata *cbor.LazyValue
492496
}
493497

498+
func (BabbageTransaction) Type() int {
499+
return TxTypeBabbage
500+
}
501+
494502
func (t BabbageTransaction) Hash() string {
495503
return t.Body.Hash()
496504
}

ledger/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
type Block interface {
2424
BlockHeader
25+
Type() int
2526
Transactions() []Transaction
2627
Utxorpc() *utxorpc.Block
2728
}

ledger/byron/byron.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func (t *ByronTransaction) UnmarshalCBOR(data []byte) error {
151151
return t.UnmarshalCbor(data, t)
152152
}
153153

154+
func (ByronTransaction) Type() int {
155+
return TxTypeByron
156+
}
157+
154158
func (t *ByronTransaction) Hash() string {
155159
if t.hash == "" {
156160
tmpHash := common.Blake2b256Hash(t.Cbor())
@@ -516,6 +520,10 @@ func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error {
516520
return b.UnmarshalCbor(cborData, b)
517521
}
518522

523+
func (ByronMainBlock) Type() int {
524+
return BlockTypeByronMain
525+
}
526+
519527
func (b *ByronMainBlock) Hash() string {
520528
return b.Header.Hash()
521529
}
@@ -566,6 +574,10 @@ func (b *ByronEpochBoundaryBlock) UnmarshalCBOR(cborData []byte) error {
566574
return b.UnmarshalCbor(cborData, b)
567575
}
568576

577+
func (ByronEpochBoundaryBlock) Type() int {
578+
return BlockTypeByronEbb
579+
}
580+
569581
func (b *ByronEpochBoundaryBlock) Hash() string {
570582
return b.Header.Hash()
571583
}

ledger/common/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
type Transaction interface {
2424
TransactionBody
25+
Type() int
2526
Metadata() *cbor.LazyValue
2627
IsValid() bool
2728
Consumed() []TransactionInput

ledger/conway/conway.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (b *ConwayBlock) UnmarshalCBOR(cborData []byte) error {
6363
return b.UnmarshalCbor(cborData, b)
6464
}
6565

66+
func (ConwayBlock) Type() int {
67+
return BlockTypeConway
68+
}
69+
6670
func (b *ConwayBlock) Hash() string {
6771
return b.Header.Hash()
6872
}
@@ -307,6 +311,10 @@ type ConwayTransaction struct {
307311
TxMetadata *cbor.LazyValue
308312
}
309313

314+
func (ConwayTransaction) Type() int {
315+
return TxTypeConway
316+
}
317+
310318
func (t ConwayTransaction) Hash() string {
311319
return t.Body.Hash()
312320
}

ledger/mary/mary.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (b *MaryBlock) UnmarshalCBOR(cborData []byte) error {
6262
return b.UnmarshalCbor(cborData, b)
6363
}
6464

65+
func (MaryBlock) Type() int {
66+
return BlockTypeMary
67+
}
68+
6569
func (b *MaryBlock) Hash() string {
6670
return b.Header.Hash()
6771
}
@@ -172,6 +176,10 @@ type MaryTransaction struct {
172176
TxMetadata *cbor.LazyValue
173177
}
174178

179+
func (MaryTransaction) Type() int {
180+
return TxTypeMary
181+
}
182+
175183
type MaryTransactionWitnessSet struct {
176184
shelley.ShelleyTransactionWitnessSet
177185
Script []interface{} `cbor:"4,keyasint,omitempty"`

ledger/shelley/shelley.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (b *ShelleyBlock) UnmarshalCBOR(cborData []byte) error {
5959
return b.UnmarshalCbor(cborData, b)
6060
}
6161

62+
func (ShelleyBlock) Type() int {
63+
return BlockTypeShelley
64+
}
65+
6266
func (b *ShelleyBlock) Hash() string {
6367
return b.Header.Hash()
6468
}
@@ -436,6 +440,10 @@ type ShelleyTransaction struct {
436440
TxMetadata *cbor.LazyValue
437441
}
438442

443+
func (ShelleyTransaction) Type() int {
444+
return TxTypeShelley
445+
}
446+
439447
func (t ShelleyTransaction) Hash() string {
440448
return t.Body.Hash()
441449
}

0 commit comments

Comments
 (0)