Skip to content

Commit

Permalink
feat: function to determine block type
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Dec 2, 2023
1 parent cf1bd95 commit 0362ac5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ func NewBlockHeaderFromCbor(blockType uint, data []byte) (BlockHeader, error) {
return nil, fmt.Errorf("unknown node-to-node block type: %d", blockType)
}

func DetermineBlockType(data []byte) (uint, error) {
if _, err := NewByronEpochBoundaryBlockFromCbor(data); err == nil {
return BlockTypeByronEbb, nil
}
if _, err := NewByronMainBlockFromCbor(data); err == nil {
return BlockTypeByronMain, nil
}
if _, err := NewShelleyBlockFromCbor(data); err == nil {
return BlockTypeShelley, nil
}
if _, err := NewAllegraBlockFromCbor(data); err == nil {
return BlockTypeAllegra, nil
}
if _, err := NewMaryBlockFromCbor(data); err == nil {
return BlockTypeMary, nil
}
if _, err := NewAlonzoBlockFromCbor(data); err == nil {
return BlockTypeAlonzo, nil
}
if _, err := NewBabbageBlockFromCbor(data); err == nil {
return BlockTypeBabbage, nil
}
if _, err := NewConwayBlockFromCbor(data); err == nil {
return BlockTypeConway, nil
}
return 0, fmt.Errorf("unknown block type")
}

func generateBlockHeaderHash(data []byte, prefix []byte) string {
// We can ignore the error return here because our fixed size/key arguments will
// never trigger an error
Expand Down

0 comments on commit 0362ac5

Please sign in to comment.