Skip to content

Commit b9654b1

Browse files
committed
feat: block function to get header
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 79d22a1 commit b9654b1

File tree

10 files changed

+99
-66
lines changed

10 files changed

+99
-66
lines changed

cmd/gouroboros/chainsync.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,15 @@ func chainSyncRollForwardHandler(
279279
byronEbbBlock := block.(*ledger.ByronEpochBoundaryBlock)
280280
fmt.Printf(
281281
"era = Byron (EBB), epoch = %d, slot = %d, id = %s\n",
282-
byronEbbBlock.Header.ConsensusData.Epoch,
282+
byronEbbBlock.BlockHeader.ConsensusData.Epoch,
283283
byronEbbBlock.SlotNumber(),
284284
byronEbbBlock.Hash(),
285285
)
286286
case ledger.BlockTypeByronMain:
287287
byronBlock := block.(*ledger.ByronMainBlock)
288288
fmt.Printf(
289289
"era = Byron, epoch = %d, slot = %d, id = %s\n",
290-
byronBlock.Header.ConsensusData.SlotId.Epoch,
290+
byronBlock.BlockHeader.ConsensusData.SlotId.Epoch,
291291
byronBlock.SlotNumber(),
292292
byronBlock.Hash(),
293293
)
@@ -313,9 +313,9 @@ func blockFetchBlockHandler(
313313
) error {
314314
switch block := blockData.(type) {
315315
case *ledger.ByronEpochBoundaryBlock:
316-
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
316+
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
317317
case *ledger.ByronMainBlock:
318-
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.Hash())
318+
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.Hash())
319319
case ledger.Block:
320320
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", block.Era().Name, block.SlotNumber(), block.BlockNumber(), block.Hash())
321321
}

