diff --git a/eth-rpc/server/servertypes.nim b/eth-rpc/server/servertypes.nim index bf027d3..0f67de5 100644 --- a/eth-rpc/server/servertypes.nim +++ b/eth-rpc/server/servertypes.nim @@ -44,7 +44,7 @@ proc hasReturnType(params: NimNode): bool = if params != nil and params.len > 0 and params[0] != nil and params[0].kind != nnkEmpty: result = true -macro rpc*(server: var RpcServer, path: string, body: untyped): untyped = +macro rpc*(server: RpcServer, path: string, body: untyped): untyped = result = newStmtList() let parameters = body.findChild(it.kind == nnkFormalParams) @@ -71,18 +71,18 @@ macro rpc*(server: var RpcServer, path: string, body: untyped): untyped = if returnType == ident"JsonNode": # `JsonNode` results don't need conversion result.add( quote do: - proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = + proc `procName`(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = `res` = await `doMain`(`paramsIdent`) ) else: result.add(quote do: - proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = + proc `procName`(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = `res` = %await `doMain`(`paramsIdent`) ) else: # no return types, inline contents result.add(quote do: - proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = + proc `procName`(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = `setup` `procBody` ) diff --git a/tests/testserverclient.nim b/tests/testserverclient.nim index b7af85b..407c248 100644 --- a/tests/testserverclient.nim +++ b/tests/testserverclient.nim @@ -5,11 +5,14 @@ var srv = newRpcServer() srv.address = "localhost" srv.port = Port(8545) -srv.rpc("myProc") do(input: string, data: array[0..3, int]): - result = %("Hello " & input & " data: " & $data) +proc makeProc(server: RpcServer) = + server.rpc("myProc") do(input: string, data: array[0..3, int]): + result = %("Hello " & input & " data: " & $data) asyncCheck srv.serve +srv.makeProc + suite "Server/Client RPC": proc main {.async.} = var client = newRpcClient()