neoneo-go/pkg/rpc
Vsevolod Brekelov 100fee164b unitTest: reworked RPC unit test
earlier we had an issue with failing test in #353 and other one #305.
Reworked these test to have in-memory database. This led to multiple
changes: made some functions like Hash and Persist public(otherwise
it's not possible to control state of the blockchain); removed
unit_tests storage package which was used mainly for leveldb in unit
tests.
I see these tests not really good since they look like e2e tests and
as for me should be run in separate step against dockerized env or
in case we want to check rpc handler we might want to rework it in order
to have interface for proper unit tests.
As for me this patchset at least makes as safe with not removing totally
previous tests and at the same time CircleCI will be happy now.
2019-09-18 18:21:16 +03:00
..
result RCP server (#50) 2018-03-23 21:36:59 +01:00
wrappers io: drop Size() method from Serializable and associated 2019-09-17 13:21:45 +03:00
client.go *: add/fix godoc comments to satisfy golint 2019-09-03 17:57:51 +03:00
doc.go RPC client (#42) 2018-03-05 09:53:09 +01:00
errors.go Fix #140 (improve error message) (#142) 2019-02-20 16:28:11 +00:00
neoScanBalanceGetter.go rpc: fix bad name spellings noted by golint 2019-09-03 18:16:48 +03:00
neoScanTypes.go *: add/fix godoc comments to satisfy golint 2019-09-03 17:57:51 +03:00
param.go RCP server (#50) 2018-03-23 21:36:59 +01:00
params.go Fix #140 (improve error message) (#142) 2019-02-20 16:28:11 +00:00
README.md Fix API documentation link (#141) 2019-02-19 12:48:02 +01:00
request.go [FIX] Formatting and code-style (#118) 2019-01-25 12:20:35 +01:00
rpc.go io: redo Serializable to return errors in BinReader/BinWriter 2019-09-17 13:21:52 +03:00
server.go io: redo Serializable to return errors in BinReader/BinWriter 2019-09-17 13:21:52 +03:00
server_helper_test.go unitTest: reworked RPC unit test 2019-09-18 18:21:16 +03:00
server_test.go unitTest: reworked RPC unit test 2019-09-18 18:21:16 +03:00
stack_param.go *: add/fix godoc comments to satisfy golint 2019-09-03 17:57:51 +03:00
stack_param_test.go uint256: add Reverse(), change String() to be BE 2019-08-26 13:32:19 +03:00
txBuilder.go io: redo Serializable to return errors in BinReader/BinWriter 2019-09-17 13:21:52 +03:00
txTypes.go *: gofmt -s 2019-09-09 12:02:24 +03:00
types.go rpc: fix bad name spellings noted by golint 2019-09-03 18:16:48 +03: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 Yes -
invokescript No VM
invokefunction No VM
sendrawtransaction No Needs to be implemented in pkg/core/blockchain.go
validateaddress Yes -
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 -