use `withState` in `jsonResponseState` (#4169)
The generic sandwich preventing `forks.withState` from working in REST serialization is no longer applicable. Update to use `withState`.
This commit is contained in:
parent
cd626cf645
commit
8b11778e14
|
@ -267,10 +267,10 @@ proc jsonResponseBlock*(t: typedesc[RestApiResponse],
|
||||||
headers = headers)
|
headers = headers)
|
||||||
|
|
||||||
proc jsonResponseState*(t: typedesc[RestApiResponse],
|
proc jsonResponseState*(t: typedesc[RestApiResponse],
|
||||||
forkedState: ForkedHashedBeaconState,
|
data: ForkedHashedBeaconState,
|
||||||
execOpt: Option[bool]): RestApiResponse =
|
execOpt: Option[bool]): RestApiResponse =
|
||||||
let
|
let
|
||||||
headers = [("eth-consensus-version", forkedState.kind.toString())]
|
headers = [("eth-consensus-version", data.kind.toString())]
|
||||||
res =
|
res =
|
||||||
block:
|
block:
|
||||||
var default: seq[byte]
|
var default: seq[byte]
|
||||||
|
@ -278,18 +278,11 @@ proc jsonResponseState*(t: typedesc[RestApiResponse],
|
||||||
var stream = memoryOutput()
|
var stream = memoryOutput()
|
||||||
var writer = JsonWriter[RestJson].init(stream)
|
var writer = JsonWriter[RestJson].init(stream)
|
||||||
writer.beginRecord()
|
writer.beginRecord()
|
||||||
writer.writeField("version", forkedState.kind.toString())
|
writer.writeField("version", data.kind.toString())
|
||||||
if execOpt.isSome():
|
if execOpt.isSome():
|
||||||
writer.writeField("execution_optimistic", execOpt.get())
|
writer.writeField("execution_optimistic", execOpt.get())
|
||||||
# TODO (cheatfate): Unable to use `forks.withState()` template here
|
withState(data):
|
||||||
# because of compiler issues and some kind of generic sandwich.
|
writer.writeField("data", forkyState.data)
|
||||||
case forkedState.kind
|
|
||||||
of BeaconStateFork.Bellatrix:
|
|
||||||
writer.writeField("data", forkedState.bellatrixData.data)
|
|
||||||
of BeaconStateFork.Altair:
|
|
||||||
writer.writeField("data", forkedState.altairData.data)
|
|
||||||
of BeaconStateFork.Phase0:
|
|
||||||
writer.writeField("data", forkedState.phase0Data.data)
|
|
||||||
writer.endRecord()
|
writer.endRecord()
|
||||||
stream.getOutput(seq[byte])
|
stream.getOutput(seq[byte])
|
||||||
except SerializationError:
|
except SerializationError:
|
||||||
|
|
Loading…
Reference in New Issue