use `ConsensusFork.init` for parsing lowercase version (#6015)

Instead of maintaining string to `ConsensusFork` version inline,
use shared helper that also comes with static assertion checks
for completion.
This commit is contained in:
Etan Kissling 2024-03-02 23:45:20 +01:00 committed by GitHub
parent b4db011daf
commit 542854e743
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 12 deletions

View File

@ -1413,18 +1413,8 @@ template prepareForkedBlockReading(blockType: typedesc,
reader.raiseUnexpectedField("Multiple version fields found", reader.raiseUnexpectedField("Multiple version fields found",
blockType.name) blockType.name)
let vres = reader.readValue(string).toLowerAscii() let vres = reader.readValue(string).toLowerAscii()
case vres version = ConsensusFork.init(vres)
of "phase0": if version.isNone():
version = Opt.some(ConsensusFork.Phase0)
of "altair":
version = Opt.some(ConsensusFork.Altair)
of "bellatrix":
version = Opt.some(ConsensusFork.Bellatrix)
of "capella":
version = Opt.some(ConsensusFork.Capella)
of "deneb":
version = Opt.some(ConsensusFork.Deneb)
else:
reader.raiseUnexpectedValue("Incorrect version field value") reader.raiseUnexpectedValue("Incorrect version field value")
of "data": of "data":
when (blockType is ProduceBlockResponseV2) or when (blockType is ProduceBlockResponseV2) or