Json info (#115)

* make info return a json with an spr

* add an `exec` target to the makefile
This commit is contained in:
Dmitriy Ryajov 2022-06-14 17:34:56 -06:00 committed by GitHub
parent 28ebb16767
commit cf4a0a393e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -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 $@

View File

@ -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"

View File

@ -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,