-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
btcjson: use type params to revamp package to be more extensible and eliminate duplication #1934
Comments
From the sketch, maybe we finally get code style like |
Do you mean if the user wants to update a struct with a breaking change vs create an entirely new command? I think in my ideal world, the only thing someone needs to do is define the new command, then the new version of the library takes care of all the other specific, which eliminates a lot of the boiler plate we have. Then at that point, having the command struct in the I think a success criteria here is that any updates to the set of JSON-RPC calls callable by the |
An basic example: Eoous@b034c29. For go version lower than 1.21, we can't use the expression We can define a deterministic type to call this, but this code may be slightly unclean.
|
In the beginning, we would keep up with the Bitcoin Core RPC interface mostly in lock step. This meant for each change, we'd also add the message (or modify) it and try to keep up with that behavior. As the years have passed, the RPC interfaces have drifted more and more over time, and at this point we are no longer explicitly putting in the effort to add every new RPC call, sometimes due to architectural differences.
However, since we don't implement all the calls they have, this means that the
rpcclient
library start to lack functionality that developers need to build on top ofbtcd
. If a new callFoo
is added, then we need to update both thebtcjson
and therpcclient
packages for this to be available to developers.With Go 1.18, generics or type params were used. We can use this feature to:
It's worth noting that devs can already use the
RawRequest
method to issue any arbitrary JSON RPC requests. For this workflow, they'd define the new json struct, then pass it in as params, and then decode the opaque json blob on the other side.Here's a sketch of what that would look like. Today we end up with a ton of duplicated code, since we implement a custom future type for each message, then also a series of methods to issue an async vs a sync code. Instead, we can rely on interfaces that look something like:
Along the way we can do away with most instances of reflection in the package as well.
Then a new call can be added purely by the developer that needs it by implementing the
RpcCall
for the new command.The text was updated successfully, but these errors were encountered: