Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: function to determine block type #449

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading