neoneo-go/pkg/rpc
dauTT 1360e1de68 Added rpc unit tests (#107)
* Fixed small incosistencies related to comments and variable name

* For testing purposes we have to move the method newBlockchain from the cli/server/server.go to  pkg/core/blockchain.go. In addition we have to rename it to NewBlockchainLevelDB in order to be able to export it and avoid naming conflicts. In future we still need to think how to switch between different blockchain implementation easily but for the time being this is not possible.

* Added unit tests for the rpc server

* Added unit_testnet chain fixture

* fixed port number

* Added errors handling

* move unit_testnet chain from 'cli/chains' to 'pkg/rpc/chains'
2019-01-22 13:14:52 +01:00
..
chains/unit_testnet Added rpc unit tests (#107) 2019-01-22 13:14:52 +01:00
result RCP server (#50) 2018-03-23 21:36:59 +01:00
wrappers Implemented rcp method GetAssetState (#103) 2018-11-26 22:12:33 +01:00
client.go Small fixes (#117) 2019-01-22 13:14:40 +01:00
doc.go RPC client (#42) 2018-03-05 09:53:09 +01:00
errors.go RCP server (#50) 2018-03-23 21:36:59 +01:00
neoScanBalanceGetter.go Small fixes (#117) 2019-01-22 13:14:40 +01:00
neoScanTypes.go SendToAddress RPC call (#114) 2018-12-21 10:32:18 +01:00
param.go RCP server (#50) 2018-03-23 21:36:59 +01:00
params.go RCP server (#50) 2018-03-23 21:36:59 +01:00
README.md SendToAddress RPC call (#114) 2018-12-21 10:32:18 +01:00
request.go RCP server (#50) 2018-03-23 21:36:59 +01:00
rpc.go Small fixes (#117) 2019-01-22 13:14:40 +01:00
server.go Implemented rcp method GetAssetState (#103) 2018-11-26 22:12:33 +01:00
server_test.go Added rpc unit tests (#107) 2019-01-22 13:14:52 +01:00
txBuilder.go Small fixes (#117) 2019-01-22 13:14:40 +01:00
txTypes.go Small fixes (#117) 2019-01-22 13:14:40 +01:00
types.go Small fixes (#117) 2019-01-22 13:14:40 +01:00

RPC

What

  • Structs used by JSON-RPC server and for interacting with a JSON-RPC endpoint.
  • Server for running the JSON-RPC protocol based on port in configuration.

This package is currently in alpha and is subject to change.

Reference

Client

You can create a new client and start interacting with any NEO node that exposes their JSON-RPC endpoint. See godocs for example.

Not all methods are currently supported in the client, please see table below for supported methods.

TODO

  • Merge structs so can be used by both server and client.
  • Add missing methods to client.
  • Allow client to connect using client cert.

Supported methods

Method Implemented Required to implement
getblock Yes -
getaccountstate Yes -
invokescript Yes -
invokefunction Yes -
sendrawtransaction Yes -
invoke Yes -
getrawtransaction Yes -
validateaddress No Handler and result struct
getblocksysfee No Handler and result struct
getcontractstate No Handler and result struct
getrawmempool No Handler and result struct
getstorage No Handler and result struct
submitblock No Handler and result struct
gettxout No Handler and result struct
getassetstate No Handler and result struct
getpeers No Handler and result struct
getversion No Handler and result struct
getconnectioncount No Handler and result struct
getblockhash No Handler and result struct
getblockcount No Handler and result struct
getbestblockhash No Handler and result struct

Server

The server is written to support as much of the JSON-RPC 2.0 Spec as possible. The server is run as part of the node currently.

TODO

  • Implement HTTPS server.
  • Add remaining methods (Documented below).
  • Add Swagger spec and test using dredd in circleCI.

Example call

An example would be viewing the version of the node:

curl -X POST -d '{"jsonrpc": "2.0", "method": "getversion", "params": [], "id": 1}" http://localhost:20332

which would yield the response:

{
  "jsonrpc" : "2.0",
    "id" : 1,
    "result" : {
      "port" : 20333,
      "useragent" : "/NEO-GO:0.36.0-dev/",
      "nonce" : 9318417
    }
}

Supported methods

Method Implemented Required to implement
getblock Yes -
getaccountstate No Result struct & wallet functionality
invokescript No VM
invokefunction No VM
sendrawtransaction No Needs to be implemented in pkg/core/blockchain.go
validateaddress No Needs to be implemented in pkg/core/blockchain.go
getblocksysfee No N/A
getcontractstate No Needs to be implemented in pkg/core/blockchain.go
getrawmempool No Needs to be implemented on in pkg/network/server.go
getrawtransaction No Needs to be implemented in pkg/core/blockchain.go
getstorage No VM
submitblock No Needs to be implemented in pkg/core/blockchain.go
gettxout No Needs to be implemented in pkg/core/blockchain.go
invoke No VM
getassetstate Yes -
getpeers Yes -
getversion Yes -
getconnectioncount Yes -
getblockhash Yes -
getblockcount Yes -
getbestblockhash Yes -