Support more content-types when specifying the Graffiti string
This commit is contained in:
parent
0e2b4e39fa
commit
2a12d1c49f
|
@ -73,7 +73,7 @@ const
|
|||
"Missing `randao_reveal` value"
|
||||
InvalidRandaoRevealValue* =
|
||||
"Invalid randao reveal value"
|
||||
InvalidGraffitiBytesValye* =
|
||||
InvalidGraffitiBytesValue* =
|
||||
"Invalid graffiti bytes value"
|
||||
InvalidEpochValueError* =
|
||||
"Invalid epoch value"
|
||||
|
|
|
@ -165,12 +165,33 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return RestApiResponse.jsonResponse((peers: res))
|
||||
|
||||
router.api(MethodPost, "/nimbus/v1/graffiti") do (
|
||||
value: Option[GraffitiBytes]) -> RestApiResponse:
|
||||
if value.isSome() and value.get().isOk():
|
||||
node.graffitiBytes = value.get().get()
|
||||
contentBody: Option[ContentBody]) -> RestApiResponse:
|
||||
if contentBody.isNone:
|
||||
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
||||
|
||||
template setGraffitiAux(node: BeaconNode, graffitiStr: string): RestApiResponse =
|
||||
node.graffitiBytes = try:
|
||||
GraffitiBytes.init(graffitiStr)
|
||||
except CatchableError as err:
|
||||
return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValue,
|
||||
err.msg)
|
||||
RestApiResponse.jsonResponse((result: true))
|
||||
|
||||
case contentBody.get.contentType
|
||||
of "application/json":
|
||||
let graffitiBytes = decodeBody(GraffitiBytes, contentBody.get)
|
||||
if graffitiBytes.isErr:
|
||||
return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValue,
|
||||
$graffitiBytes.error)
|
||||
node.graffitiBytes = graffitiBytes.get
|
||||
return RestApiResponse.jsonResponse((result: true))
|
||||
of "text/plain":
|
||||
return node.setGraffitiAux contentBody.get.strData
|
||||
of "application/x-www-form-urlencoded":
|
||||
return node.setGraffitiAux decodeUrl(contentBody.get.strData)
|
||||
else:
|
||||
return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValye)
|
||||
return RestApiResponse.jsonError(Http400, "Unsupported content type: " &
|
||||
$contentBody.get.contentType)
|
||||
|
||||
router.api(MethodGet, "/nimbus/v1/graffiti") do (
|
||||
) -> RestApiResponse:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import std/[options, macros],
|
||||
presto,
|
||||
stew/byteutils, presto,
|
||||
nimcrypto/utils as ncrutils,
|
||||
../spec/[forks],
|
||||
../spec/eth2_apis/[rest_types, eth2_rest_serialization],
|
||||
|
@ -191,6 +191,10 @@ template withStateForBlockSlot*(nodeParam: BeaconNode,
|
|||
withStateVars(stateToAdvance[]):
|
||||
body
|
||||
|
||||
template strData*(body: ContentBody): string =
|
||||
bind fromBytes
|
||||
string.fromBytes(body.data)
|
||||
|
||||
proc toValidatorIndex*(value: RestValidatorIndex): Result[ValidatorIndex,
|
||||
ValidatorIndexError] =
|
||||
when sizeof(ValidatorIndex) == 4:
|
||||
|
|
|
@ -313,7 +313,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let res = graffiti.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidGraffitiBytesValye,
|
||||
InvalidGraffitiBytesValue,
|
||||
$res.error())
|
||||
res.get()
|
||||
let qhead =
|
||||
|
@ -371,7 +371,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let res = graffiti.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidGraffitiBytesValye,
|
||||
InvalidGraffitiBytesValue,
|
||||
$res.error())
|
||||
res.get()
|
||||
let qhead =
|
||||
|
|
|
@ -17,7 +17,7 @@ const
|
|||
versionMinor* = 5
|
||||
versionBuild* = 5
|
||||
|
||||
versionBlob* = "stateofus" # Single word - ends up in the default graffitti
|
||||
versionBlob* = "stateofus" # Single word - ends up in the default graffiti
|
||||
|
||||
gitRevision* = strip(staticExec("git rev-parse --short HEAD"))[0..5]
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Environment="WEB3_URL=wss://provider/"
|
||||
#
|
||||
# To completely override the start command (to add custom parameters such as
|
||||
# graffitti), override the `ExecStart` value instead:
|
||||
# graffiti), override the `ExecStart` value instead:
|
||||
#
|
||||
# [Service]
|
||||
# ExecStart=/usr/bin/nimbus_beacon_node --network=${NETWORK} \
|
||||
|
|
Loading…
Reference in New Issue