-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Separate RPC serialization from implementation #2072
Conversation
@@ -100,13 +99,13 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where | |||
} | |||
} | |||
|
|||
fn block(&self, id: BlockID, include_txs: bool) -> Result<Value, Error> { | |||
fn block(&self, id: BlockID, include_txs: bool) -> Result<Option<Block>, Error> { |
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.
Shouldn't we have a non-serialization related Error
also?
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.
What would it consist of? The errors that can occur still need to be serialized and won't be used anywhere else.
@debris please review this |
d0bbf1f
to
73f813c
Compare
this seems to increase the amount of effort to expose functionality by another function implementation per RPC. thus increase dev effort and maintenance burden. i would prefer to reduce the effort, not increase it. |
But it keeps parameter deserialization in a single place in case of multiple implementations (which I suppose will be a case with light client) - keeping two APIs in sync in terms of expected parameters is easier. What about a default implementation for trait Eth {
fn syncing(&self) -> Result<bool, Error>;
fn rpc_syncing(&self, params: Params) -> Result<Value, Error> {
try!(expect_no_params(params));
self.syncing().map(to_value)
}
} |
tbh introducing a pattern that requires a new function it's additional clutter which makes adding, renaming and removing functions more tedious than it really should be. i'm just wondering whether it is something that can be fixed properly in due course (in which case i'd favour the q'n'd solution of just duplicating logic in order to minimise effort when adding functions and keep us reminded that it really does need addressing) or whether this is really the best we can reasonably do (in which case merging is reasonable). |
Played around with macro and type-based codegen for parameter and output deserialization -- the results are here: ethcore/parity@fd711c6 Only a single trait with strongly-typed methods is required for an RPC-API (with the caveat that all parameters must be deserializable except for optional delegate.add_method("foo_Bar", move |base, params| foo_bar.wrap_rpc(base, params)) which is the only added complexity. When @gavofyork think that this solution would be acceptable? |
oh yeah! :) |
73f813c
to
1f4aa4b
Compare
Latest take on it is pushed -- takes a slightly different approach than described in the comment above because I was running into some issues with coercing anonymous function types into concrete function pointers without specifying the args explicitly. RPC APIs are to be wrapped in the Trailing parameters are managed by the Not supported yet:
|
lgtm |
This PR only does the
Eth
andEthFilter
APIs but it was getting a bit big.The
jsonrpc_core
update is for https://github.com/ethcore/jsonrpc-core/pull/27