From edf214bc4ff99e8444fd8766a8c5357935c9a90a Mon Sep 17 00:00:00 2001 From: coffeepots Date: Tue, 24 Apr 2018 13:41:59 +0100 Subject: [PATCH] `on` macro now fetches from params as array as per ethereum rpc standard --- eth-rpc/server/servertypes.nim | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/eth-rpc/server/servertypes.nim b/eth-rpc/server/servertypes.nim index c51b48a..edba4a6 100644 --- a/eth-rpc/server/servertypes.nim +++ b/eth-rpc/server/servertypes.nim @@ -1,4 +1,5 @@ import asyncdispatch, asyncnet, json, tables, macros, strutils +export asyncdispatch, asyncnet, json type RpcProc* = proc (params: JsonNode): Future[JsonNode] @@ -78,51 +79,65 @@ macro multiRemove(s: string, values: varargs[string]): untyped = macro on*(server: var RpcServer, path: string, body: untyped): untyped = var paramTemplates = newStmtList() - # process parameters of body into templates let parameters = body.findChild(it.kind == nnkFormalParams) if not parameters.isNil: - # marshall result to json + # process parameters of body into json fetch templates var resType = parameters[0] if resType.kind != nnkEmpty: # TODO: transform result type and/or return to json discard - # convert input parameters to json fetch templates + # for i in 1.. int: echo "hello2" s.on("the/path3"): echo "hello3" - assert s.procs.hasKey("the/path") - assert s.procs.hasKey("the/path2") - assert s.procs.hasKey("the/path3") + result = %1 + suite "Server types": + test "On macro registration": + check s.procs.hasKey("the/path") + check s.procs.hasKey("the/path2") + check s.procs.hasKey("the/path3")