neo-go/pkg/rpc
dauTT 095653af23 Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'

* Added new files:

* Added new method: CompareTo

* Fixed empty Slice case

* Added new methods: LessThan, GreaterThan, Equal, CompareTo

* Added new method: InputIntersection

* Added MaxTransactionSize, GroupOutputByAssetID

* Added ned method: ScriptHash

* Added new method: IsDoubleSpend

* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method

* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool

* Added new methods: RelayTxn, RelayDirectly

* Fixed tests

* Implemented RPC server method sendrawtransaction

* Refactor getrawtransaction, sendrawtransaction in separate methods

* Moved 'secondsPerBlock' to config file

* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection  method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code

* Fixed minor issues related to

1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring  CompareTo method in uint256.go

* Fixed small issues

* Use sync.RWMutex instead of sync.Mutex

* Refined (R)Lock/(R)Unlock

* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00: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 rpc server method GetRawTransaction (#135) 2019-02-20 18:39:32 +01:00
client.go Fix possible data race (#136) 2019-02-12 20:03:21 +01: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 Code refactoring (#143) 2019-02-19 14:22:33 +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 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 Fix typos (#133) 2019-02-13 18:01:10 +00:00
server.go Implement rpc server method: sendrawtransaction (#174) 2019-03-20 12:30:05 +00:00
server_test.go Implement rpc server method: sendrawtransaction (#174) 2019-03-20 12:30:05 +00:00
stack_param.go Parse stack params (#119) 2019-02-05 13:22:10 +01:00
stack_param_test.go Code refactoring (#143) 2019-02-19 14:22:33 +01:00
txBuilder.go small fix of utxo calculation on raw transaction build (#126) 2019-02-07 12:44:51 +01:00
txTypes.go BalanceGetter interface shortened (#127) 2019-02-08 16:32:01 +01:00
types.go make State a set as in reference C# implementation (#123) 2019-02-19 12:47:25 +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 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 -