Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

update JSON-RPC codec to observe specification #465

Merged

Conversation

benjaminbollen
Copy link
Contributor

@benjaminbollen benjaminbollen commented Jan 30, 2017

rpc: update JSON-RPC codec to follow the specification wrt Response object;
specifically the result and error member of the Response object are mutually exclusive per http://www.jsonrpc.org/specification#response_object

fixes #464

@benjaminbollen
Copy link
Contributor Author

benjaminbollen commented Jan 30, 2017

for erisdb.GetAccounts I now get on an empty chain:

$ curl -H "Content-Type: application/json" -X POST --data '{"id":"0","method":"erisdb.getAccounts","params":{"filters":[]},"jsonrpc":"2.0"}' http://localhost:1337/rpc | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   515  100   435  100    80   114k  21557 --:--:-- --:--:-- --:--:--  141k
{
  "result": {
    "accounts": [
      {
        "address": "0000000000000000000000000000000000000000",
        "pub_key": null,
        "sequence": 0,
        "balance": 1337,
        "code": "",
        "storage_root": "",
        "permissions": {
          "base": {
            "perms": 2302,
            "set": 16383
          },
          "roles": []
        }
      },
      {
        "address": "DDE80114E6BFED2EC6A823B30FC1F47B4B9C72B3",
        "pub_key": null,
        "sequence": 0,
        "balance": 99999999999999,
        "code": "",
        "storage_root": "",
        "permissions": {
          "base": {
            "perms": 16383,
            "set": 16383
          },
          "roles": []
        }
      }
    ]
  },
  "id": "0",
  "jsonrpc": "2.0"
}

and for an error:

curl -H "Content-Type: application/json" -X POST --data '{"id":"0","method":"erisdb.getAccounts","params":{"filters":[THIS-IS-AN-INVALID-FILTER]},"jsonrpc":"2.0"}' http://localhost:1337/rpc | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   244  100   139  100   105  33582  25368 --:--:-- --:--:-- --:--:-- 46333
{
  "error": {
    "code": -32700,
    "message": "Failed to parse request: invalid character 'T' looking for beginning of value"
  },
  "id": "",
  "jsonrpc": "2.0"
}

Copy link
Contributor

@silasdavis silasdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge, unless we want to switch to marker interface. Just has the advantage of adding intentionality to the struct definer rather than the caller who is passing that struct.

rpc/jsonrpc.go Outdated
RPCResponse struct {
// RPCResponse MUST follow the JSON-RPC specification for Response object
// reference: http://www.jsonrpc.org/specification#response_object
RPCResponse interface{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making this an interface with a marker method func AssertIsRPCResponse()?

@silasdavis silasdavis merged commit 17ddab3 into hyperledger-archives:develop Jan 31, 2017
silasdavis added a commit to silasdavis/burrow that referenced this pull request Mar 9, 2019
…464_json_spec

update JSON-RPC codec to observe specification
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[RPC] JSON-RPC 2.0 Specification are not met
2 participants