ledger/allegra/allegra.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func init() {
5050
type AllegraBlock struct {
5151
cbor.StructAsArray
5252
cbor.DecodeStoreCbor
53-
Header *AllegraBlockHeader
53+
BlockHeader *AllegraBlockHeader
5454
TransactionBodies []AllegraTransactionBody
5555
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
5656
TransactionMetadataSet map[uint]*cbor.LazyValue
@@ -65,27 +65,31 @@ func (AllegraBlock) Type() int {
6565
}
6666

6767
func (b *AllegraBlock) Hash() string {
68-
return b.Header.Hash()
68+
return b.BlockHeader.Hash()
69+
}
70+
71+
func (b *AllegraBlock) Header() common.BlockHeader {
72+
return b.BlockHeader
6973
}
7074

7175
func (b *AllegraBlock) PrevHash() string {
72-
return b.Header.PrevHash()
76+
return b.BlockHeader.PrevHash()
7377
}
7478

7579
func (b *AllegraBlock) BlockNumber() uint64 {
76-
return b.Header.BlockNumber()
80+
return b.BlockHeader.BlockNumber()
7781
}
7882

7983
func (b *AllegraBlock) SlotNumber() uint64 {
80-
return b.Header.SlotNumber()
84+
return b.BlockHeader.SlotNumber()
8185
}
8286

8387
func (b *AllegraBlock) IssuerVkey() common.IssuerVkey {
84-
return b.Header.IssuerVkey()
88+
return b.BlockHeader.IssuerVkey()
8589
}
8690

8791
func (b *AllegraBlock) BlockBodySize() uint64 {
88-
return b.Header.BlockBodySize()
92+
return b.BlockHeader.BlockBodySize()
8993
}
9094

9195
func (b *AllegraBlock) Era() common.Era {

ledger/alonzo/alonzo.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func init() {
5252
type AlonzoBlock struct {
5353
cbor.StructAsArray
5454
cbor.DecodeStoreCbor
55-
Header *AlonzoBlockHeader
55+
BlockHeader *AlonzoBlockHeader
5656
TransactionBodies []AlonzoTransactionBody
5757
TransactionWitnessSets []AlonzoTransactionWitnessSet
5858
TransactionMetadataSet map[uint]*cbor.LazyValue
@@ -68,27 +68,31 @@ func (AlonzoBlock) Type() int {
6868
}
6969

7070
func (b *AlonzoBlock) Hash() string {
71-
return b.Header.Hash()
71+
return b.BlockHeader.Hash()
72+
}
73+
74+
func (b *AlonzoBlock) Header() common.BlockHeader {
75+
return b.BlockHeader
7276
}
7377

7478
func (b *AlonzoBlock) PrevHash() string {
75-
return b.Header.PrevHash()
79+
return b.BlockHeader.PrevHash()
7680
}
7781

7882
func (b *AlonzoBlock) BlockNumber() uint64 {
79-
return b.Header.BlockNumber()
83+
return b.BlockHeader.BlockNumber()
8084
}
8185

8286
func (b *AlonzoBlock) SlotNumber() uint64 {
83-
return b.Header.SlotNumber()
87+
return b.BlockHeader.SlotNumber()
8488
}
8589

8690
func (b *AlonzoBlock) IssuerVkey() common.IssuerVkey {
87-
return b.Header.IssuerVkey()
91+
return b.BlockHeader.IssuerVkey()
8892
}
8993

9094
func (b *AlonzoBlock) BlockBodySize() uint64 {
91-
return b.Header.BlockBodySize()
95+
return b.BlockHeader.BlockBodySize()
9296
}
9397

9498
func (b *AlonzoBlock) Era() common.Era {

ledger/babbage/babbage.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353
type BabbageBlock struct {
5454
cbor.StructAsArray
5555
cbor.DecodeStoreCbor
56-
Header *BabbageBlockHeader
56+
BlockHeader *BabbageBlockHeader
5757
TransactionBodies []BabbageTransactionBody
5858
TransactionWitnessSets []BabbageTransactionWitnessSet
5959
TransactionMetadataSet map[uint]*cbor.LazyValue
@@ -69,27 +69,31 @@ func (BabbageBlock) Type() int {
6969
}
7070

7171
func (b *BabbageBlock) Hash() string {
72-
return b.Header.Hash()
72+
return b.BlockHeader.Hash()
73+
}
74+
75+
func (b *BabbageBlock) Header() common.BlockHeader {
76+
return b.BlockHeader
7377
}
7478

7579
func (b *BabbageBlock) PrevHash() string {
76-
return b.Header.PrevHash()
80+
return b.BlockHeader.PrevHash()
7781
}
7882

7983
func (b *BabbageBlock) BlockNumber() uint64 {
80-
return b.Header.BlockNumber()
84+
return b.BlockHeader.BlockNumber()
8185
}
8286

8387
func (b *BabbageBlock) SlotNumber() uint64 {
84-
return b.Header.SlotNumber()
88+
return b.BlockHeader.SlotNumber()
8589
}
8690

8791
func (b *BabbageBlock) IssuerVkey() common.IssuerVkey {
88-
return b.Header.IssuerVkey()
92+
return b.BlockHeader.IssuerVkey()
8993
}
9094

9195
func (b *BabbageBlock) BlockBodySize() uint64 {
92-
return b.Header.BlockBodySize()
96+
return b.BlockHeader.BlockBodySize()
9397
}
9498

9599
func (b *BabbageBlock) Era() common.Era {

ledger/byron/byron.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ func (h *ByronEpochBoundaryBlockHeader) Era() common.Era {
559559
type ByronMainBlock struct {
560560
cbor.StructAsArray
561561
cbor.DecodeStoreCbor
562-
Header *ByronMainBlockHeader
563-
Body ByronMainBlockBody
564-
Extra []interface{}
562+
BlockHeader *ByronMainBlockHeader
563+
Body ByronMainBlockBody
564+
Extra []interface{}
565565
}
566566

567567
func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error {
@@ -574,31 +574,35 @@ func (ByronMainBlock) Type() int {
574574
}
575575

576576
func (b *ByronMainBlock) Hash() string {
577-
return b.Header.Hash()
577+
return b.BlockHeader.Hash()
578+
}
579+
580+
func (b *ByronMainBlock) Header() common.BlockHeader {
581+
return b.BlockHeader
578582
}
579583

580584
func (b *ByronMainBlock) PrevHash() string {
581-
return b.Header.PrevHash()
585+
return b.BlockHeader.PrevHash()
582586
}
583587

584588
func (b *ByronMainBlock) BlockNumber() uint64 {
585-
return b.Header.BlockNumber()
589+
return b.BlockHeader.BlockNumber()
586590
}
587591

588592
func (b *ByronMainBlock) SlotNumber() uint64 {
589-
return b.Header.SlotNumber()
593+
return b.BlockHeader.SlotNumber()
590594
}
591595

592596
func (b *ByronMainBlock) IssuerVkey() common.IssuerVkey {
593-
return b.Header.IssuerVkey()
597+
return b.BlockHeader.IssuerVkey()
594598
}
595599

596600
func (b *ByronMainBlock) BlockBodySize() uint64 {
597601
return uint64(len(b.Body.Cbor()))
598602
}
599603

600604
func (b *ByronMainBlock) Era() common.Era {
601-
return b.Header.Era()
605+
return b.BlockHeader.Era()
602606
}
603607

604608
func (b *ByronMainBlock) Transactions() []common.Transaction {
@@ -617,9 +621,9 @@ func (b *ByronMainBlock) Utxorpc() *utxorpc.Block {
617621
type ByronEpochBoundaryBlock struct {
618622
cbor.StructAsArray
619623
cbor.DecodeStoreCbor
620-
Header *ByronEpochBoundaryBlockHeader
621-
Body []common.Blake2b224
622-
Extra []interface{}
624+
BlockHeader *ByronEpochBoundaryBlockHeader
625+
Body []common.Blake2b224
626+
Extra []interface{}
623627
}
624628

625629
func (b *ByronEpochBoundaryBlock) UnmarshalCBOR(cborData []byte) error {
@@ -632,23 +636,27 @@ func (ByronEpochBoundaryBlock) Type() int {
632636
}
633637

634638
func (b *ByronEpochBoundaryBlock) Hash() string {
635-
return b.Header.Hash()
639+
return b.BlockHeader.Hash()
640+
}
641+
642+
func (b *ByronEpochBoundaryBlock) Header() common.BlockHeader {
643+
return b.BlockHeader
636644
}
637645

638646
func (b *ByronEpochBoundaryBlock) PrevHash() string {
639-
return b.Header.PrevHash()
647+
return b.BlockHeader.PrevHash()
640648
}
641649

642650
func (b *ByronEpochBoundaryBlock) BlockNumber() uint64 {
643-
return b.Header.BlockNumber()
651+
return b.BlockHeader.BlockNumber()
644652
}
645653

646654
func (b *ByronEpochBoundaryBlock) SlotNumber() uint64 {
647-
return b.Header.SlotNumber()
655+
return b.BlockHeader.SlotNumber()
648656
}
649657

650658
func (b *ByronEpochBoundaryBlock) IssuerVkey() common.IssuerVkey {
651-
return b.Header.IssuerVkey()
659+
return b.BlockHeader.IssuerVkey()
652660
}
653661

654662
func (b *ByronEpochBoundaryBlock) BlockBodySize() uint64 {
@@ -657,7 +665,7 @@ func (b *ByronEpochBoundaryBlock) BlockBodySize() uint64 {
657665
}
658666

659667
func (b *ByronEpochBoundaryBlock) Era() common.Era {
660-
return b.Header.Era()
668+
return b.BlockHeader.Era()
661669
}
662670

663671
func (b *ByronEpochBoundaryBlock) Transactions() []common.Transaction {

ledger/common/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
44

55
type Block interface {
66
BlockHeader
7+
Header() BlockHeader
78
Type() int
89
Transactions() []Transaction
910
Utxorpc() *utxorpc.Block

ledger/conway/conway.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func init() {
5252
type ConwayBlock struct {
5353
cbor.StructAsArray
5454
cbor.DecodeStoreCbor
55-
Header *ConwayBlockHeader
55+
BlockHeader *ConwayBlockHeader
5656
TransactionBodies []ConwayTransactionBody
5757
TransactionWitnessSets []ConwayTransactionWitnessSet
5858
TransactionMetadataSet map[uint]*cbor.LazyValue
@@ -68,27 +68,31 @@ func (ConwayBlock) Type() int {
6868
}
6969

7070
func (b *ConwayBlock) Hash() string {
71-
return b.Header.Hash()
71+
return b.BlockHeader.Hash()
72+
}
73+
74+
func (b *ConwayBlock) Header() common.BlockHeader {
75+
return b.BlockHeader
7276
}
7377

7478
func (b *ConwayBlock) PrevHash() string {
75-
return b.Header.PrevHash()
79+
return b.BlockHeader.PrevHash()
7680
}
7781

7882
func (b *ConwayBlock) BlockNumber() uint64 {
79-
return b.Header.BlockNumber()
83+
return b.BlockHeader.BlockNumber()
8084
}
8185

8286
func (b *ConwayBlock) SlotNumber() uint64 {
83-
return b.Header.SlotNumber()
87+
return b.BlockHeader.SlotNumber()
8488
}
8589

8690
func (b *ConwayBlock) IssuerVkey() common.IssuerVkey {
87-
return b.Header.IssuerVkey()
91+
return b.BlockHeader.IssuerVkey()
8892
}
8993

9094
func (b *ConwayBlock) BlockBodySize() uint64 {
91-
return b.Header.BlockBodySize()
95+
return b.BlockHeader.BlockBodySize()
9296
}
9397

9498
func (b *ConwayBlock) Era() common.Era {

ledger/mary/mary.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func init() {
5252
type MaryBlock struct {
5353
cbor.StructAsArray
5454
cbor.DecodeStoreCbor
55-
Header *MaryBlockHeader
55+
BlockHeader *MaryBlockHeader
5656
TransactionBodies []MaryTransactionBody
5757
TransactionWitnessSets []MaryTransactionWitnessSet
5858
TransactionMetadataSet map[uint]*cbor.LazyValue
@@ -67,27 +67,31 @@ func (MaryBlock) Type() int {
6767
}
6868

6969
func (b *MaryBlock) Hash() string {
70-
return b.Header.Hash()
70+
return b.BlockHeader.Hash()
71+
}
72+
73+
func (b *MaryBlock) Header() common.BlockHeader {
74+
return b.BlockHeader
7175
}
7276

7377
func (b *MaryBlock) PrevHash() string {
74-
return b.Header.PrevHash()
78+
return b.BlockHeader.PrevHash()
7579
}
7680

7781
func (b *MaryBlock) BlockNumber() uint64 {
78-
return b.Header.BlockNumber()
82+
return b.BlockHeader.BlockNumber()
7983
}
8084

8185
func (b *MaryBlock) SlotNumber() uint64 {
82-
return b.Header.SlotNumber()
86+
return b.BlockHeader.SlotNumber()
8387
}
8488

8589
func (b *MaryBlock) IssuerVkey() common.IssuerVkey {
86-
return b.Header.IssuerVkey()
90+
return b.BlockHeader.IssuerVkey()
8791
}
8892

8993
func (b *MaryBlock) BlockBodySize() uint64 {
90-
return b.Header.BlockBodySize()
94+
return b.BlockHeader.BlockBodySize()
9195
}
9296

9397
func (b *MaryBlock) Era() common.Era {

0 commit comments

Comments
 (0)