Merge pull request #14 from status-im/RemoveExportOnRpcProcs

Remove export on rpc procs
This commit is contained in:
coffeepots 2018-06-04 15:44:43 +01:00 committed by GitHub
commit f8d0050dff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -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`
)

View File

@ -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()