Skip to content

Commit 177d2d2

Browse files
authored
feat: expose previous block hash in block interface (#798)
Fixes #797
1 parent 5d64b2b commit 177d2d2

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

ledger/allegra/allegra.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func (b *AllegraBlock) Hash() string {
6868
return b.Header.Hash()
6969
}
7070

71+
func (b *AllegraBlock) PrevHash() string {
72+
return b.Header.PrevHash()
73+
}
74+
7175
func (b *AllegraBlock) BlockNumber() uint64 {
7276
return b.Header.BlockNumber()
7377
}

ledger/alonzo/alonzo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (b *AlonzoBlock) Hash() string {
7171
return b.Header.Hash()
7272
}
7373

74+
func (b *AlonzoBlock) PrevHash() string {
75+
return b.Header.PrevHash()
76+
}
77+
7478
func (b *AlonzoBlock) BlockNumber() uint64 {
7579
return b.Header.BlockNumber()
7680
}

ledger/babbage/babbage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (b *BabbageBlock) Hash() string {
7272
return b.Header.Hash()
7373
}
7474

75+
func (b *BabbageBlock) PrevHash() string {
76+
return b.Header.PrevHash()
77+
}
78+
7579
func (b *BabbageBlock) BlockNumber() uint64 {
7680
return b.Header.BlockNumber()
7781
}
@@ -174,6 +178,10 @@ func (h *BabbageBlockHeader) Hash() string {
174178
return h.hash
175179
}
176180

181+
func (h *BabbageBlockHeader) PrevHash() string {
182+
return h.Body.PrevHash.String()
183+
}
184+
177185
func (h *BabbageBlockHeader) BlockNumber() uint64 {
178186
return h.Body.BlockNumber
179187
}

ledger/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Block interface {
2929

3030
type BlockHeader interface {
3131
Hash() string
32+
PrevHash() string
3233
BlockNumber() uint64
3334
SlotNumber() uint64
3435
IssuerVkey() IssuerVkey

ledger/byron/byron.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (h *ByronMainBlockHeader) Hash() string {
101101
return h.hash
102102
}
103103

104+
func (h *ByronMainBlockHeader) PrevHash() string {
105+
return h.PrevBlock.String()
106+
}
107+
104108
func (h *ByronMainBlockHeader) BlockNumber() uint64 {
105109
// Byron blocks don't store the block number in the block
106110
return 0
@@ -525,6 +529,10 @@ func (h *ByronEpochBoundaryBlockHeader) Hash() string {
525529
return h.hash
526530
}
527531

532+
func (h *ByronEpochBoundaryBlockHeader) PrevHash() string {
533+
return h.PrevBlock.String()
534+
}
535+
528536
func (h *ByronEpochBoundaryBlockHeader) BlockNumber() uint64 {
529537
// Byron blocks don't store the block number in the block
530538
return 0
@@ -569,6 +577,10 @@ func (b *ByronMainBlock) Hash() string {
569577
return b.Header.Hash()
570578
}
571579

580+
func (b *ByronMainBlock) PrevHash() string {
581+
return b.Header.PrevHash()
582+
}
583+
572584
func (b *ByronMainBlock) BlockNumber() uint64 {
573585
return b.Header.BlockNumber()
574586
}
@@ -623,6 +635,10 @@ func (b *ByronEpochBoundaryBlock) Hash() string {
623635
return b.Header.Hash()
624636
}
625637

638+
func (b *ByronEpochBoundaryBlock) PrevHash() string {
639+
return b.Header.PrevHash()
640+
}
641+
626642
func (b *ByronEpochBoundaryBlock) BlockNumber() uint64 {
627643
return b.Header.BlockNumber()
628644
}

ledger/conway/conway.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (b *ConwayBlock) Hash() string {
7171
return b.Header.Hash()
7272
}
7373

74+
func (b *ConwayBlock) PrevHash() string {
75+
return b.Header.PrevHash()
76+
}
77+
7478
func (b *ConwayBlock) BlockNumber() uint64 {
7579
return b.Header.BlockNumber()
7680
}

ledger/mary/mary.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func (b *MaryBlock) Hash() string {
7070
return b.Header.Hash()
7171
}
7272

73+
func (b *MaryBlock) PrevHash() string {
74+
return b.Header.PrevHash()
75+
}
76+
7377
func (b *MaryBlock) BlockNumber() uint64 {
7478
return b.Header.BlockNumber()
7579
}

ledger/shelley/shelley.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (b *ShelleyBlock) Hash() string {
6767
return b.Header.Hash()
6868
}
6969

70+
func (b *ShelleyBlock) PrevHash() string {
71+
return b.Header.PrevHash()
72+
}
73+
7074
func (b *ShelleyBlock) BlockNumber() uint64 {
7175
return b.Header.BlockNumber()
7276
}
@@ -158,6 +162,10 @@ func (h *ShelleyBlockHeader) Hash() string {
158162
return h.hash
159163
}
160164

165+
func (h *ShelleyBlockHeader) PrevHash() string {
166+
return h.Body.PrevHash.String()
167+
}
168+
161169
func (h *ShelleyBlockHeader) BlockNumber() uint64 {
162170
return h.Body.BlockNumber
163171
}

0 commit comments

Comments
 (0)