From 5266db34852ccc1bb1faa641d649042565125387 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 26 Mar 2021 19:57:02 +0200 Subject: [PATCH] Add a POST /api/nimbus/v1/graffiti API --- beacon_chain/beacon_node_common.nim | 2 +- beacon_chain/rpc/nimbus_rest_api.nim | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/beacon_chain/beacon_node_common.nim b/beacon_chain/beacon_node_common.nim index 34d110355..bc8ce300f 100644 --- a/beacon_chain/beacon_node_common.nim +++ b/beacon_chain/beacon_node_common.nim @@ -11,7 +11,7 @@ import std/osproc, # Nimble packages - chronos, json_rpc/servers/httpserver, presto + chronos, json_rpc/servers/httpserver, presto, # Local modules ./conf, ./beacon_clock, ./beacon_chain_db, diff --git a/beacon_chain/rpc/nimbus_rest_api.nim b/beacon_chain/rpc/nimbus_rest_api.nim index e2accf164..a3e0d27da 100644 --- a/beacon_chain/rpc/nimbus_rest_api.nim +++ b/beacon_chain/rpc/nimbus_rest_api.nim @@ -139,6 +139,19 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) = )) return RestApiResponse.jsonResponse((peers: res)) + router.api(MethodPost, "/api/nimbus/v1/graffiti") do ( + graffiti: Option[string]) -> RestApiResponse: + if graffiti.isSome and graffiti.get.isOk: + try: + node.graffitiBytes = GraffitiBytes.init(graffiti.get.get) + return RestApiResponse.jsonResponse((result: true)) + except CatchableError as err: + return RestApiResponse.jsonError( + Http400, "Invalid graffiti string", err.msg) + else: + return RestApiResponse.jsonError( + Http400, "You must specify a valid graffiti string") + router.api(MethodPost, "/api/nimbus/v1/chronicles/settings") do ( log_level: Option[string]) -> RestApiResponse: if log_level.isSome():