Skip to content

Commit

Permalink
feat: expose previous block hash in block interface (#798)
Browse files Browse the repository at this point in the history
Fixes #797
  • Loading branch information
agaffney authored Nov 21, 2024
1 parent 5d64b2b commit 177d2d2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func (b *AllegraBlock) Hash() string {
return b.Header.Hash()
}

func (b *AllegraBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *AllegraBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (b *AlonzoBlock) Hash() string {
return b.Header.Hash()
}

func (b *AlonzoBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *AlonzoBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (b *BabbageBlock) Hash() string {
return b.Header.Hash()
}

func (b *BabbageBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *BabbageBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down Expand Up @@ -174,6 +178,10 @@ func (h *BabbageBlockHeader) Hash() string {
return h.hash
}

func (h *BabbageBlockHeader) PrevHash() string {
return h.Body.PrevHash.String()
}

func (h *BabbageBlockHeader) BlockNumber() uint64 {
return h.Body.BlockNumber
}
Expand Down
1 change: 1 addition & 0 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Block interface {

type BlockHeader interface {
Hash() string
PrevHash() string
BlockNumber() uint64
SlotNumber() uint64
IssuerVkey() IssuerVkey
Expand Down
16 changes: 16 additions & 0 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (h *ByronMainBlockHeader) Hash() string {
return h.hash
}

func (h *ByronMainBlockHeader) PrevHash() string {
return h.PrevBlock.String()
}

func (h *ByronMainBlockHeader) BlockNumber() uint64 {
// Byron blocks don't store the block number in the block
return 0
Expand Down Expand Up @@ -525,6 +529,10 @@ func (h *ByronEpochBoundaryBlockHeader) Hash() string {
return h.hash
}

func (h *ByronEpochBoundaryBlockHeader) PrevHash() string {
return h.PrevBlock.String()
}

func (h *ByronEpochBoundaryBlockHeader) BlockNumber() uint64 {
// Byron blocks don't store the block number in the block
return 0
Expand Down Expand Up @@ -569,6 +577,10 @@ func (b *ByronMainBlock) Hash() string {
return b.Header.Hash()
}

func (b *ByronMainBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *ByronMainBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down Expand Up @@ -623,6 +635,10 @@ func (b *ByronEpochBoundaryBlock) Hash() string {
return b.Header.Hash()
}

func (b *ByronEpochBoundaryBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *ByronEpochBoundaryBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (b *ConwayBlock) Hash() string {
return b.Header.Hash()
}

func (b *ConwayBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *ConwayBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (b *MaryBlock) Hash() string {
return b.Header.Hash()
}

func (b *MaryBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *MaryBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down
8 changes: 8 additions & 0 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (b *ShelleyBlock) Hash() string {
return b.Header.Hash()
}

func (b *ShelleyBlock) PrevHash() string {
return b.Header.PrevHash()
}

func (b *ShelleyBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
}
Expand Down Expand Up @@ -158,6 +162,10 @@ func (h *ShelleyBlockHeader) Hash() string {
return h.hash
}

func (h *ShelleyBlockHeader) PrevHash() string {
return h.Body.PrevHash.String()
}

func (h *ShelleyBlockHeader) BlockNumber() uint64 {
return h.Body.BlockNumber
}
Expand Down

0 comments on commit 177d2d2

Please sign in to comment.