rpc: rename RawParams to Params in Raw, add comments

We've got parameters here and usually we name them Raw when they're
represented by json.RawMessage which is not the case here, so make it a bit
more friendly (the type itself is only used in client internals, so rename is
not a huge problem).
This commit is contained in:
Roman Khimov 2022-07-07 18:33:23 +03:00
parent 9aecfb7c94
commit 113cb0fac3
3 changed files with 25 additions and 13 deletions

View file

@ -176,7 +176,7 @@ func (c *Client) performRequest(method string, p request.RawParams, v interface{
var r = request.Raw{
JSONRPC: request.JSONRPCVersion,
Method: method,
RawParams: p.Values,
Params: p.Values,
ID: c.getNextRequestID(),
}

View file

@ -256,7 +256,7 @@ writeloop:
break writeloop
}
if err := c.ws.WriteJSON(req); err != nil {
connCloseErr = fmt.Errorf("failed to write JSON request (%s / %d): %w", req.Method, len(req.RawParams), err)
connCloseErr = fmt.Errorf("failed to write JSON request (%s / %d): %w", req.Method, len(req.Params), err)
break writeloop
}
case <-pingTicker.C:

View file

@ -32,15 +32,27 @@ func NewRawParams(vals ...interface{}) RawParams {
return p
}
// Raw represents JSON-RPC request on the Client side.
type Raw struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
RawParams []interface{} `json:"params"`
ID uint64 `json:"id"`
}
type (
// Raw represents JSON-RPC request. It's generic enough to be used in many
// generic JSON-RPC communication scenarios, yet at the same time it's
// tailored for NeoGo RPC Client needs.
Raw struct {
// JSONRPC is the protocol version, only valid when it contains JSONRPCVersion.
JSONRPC string `json:"jsonrpc"`
// Method is the method being called.
Method string `json:"method"`
// Params is a set of method-specific parameters passed to the call. They
// can be anything as long as they can be marshaled to JSON correctly and
// used by the method implementation on the server side. While JSON-RPC
// technically allows it to be an object, all Neo calls expect params
// to be an array.
Params []interface{} `json:"params"`
// ID is an identifier associated with this request. JSON-RPC itself allows
// any strings to be used for it as well, but NeoGo RPC client uses numeric
// identifiers.
ID uint64 `json:"id"`
}
// BlockFilter is a wrapper structure for the block event filter. The only
// allowed filter is primary index.
BlockFilter struct {