diff --git a/eth-rpc/server/ethprocs.nim b/eth-rpc/server/ethprocs.nim index 9e11d55..c06ea07 100644 --- a/eth-rpc/server/ethprocs.nim +++ b/eth-rpc/server/ethprocs.nim @@ -24,18 +24,18 @@ import servertypes, cryptoutils, json, stint, ../ethtypes.nim var server = sharedRpcServer() -server.on("web3_clientVersion") do() -> string: +server.rpc("web3_clientVersion") do() -> string: ## Returns the current client version. result = "Nimbus-RPC-Test" -server.on("web3_sha3") do(data: string) -> string: +server.rpc("web3_sha3") do(data: string) -> string: ## Returns Keccak-256 (not the standardized SHA3-256) of the given data. ## ## data: the data to convert into a SHA3 hash. ## Returns the SHA3 result of the given string. result = k256(data) -server.on("net_version") do() -> string: +server.rpc("net_version") do() -> string: ## Returns string of the current network id: ## "1": Ethereum Mainnet ## "2": Morden Testnet (deprecated) @@ -48,19 +48,19 @@ server.on("net_version") do() -> string: ]# result = "" -server.on("net_listening") do() -> bool: +server.rpc("net_listening") do() -> bool: ## Returns boolean true when listening, otherwise false. result = true -server.on("net_peerCount") do() -> int: +server.rpc("net_peerCount") do() -> int: ## Returns integer of the number of connected peers. discard -server.on("eth_protocolVersion") do() -> string: +server.rpc("eth_protocolVersion") do() -> string: ## Returns string of the current ethereum protocol version. discard -server.on("eth_syncing") do() -> JsonNode: +server.rpc("eth_syncing") do() -> JsonNode: ## Returns SyncObject or false when not syncing. var res: JsonNode @@ -69,33 +69,33 @@ server.on("eth_syncing") do() -> JsonNode: else: res = newJBool(false) result = res -server.on("eth_coinbase") do() -> string: +server.rpc("eth_coinbase") do() -> string: ## Returns the current coinbase address. result = "" -server.on("eth_mining") do() -> bool: +server.rpc("eth_mining") do() -> bool: ## Returns true of the client is mining, otherwise false. discard -server.on("eth_hashrate") do() -> int: +server.rpc("eth_hashrate") do() -> int: ## Returns the number of hashes per second that the node is mining with. discard -server.on("eth_gasPrice") do() -> int64: +server.rpc("eth_gasPrice") do() -> int64: ## Returns an integer of the current gas price in wei. discard -server.on("eth_accounts") do() -> seq[array[20, byte]]: +server.rpc("eth_accounts") do() -> seq[array[20, byte]]: ## Returns a list of addresses owned by client. # TODO: this might be easier to use as seq[string] # This is what's expected: "result": ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"] discard -server.on("eth_blockNumber") do() -> int: +server.rpc("eth_blockNumber") do() -> int: ## Returns integer of the current block number the client is on. discard -server.on("eth_getBalance") do(data: array[20, byte], quantityTag: string) -> int: +server.rpc("eth_getBalance") do(data: array[20, byte], quantityTag: string) -> int: ## Returns the balance of the account of given address. ## ## data: address to check for balance. @@ -103,7 +103,7 @@ server.on("eth_getBalance") do(data: array[20, byte], quantityTag: string) -> in ## Returns integer of the current balance in wei. discard -server.on("eth_getStorageAt") do(data: array[20, byte], quantity: int, quantityTag: string) -> seq[byte]: +server.rpc("eth_getStorageAt") do(data: array[20, byte], quantity: int, quantityTag: string) -> seq[byte]: ## Returns the value from a storage position at a given address. ## ## data: address of the storage. @@ -114,7 +114,7 @@ server.on("eth_getStorageAt") do(data: array[20, byte], quantity: int, quantityT # For more details, see: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat result = @[] -server.on("eth_getTransactionCount") do(data: array[20, byte], quantityTag: string): +server.rpc("eth_getTransactionCount") do(data: array[20, byte], quantityTag: string): ## Returns the number of transactions sent from an address. ## ## data: address. @@ -122,35 +122,35 @@ server.on("eth_getTransactionCount") do(data: array[20, byte], quantityTag: stri ## Returns integer of the number of transactions send from this address. discard -server.on("eth_getBlockTransactionCountByHash") do(data: array[32, byte]) -> int: +server.rpc("eth_getBlockTransactionCountByHash") do(data: array[32, byte]) -> int: ## Returns the number of transactions in a block from a block matching the given block hash. ## ## data: hash of a block ## Returns integer of the number of transactions in this block. discard -server.on("eth_getBlockTransactionCountByNumber") do(quantityTag: string) -> int: +server.rpc("eth_getBlockTransactionCountByNumber") do(quantityTag: string) -> int: ## Returns the number of transactions in a block matching the given block number. ## ## data: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter. ## Returns integer of the number of transactions in this block. discard -server.on("eth_getUncleCountByBlockHash") do(data: array[32, byte]): +server.rpc("eth_getUncleCountByBlockHash") do(data: array[32, byte]): ## Returns the number of uncles in a block from a block matching the given block hash. ## ## data: hash of a block. ## Returns integer of the number of uncles in this block. discard -server.on("eth_getUncleCountByBlockNumber") do(quantityTag: string): +server.rpc("eth_getUncleCountByBlockNumber") do(quantityTag: string): ## Returns the number of uncles in a block from a block matching the given block number. ## ## quantityTag: integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter. ## Returns integer of uncles in this block. discard -server.on("eth_getCode") do(data: array[20, byte], quantityTag: string) -> seq[byte]: +server.rpc("eth_getCode") do(data: array[20, byte], quantityTag: string) -> seq[byte]: ## Returns code at a given address. ## ## data: address @@ -158,7 +158,7 @@ server.on("eth_getCode") do(data: array[20, byte], quantityTag: string) -> seq[b ## Returns the code from the given address. result = @[] -server.on("eth_sign") do(data: array[20, byte], message: seq[byte]) -> seq[byte]: +server.rpc("eth_sign") do(data: array[20, byte], message: seq[byte]) -> seq[byte]: ## The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))). ## By adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. ## This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim. @@ -169,7 +169,7 @@ server.on("eth_sign") do(data: array[20, byte], message: seq[byte]) -> seq[byte] ## Returns signature. discard -server.on("eth_sendTransaction") do(obj: EthSend) -> UInt256: +server.rpc("eth_sendTransaction") do(obj: EthSend) -> UInt256: ## Creates new message call transaction or a contract creation, if the data field contains code. ## ## obj: the transaction object. @@ -177,7 +177,7 @@ server.on("eth_sendTransaction") do(obj: EthSend) -> UInt256: ## Note: Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract. discard -server.on("eth_sendRawTransaction") do(data: string, quantityTag: int) -> UInt256: # TODO: string or array of byte? +server.rpc("eth_sendRawTransaction") do(data: string, quantityTag: int) -> UInt256: # TODO: string or array of byte? ## Creates new message call transaction or a contract creation for signed transactions. ## ## data: the signed transaction data. @@ -185,7 +185,7 @@ server.on("eth_sendRawTransaction") do(data: string, quantityTag: int) -> UInt25 ## Note: Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract. discard -server.on("eth_call") do(call: EthCall, quantityTag: string) -> UInt256: +server.rpc("eth_call") do(call: EthCall, quantityTag: string) -> UInt256: ## Executes a new message call immediately without creating a transaction on the block chain. ## ## call: the transaction call object. @@ -194,7 +194,7 @@ server.on("eth_call") do(call: EthCall, quantityTag: string) -> UInt256: # TODO: Should return value be UInt256 or seq[byte] or string? discard -server.on("eth_estimateGas") do(call: EthCall, quantityTag: string) -> UInt256: # TODO: Int or U/Int256? +server.rpc("eth_estimateGas") do(call: EthCall, quantityTag: string) -> UInt256: # TODO: Int or U/Int256? ## Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. ## The transaction will not be added to the blockchain. Note that the estimate may be significantly more than ## the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance. @@ -204,7 +204,7 @@ server.on("eth_estimateGas") do(call: EthCall, quantityTag: string) -> UInt256: ## Returns the amount of gas used. discard -server.on("eth_getBlockByHash") do(data: array[32, byte], fullTransactions: bool) -> BlockObject: +server.rpc("eth_getBlockByHash") do(data: array[32, byte], fullTransactions: bool) -> BlockObject: ## Returns information about a block by hash. ## ## data: Hash of a block. @@ -212,7 +212,7 @@ server.on("eth_getBlockByHash") do(data: array[32, byte], fullTransactions: bool ## Returns BlockObject or nil when no block was found. discard -server.on("eth_getBlockByNumber") do(quantityTag: string, fullTransactions: bool) -> BlockObject: +server.rpc("eth_getBlockByNumber") do(quantityTag: string, fullTransactions: bool) -> BlockObject: ## Returns information about a block by block number. ## ## quantityTag: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter. @@ -220,14 +220,14 @@ server.on("eth_getBlockByNumber") do(quantityTag: string, fullTransactions: bool ## Returns BlockObject or nil when no block was found. discard -server.on("eth_getTransactionByHash") do(data: Uint256) -> TransactionObject: +server.rpc("eth_getTransactionByHash") do(data: Uint256) -> TransactionObject: ## Returns the information about a transaction requested by transaction hash. ## ## data: hash of a transaction. ## Returns requested transaction information. discard -server.on("eth_getTransactionByBlockHashAndIndex") do(data: UInt256, quantity: int) -> TransactionObject: +server.rpc("eth_getTransactionByBlockHashAndIndex") do(data: UInt256, quantity: int) -> TransactionObject: ## Returns information about a transaction by block hash and transaction index position. ## ## data: hash of a block. @@ -235,21 +235,21 @@ server.on("eth_getTransactionByBlockHashAndIndex") do(data: UInt256, quantity: i ## Returns requested transaction information. discard -server.on("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: string, quantity: int) -> TransactionObject: +server.rpc("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: string, quantity: int) -> TransactionObject: ## Returns information about a transaction by block number and transaction index position. ## ## quantityTag: a block number, or the string "earliest", "latest" or "pending", as in the default block parameter. ## quantity: the transaction index position. discard -server.on("eth_getTransactionReceipt") do(data: UInt256) -> ReceiptObject: +server.rpc("eth_getTransactionReceipt") do(data: UInt256) -> ReceiptObject: ## Returns the receipt of a transaction by transaction hash. ## ## data: hash of a transaction. ## Returns transaction receipt. discard -server.on("eth_getUncleByBlockHashAndIndex") do(data: UInt256, quantity: int64) -> BlockObject: +server.rpc("eth_getUncleByBlockHashAndIndex") do(data: UInt256, quantity: int64) -> BlockObject: ## Returns information about a uncle of a block by hash and uncle index position. ## ## data: hash a block. @@ -257,7 +257,7 @@ server.on("eth_getUncleByBlockHashAndIndex") do(data: UInt256, quantity: int64) ## Returns BlockObject or nil when no block was found. discard -server.on("eth_getUncleByBlockNumberAndIndex") do(quantityTag: string, quantity: int64) -> BlockObject: +server.rpc("eth_getUncleByBlockNumberAndIndex") do(quantityTag: string, quantity: int64) -> BlockObject: # Returns information about a uncle of a block by number and uncle index position. ## ## quantityTag: a block number, or the string "earliest", "latest" or "pending", as in the default block parameter. @@ -265,34 +265,34 @@ server.on("eth_getUncleByBlockNumberAndIndex") do(quantityTag: string, quantity: ## Returns BlockObject or nil when no block was found. discard -server.on("eth_getCompilers") do() -> seq[string]: +server.rpc("eth_getCompilers") do() -> seq[string]: ## Returns a list of available compilers in the client. ## ## Returns a list of available compilers. result = @[] -server.on("eth_compileSolidity") do(sourceCode: string) -> seq[byte]: +server.rpc("eth_compileSolidity") do(sourceCode: string) -> seq[byte]: ## Returns compiled solidity code. ## ## sourceCode: source code as string. ## Returns compiles source code. result = @[] -server.on("eth_compileLLL") do(sourceCode: string) -> seq[byte]: +server.rpc("eth_compileLLL") do(sourceCode: string) -> seq[byte]: ## Returns compiled LLL code. ## ## sourceCode: source code as string. ## Returns compiles source code. result = @[] -server.on("eth_compileSerpent") do(sourceCode: string) -> seq[byte]: +server.rpc("eth_compileSerpent") do(sourceCode: string) -> seq[byte]: ## Returns compiled serpent code. ## ## sourceCode: source code as string. ## Returns compiles source code. result = @[] -server.on("eth_newFilter") do(filterOptions: FilterOptions) -> int: +server.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int: ## Creates a filter object, based on filter options, to notify when the state changes (logs). ## To check if the state has changed, call eth_getFilterChanges. ## Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters: @@ -306,21 +306,21 @@ server.on("eth_newFilter") do(filterOptions: FilterOptions) -> int: ## Returns integer filter id. discard -server.on("eth_newBlockFilter") do() -> int: +server.rpc("eth_newBlockFilter") do() -> int: ## Creates a filter in the node, to notify when a new block arrives. ## To check if the state has changed, call eth_getFilterChanges. ## ## Returns integer filter id. discard -server.on("eth_newPendingTransactionFilter") do() -> int: +server.rpc("eth_newPendingTransactionFilter") do() -> int: ## Creates a filter in the node, to notify when a new block arrives. ## To check if the state has changed, call eth_getFilterChanges. ## ## Returns integer filter id. discard -server.on("eth_uninstallFilter") do(filterId: int) -> bool: +server.rpc("eth_uninstallFilter") do(filterId: int) -> bool: ## Uninstalls a filter with given id. Should always be called when watch is no longer needed. ## Additonally Filters timeout when they aren't requested with eth_getFilterChanges for a period of time. ## @@ -328,23 +328,23 @@ server.on("eth_uninstallFilter") do(filterId: int) -> bool: ## Returns true if the filter was successfully uninstalled, otherwise false. discard -server.on("eth_getFilterChanges") do(filterId: int) -> seq[LogObject]: +server.rpc("eth_getFilterChanges") do(filterId: int) -> seq[LogObject]: ## Polling method for a filter, which returns an list of logs which occurred since last poll. ## ## filterId: the filter id. result = @[] -server.on("eth_getFilterLogs") do(filterId: int) -> seq[LogObject]: +server.rpc("eth_getFilterLogs") do(filterId: int) -> seq[LogObject]: ## filterId: the filter id. ## Returns a list of all logs matching filter with given id. result = @[] -server.on("eth_getLogs") do(filterOptions: FilterOptions) -> seq[LogObject]: +server.rpc("eth_getLogs") do(filterOptions: FilterOptions) -> seq[LogObject]: ## filterOptions: settings for this filter. ## Returns a list of all logs matching a given filter object. result = @[] -server.on("eth_getWork") do() -> seq[UInt256]: +server.rpc("eth_getWork") do() -> seq[UInt256]: ## Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target"). ## Returned list has the following properties: ## DATA, 32 Bytes - current block header pow-hash. @@ -352,7 +352,7 @@ server.on("eth_getWork") do() -> seq[UInt256]: ## DATA, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty. result = @[] -server.on("eth_submitWork") do(nonce: int64, powHash: Uint256, mixDigest: Uint256) -> bool: +server.rpc("eth_submitWork") do(nonce: int64, powHash: Uint256, mixDigest: Uint256) -> bool: ## Used for submitting a proof-of-work solution. ## ## nonce: the nonce found. @@ -361,7 +361,7 @@ server.on("eth_submitWork") do(nonce: int64, powHash: Uint256, mixDigest: Uint25 ## Returns true if the provided solution is valid, otherwise false. discard -server.on("eth_submitHashrate") do(hashRate: UInt256, id: Uint256) -> bool: +server.rpc("eth_submitHashrate") do(hashRate: UInt256, id: Uint256) -> bool: ## Used for submitting mining hashrate. ## ## hashRate: a hexadecimal string representation (32 bytes) of the hash rate. @@ -369,44 +369,44 @@ server.on("eth_submitHashrate") do(hashRate: UInt256, id: Uint256) -> bool: ## Returns true if submitting went through succesfully and false otherwise. discard -server.on("shh_version") do() -> string: +server.rpc("shh_version") do() -> string: ## Returns string of the current whisper protocol version. discard -server.on("shh_post") do(message: WhisperPost) -> bool: +server.rpc("shh_post") do(message: WhisperPost) -> bool: ## Sends a whisper message. ## ## message: Whisper message to post. ## Returns true if the message was send, otherwise false. discard -server.on("shh_newIdentity") do() -> array[60, byte]: +server.rpc("shh_newIdentity") do() -> array[60, byte]: ## Creates new whisper identity in the client. ## ## Returns the address of the new identiy. discard -server.on("shh_hasIdentity") do(identity: array[60, byte]) -> bool: +server.rpc("shh_hasIdentity") do(identity: array[60, byte]) -> bool: ## Checks if the client holds the private keys for a given identity. ## ## identity: the identity address to check. ## Returns true if the client holds the privatekey for that identity, otherwise false. discard -server.on("shh_newGroup") do() -> array[60, byte]: +server.rpc("shh_newGroup") do() -> array[60, byte]: ## (?) - This has no description information in the RPC wiki. ## ## Returns the address of the new group. (?) discard -server.on("shh_addToGroup") do(identity: array[60, byte]) -> bool: +server.rpc("shh_addToGroup") do(identity: array[60, byte]) -> bool: ## (?) - This has no description information in the RPC wiki. ## ## identity: the identity address to add to a group (?). ## Returns true if the identity was successfully added to the group, otherwise false (?). discard -server.on("shh_newFilter") do(filterOptions: FilterOptions, to: array[60, byte], topics: seq[UInt256]) -> int: # TODO: Is topic of right type? +server.rpc("shh_newFilter") do(filterOptions: FilterOptions, to: array[60, byte], topics: seq[UInt256]) -> int: # TODO: Is topic of right type? ## Creates filter to notify, when client receives whisper message matching the filter options. ## ## filterOptions: The filter options: @@ -418,7 +418,7 @@ server.on("shh_newFilter") do(filterOptions: FilterOptions, to: array[60, byte], ## Returns the newly created filter. discard -server.on("shh_uninstallFilter") do(id: int) -> bool: +server.rpc("shh_uninstallFilter") do(id: int) -> bool: ## Uninstalls a filter with given id. ## Should always be called when watch is no longer needed. ## Additonally Filters timeout when they aren't requested with shh_getFilterChanges for a period of time. @@ -427,14 +427,14 @@ server.on("shh_uninstallFilter") do(id: int) -> bool: ## Returns true if the filter was successfully uninstalled, otherwise false. discard -server.on("shh_getFilterChanges") do(id: int) -> seq[WhisperMessage]: +server.rpc("shh_getFilterChanges") do(id: int) -> seq[WhisperMessage]: ## Polling method for whisper filters. Returns new messages since the last call of this method. ## Note: calling the shh_getMessages method, will reset the buffer for this method, so that you won't receive duplicate messages. ## ## id: the filter id. discard -server.on("shh_getMessages") do(id: int) -> seq[WhisperMessage]: +server.rpc("shh_getMessages") do(id: int) -> seq[WhisperMessage]: ## Get all messages matching a filter. Unlike shh_getFilterChanges this returns all messages. ## ## id: the filter id. diff --git a/eth-rpc/server/servertypes.nim b/eth-rpc/server/servertypes.nim index 263d2f3..25d33d9 100644 --- a/eth-rpc/server/servertypes.nim +++ b/eth-rpc/server/servertypes.nim @@ -141,51 +141,47 @@ proc makeProcName(s: string): string = if c.isAlphaNumeric: result.add c proc hasReturnType(params: NimNode): bool = - if params.len > 0 and params[0] != nil and params[0].kind != nnkEmpty: + if params != nil and params.len > 0 and params[0] != nil and params[0].kind != nnkEmpty: result = true -macro on*(server: var RpcServer, path: string, body: untyped): untyped = +macro rpc*(server: var RpcServer, path: string, body: untyped): untyped = result = newStmtList() let parameters = body.findChild(it.kind == nnkFormalParams) - paramsIdent = ident"params" # all remote calls have a single parameter: `params: JsonNode` - pathStr = $path # procs are generated from the stripped path - procName = ident(pathStr.makeProcName) - doMain = genSym(nskProc) # proc that contains our rpc body - res = ident"result" # async result + paramsIdent = newIdentNode"params" # all remote calls have a single parameter: `params: JsonNode` + pathStr = $path # procs are generated from the stripped path + procNameStr = pathStr.makeProcName # strip non alphanumeric + procName = newIdentNode(procNameStr) # public rpc proc + doMain = newIdentNode(procNameStr & "DoMain") # when parameters: proc that contains our rpc body + res = newIdentNode("result") # async result var setup = setupParams(parameters, paramsIdent) - procBody: NimNode - - if body.kind == nnkStmtList: procBody = body - else: procBody = body.body + procBody = if body.kind == nnkStmtList: body else: body.body if parameters.hasReturnType: let returnType = parameters[0] - # `doMain` is outside of async transformation, - # allowing natural `return` + # delgate async proc allows return and setting of result as native type result.add(quote do: - proc `doMain`(`paramsIdent`: JsonNode): `returnType` {.inline.} = + proc `doMain`(`paramsIdent`: JsonNode): Future[`returnType`] {.async.} = `setup` `procBody` ) - # Note ``res` =` (which becomes `result = `) will be transformed by {.async.} to `complete` if returnType == ident"JsonNode": # `JsonNode` results don't need conversion result.add( quote do: proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = - `res` = `doMain`(`paramsIdent`) + `res` = await `doMain`(`paramsIdent`) ) else: - result.add( quote do: + result.add(quote do: proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = - `res` = %`doMain`(`paramsIdent`) + `res` = %await `doMain`(`paramsIdent`) ) else: # no return types, inline contents - result.add( quote do: + result.add(quote do: proc `procName`*(`paramsIdent`: JsonNode): Future[JsonNode] {.async.} = `setup` `procBody` diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index 372ab36..b1e8e7f 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -30,42 +30,42 @@ var s = newRpcServer("localhost") # RPC definitions -s.on("rpc.simplepath"): +s.rpc("rpc.simplepath"): result = %1 -s.on("rpc.differentparams") do(a: int, b: string): +s.rpc("rpc.differentparams") do(a: int, b: string): result = %[%a, %b] -s.on("rpc.arrayparam") do(arr: array[0..5, byte], b: string): +s.rpc("rpc.arrayparam") do(arr: array[0..5, byte], b: string): var res = %arr res.add %b result = %res -s.on("rpc.seqparam") do(a: string, s: seq[int]): +s.rpc("rpc.seqparam") do(a: string, s: seq[int]): var res = newJArray() res.add %a for item in s: res.add %int(item) result = res -s.on("rpc.objparam") do(a: string, obj: MyObject): +s.rpc("rpc.objparam") do(a: string, obj: MyObject): result = %obj -s.on("rpc.uint256param") do(i: UInt256): +s.rpc("rpc.uint256param") do(i: UInt256): let r = i + 1.stUint(256) result = %r -s.on("rpc.returntypesimple") do(i: int) -> int: +s.rpc("rpc.returntypesimple") do(i: int) -> int: result = i -s.on("rpc.returntypecomplex") do(i: int) -> Test2: +s.rpc("rpc.returntypecomplex") do(i: int) -> Test2: result.x = [1, i, 3] result.y = "test" -s.on("rpc.testreturns") do() -> int: +s.rpc("rpc.testreturns") do() -> int: return 1234 -s.on("rpc.testreturnuint256") do() -> UInt256: +s.rpc("rpc.testreturnuint256") do() -> UInt256: let r: UInt256 = "0x1234567890abcdef".parse(UInt256, 16) return r diff --git a/tests/testserverclient.nim b/tests/testserverclient.nim index ecc0870..fb1691e 100644 --- a/tests/testserverclient.nim +++ b/tests/testserverclient.nim @@ -13,7 +13,7 @@ var srv = sharedRpcServer() srv.address = "localhost" srv.port = Port(8545) -srv.on("myProc") do(input: string, data: array[0..3, int]): +srv.rpc("myProc") do(input: string, data: array[0..3, int]): result = %("Hello " & input & " data: " & $data) asyncCheck srv.serve