From cf4a0a393eebb2258aba18e23355b43620a6d772 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 14 Jun 2022 17:34:56 -0600 Subject: [PATCH] Json info (#115) * make info return a json with an spr * add an `exec` target to the makefile --- Makefile | 5 +++++ codex.nimble | 2 +- codex/rest/api.nim | 15 ++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 30adaf84..e72d8e66 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,11 @@ testAll: | build deps echo -e $(BUILD_MSG) "build/testCodex" "build/testContracts" && \ $(ENV_SCRIPT) nim testAll $(NIM_PARAMS) codex.nims +# Builds the codex binary +exec: | build deps + echo -e $(BUILD_MSG) "build/$@" && \ + $(ENV_SCRIPT) nim codex codex.nims + # symlink codex.nims: ln -s codex.nimble $@ diff --git a/codex.nimble b/codex.nimble index e3348d80..572c5b5b 100644 --- a/codex.nimble +++ b/codex.nimble @@ -46,7 +46,7 @@ proc test(name: string, srcDir = "tests/", lang = "c") = exec "build/" & name task codex, "build codex binary": - buildBinary "codex" + buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE" task testCodex, "Build & run Codex tests": test "testCodex" diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 5e0df30d..eb3f8ddd 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -25,6 +25,7 @@ import pkg/stew/byteutils import pkg/confutils import pkg/libp2p/routing_record +import pkg/libp2pdht/discv5/spr as spr import ../node import ../blocktype @@ -260,14 +261,14 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = ## Print rudimentary node information ## - var addrs: string - for a in node.switch.peerInfo.addrs: - addrs &= "- " & $a & "\n" + let json = %*{ + "id": $node.switch.peerInfo.peerId, + "addrs": node.switch.peerInfo.addrs.mapIt( $it ), + "repo": $conf.dataDir, + "spr": node.switch.peerInfo.signedPeerRecord.toURI + } - return RestApiResponse.response( - "Id: " & $node.switch.peerInfo.peerId & - "\nAddrs: \n" & addrs & - "\nRoot Dir: " & $conf.dataDir) + return RestApiResponse.response($json) router.api( MethodGet,