-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use nim-json-serialization for RPCs #172
Use nim-json-serialization for RPCs #172
Conversation
before we move in this direction we need:
|
@arnetheduck I've added some serialization wrappers that will hopefully satisfy the second requirement. This commit fixes types to specific Let me know if you'd prefer me to completely avoid all pass-through to |
Regarding f314957, I hope a template `==`*(a, b: distinct (string|StringOfJson)): bool =
{.push hint[ConvFromXtoItselfNotNeeded]:off.}
let r =string(a) == string(b)
{.pop.}
r |
this is something that needs fixing in nim-json-serialization - ie it's nim-json-rpc is just a thin wrapper - the only thing it should do is to implement the json-rpc standard on top of a few transports - ie the framing etc - it should not contain any json lexing code - that belongs in nim-json-serialization. It should also not contain any ethereum-specific encoding quirks - that belong in nim-web3 and friends - this project is agnostic to ethereum and it should be possible to customize the "standard" used to interpret / parse the json data. Taking a step back, there are two standards at play here: one is the JSON-RPC protocol which defines a "frame" for an RPC call - the other is the standard that the library user controls - ie how to parse the The key insight from the standards text is that this serialization is distinct from the parsing of the frame. As a user of the json-rpc library, I need to be able to define a parser used for for the user-controlled parts which needs to be precise and without cross-implementation leaks in general while JSON-RPC itself needs to use its own parser to ensure that it correctly parses the data in the standard - these two parsers may coincide but they don't have to. Going even deeper, parsing JSON is made up of two "stages": interpreting text as "json types" and translating "json types" to "nim types" - the first stage is shared between all json parsers while the second stage needs to be customizable with fine-grained control. As such, looking at the state of this PR we need to go back to the basics:
|
json_rpc/jsonmarshal.nim
Outdated
|
||
export json, options, json_serialization | ||
|
||
Json.createFlavor Eth1JsonRpc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change Eth1JsonRpc
to JsonRpc
.
And please set the target branch to v0.2.0 because we still need to refactor |
This is a PR to use
nim-json-serialization
for encoding and decoding.Notes about
testrpcmacro.nim
:check r == %value
were changed tocheck r == Eth1JsonRpc.encode value
. This is because serialization handles optionals slightly differently to the native json library.1.0
rather than the1.23
it was before - otherwise we get 1.2300000014 or similar. I assume this is because the internal floating point output is in a different precision. Please advise if there's a better way to test this.