use enum for ForkchoiceUpdatedStatus.status

This commit is contained in:
Dustin Brody 2022-01-13 18:47:16 +00:00
parent 980461c982
commit 0b5466f56e
2 changed files with 14 additions and 5 deletions

View File

@ -73,11 +73,22 @@ func getEnumStringTable(enumType: typedesc): Table[string, enumType] {.compileTi
res[$value] = value
res
proc fromJson*(n: JsonNode, argName: string, result: var PayloadExecutionStatus) {.inline.} =
proc fromJson*(
n: JsonNode, argName: string, result: var ForkchoiceUpdatedStatus) {.inline.} =
n.kind.expect(JString, argName)
const enumStrings = static: getEnumStringTable(type(result))
try:
enumStrings[n.getStr]
result = enumStrings[n.getStr]
except KeyError:
raise newException(
ValueError, "Parameter \"" & argName & "\" value invalid: " & n.getStr)
proc fromJson*(
n: JsonNode, argName: string, result: var PayloadExecutionStatus) {.inline.} =
n.kind.expect(JString, argName)
const enumStrings = static: getEnumStringTable(type(result))
try:
result = enumStrings[n.getStr]
except KeyError:
raise newException(
ValueError, "Parameter \"" & argName & "\" value invalid: " & n.getStr)

View File

@ -1,5 +1,3 @@
# https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.5/src/engine/specification.md
import
std/options,
ethtypes
@ -37,5 +35,5 @@ type
syncing = "SYNCING"
ForkchoiceUpdatedResponse* = object
status*: string
status*: ForkchoiceUpdatedStatus
payloadId*: Option[PayloadID]