dcrd/dcrjson
Dave Collins 04a107e7c5
rpcserver: Correct JSON-RPC request unmarshal.
This reworks the JSON-RPC unmarshalling logic to correct some error
handling cases as well as optimize the normal path.

It accomplishes this as follows:

- Removes the custom, and incorrect, unmarshalling code in favor of just
  unmarshalling into the Request struct directly
- Allows the Params to be nil (unspecified) per the spec
- Corrects the per-entry batch unmarshal logic such that it first
  unmarshals into an array of json.RawMessage and then unmarshals each
  individual entry into the Request struct
- No longer attempts to process non-batched requests that fail to
  unmarshal properly
2020-06-03 01:58:29 -05:00
..
cmdinfo_test.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
cmdinfo.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
cmdparse_test.go multi: remove unused funcs and vars 2019-09-05 10:13:18 -05:00
cmdparse.go multi: Correct typos. 2019-08-16 17:37:58 -05:00
CONTRIBUTORS Initial Decred Commit. 2016-02-07 14:00:12 -05:00
doc.go multi: replace godoc.org with pkg.go.dev 2020-02-18 19:35:19 -06:00
error_test.go dcrjson: Consolidate tests into dcrjson package. 2018-07-23 18:20:13 -05:00
error.go multi: Correct typos. 2019-08-16 17:37:58 -05:00
example_test.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
go.mod dcrjson: Prepare v3.0.1. 2019-10-14 15:54:11 -05:00
go.sum dcrjson: Prepare v3.0.1. 2019-10-14 15:54:11 -05:00
help_test.go multi: Correct typos. 2019-08-16 17:37:58 -05:00
help.go multi: Updates for staticcheck results. 2019-10-31 15:14:35 -05:00
helpers_test.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
helpers.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
jsonerr.go multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
jsonrpc_test.go dcrjson: Consolidate tests into dcrjson package. 2018-07-23 18:20:13 -05:00
jsonrpc.go rpcserver: Correct JSON-RPC request unmarshal. 2020-06-03 01:58:29 -05:00
jsonrpcerr.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
parse_test.go multi: preallocate memory. 2019-03-09 16:43:48 -06:00
parse.go dcrjson: Remove unused vote bit concat codec funcs. 2018-08-05 16:24:56 -05:00
README.md multi: replace godoc.org with pkg.go.dev 2020-02-18 19:35:19 -06:00
register_test.go dcrjson: Introduce v3 and move types to module. 2019-07-19 08:49:49 -05:00
register.go multi: Correct typos. 2019-08-16 17:37:58 -05:00

dcrjson

Build Status ISC License Doc

Package dcrjson implements infrastructure for marshalling to and from the decred JSON-RPC API via concrete types. A comprehensive suite of tests is provided to ensure proper functionality.

Although this package was primarily written for the decred, it has intentionally been designed so it can be used as a standalone package for any projects needing to marshal to and from decred JSON-RPC requests and responses.

Note that although it's possible to use this package directly to implement an RPC client, it is not recommended since it is only intended as an infrastructure package. Instead, RPC clients should use the rpcclient package which provides a full blown RPC client with many features such as automatic connection management, websocket support, automatic notification re-registration on reconnect, and conversion from the raw underlying RPC types (strings, floats, ints, etc) to higher-level types with many nice and useful properties.

Installation and Updating

$ go get -u github.com/decred/dcrd/dcrjson

Examples

  • Marshal Command Demonstrates how to create and marshal a command into a JSON-RPC request.

  • Parse Command Demonstrates how to unmarshal a JSON-RPC request and then parse the params of the concrete request into a concrete command.

  • Marshal Response Demonstrates how to marshal a JSON-RPC response.

  • Unmarshal Response Demonstrates how to unmarshal a JSON-RPC response and then unmarshal the result field in the response to a concrete type.

License

Package dcrjson is licensed under the copyfree ISC License.