rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes#831
Conversation
|
cc @csgui Why i cant alter the name of the PR 😭 |
766648c to
5cd9007
Compare
|
Can someone with permission to alter the pr title fix it for me ? rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes. |
|
5cd9007 Unrelated test fail |
|
@jaoleal double check if you can use That would makes more sense and allows the remove of |
c13b68a to
0e160f5
Compare
|
top commit: 0e160f5
Thanks for the suggestions @csgui |
|
I think the commit descriptions are missing because they only have titles. |
0e160f5 to
781ea91
Compare
|
[781ea91 Rebased and extended commit message with descriptions. |
|
Added formal |
781ea91 to
994e4b7
Compare
This comment was marked as outdated.
This comment was marked as outdated.
2d230a8 to
bd4d7a1
Compare
|
gaddamit these conflicts |
bd4d7a1 to
d18e6dd
Compare
|
unrelated fail on functional tests d18e6dd |
f8aa0e3 to
0f62bfa
Compare
|
@moisesPompilio done in 0f62bfa |
edad67c to
d4afa59
Compare
|
rebased |
| //! [`RpcError`]: jsonrpc_interface::RpcError | ||
| //! [`JsonRpcError`]: jsonrpc_interface::JsonRpcError | ||
|
|
||
| use std::fmt::Debug; |
There was a problem hiding this comment.
use core instead std
| use std::fmt::Display; | ||
| use std::fmt::Formatter; |
There was a problem hiding this comment.
use core instead std
|
need rebase |
- Add named constants for floresta-specific rpc server error codes (TX_NOT_FOUND, BLOCK_NOT_FOUND, PEER_NOT_FOUND, etc.) - Add SERIALIZATION_EXPECT and HTTP_RESPONSE_EXPECT constants for expect() messages - Add From<BlockchainError> for JsonRpcError conversion. - Change ScriptPubKeyJson.address to Option<String> for nonstandard scripts (matching Bitcoin Core behavior)
- Rewrite arg_parser with organic get_at(), get_with_default(), get_arr_at(), and optional(). - Change RpcRequest.params to support named (object) parameters alongside positional (array) parameters. - Split method dispatch into no-param methods (early return) and param methods (with params.unwrap_or_default()). - Replace .unwrap() calls with .expect() using descriptive constants. - Build explicit HTTP responses for parse errors with proper status codes.
…d clippy lint - Replace all .unwrap() calls in blockchain.rs with proper error propagation via map_err and the ? operator - Apply #[deny(clippy::unwrap_used)] lint to the json_rpc module
- Add comprehensive tests covering positional and named parameters, null/omitted params, optional defaults, error codes, and response structure validation
d4afa59 to
8ecf173
Compare
|
Double-checking this PR, and it seems there are still some things to improve. 1 - Run the command below and check the response:
The correct response would be something like 2 - Run the command below and check the response:
It is the same Also, corner cases like those, should be covered by some kind of test. |
|
Thanks for finding these bugs @csgui, ill investigate them and address a fix. By intuition a fix would be a general check done on each request, as it is now problems are found by the command execution pipeline.
Ill be more aggressive on these |
|
I think this is also related to #463 scoping floresta_node/s/json_rpc/ |
|
|
||
| /// Types and methods implementing the [JSON-RPC 2.0 spec](https://www.jsonrpc.org/specification), | ||
| /// tailored for floresta's RPC server. | ||
| pub mod jsonrpc_interface { |
There was a problem hiding this comment.
NIT:
It doesn't seem good to have a mod inside a file. Maybe it's interesting to put this content inside that mod json_interface into a new file, or make res.rs a folder res/ and what is inside it become a mod, and what is inside that json_interface mod would go to a new file inside it calledjson_interface.rsor something like that. I think it looks nicer
There was a problem hiding this comment.
No yeah, totally agree with you, we actually reimplement a lot of things from jsonrpc (rust-bitcoins lib) and expand some others like the getters we have.
I wish we centralized those to avoid code duplication and drifting which still happening thanks to us not agreeing with an approach, I may give it another shot on Q3 but right now im focusing in delivering the most rpcs i can until there.
Yes, it is! |
|
Also guys, I want to refact the tests for this PR as it seems to not cover all those cases where the rpc interface can fail, but for that i really wish for #794 to be merged before to void more rework... |
| @@ -19,7 +19,7 @@ pub struct RpcRequest { | |||
| pub method: String, | |||
|
|
|||
| /// The parameters for the method, as an array of json values. | |||
There was a problem hiding this comment.
nit: I think the comment should be updated, maybe "an optional array of json values" ?
There was a problem hiding this comment.
Yes, nice catch, regarding the new doc; the whole parameter should be a Json value by itself because we expect both an array and an object.
There was a problem hiding this comment.
that then make the whole statement of it being only array of json values wrong. Maybe sonething around "JSON value (array or object)"
|
Needs rebase.
Since this depends on #794 and will go through some major changes, I recommend changing back to draft. |
|
done! |
Description and Notes
Some time ago i was messing with the server trying to fix some pains that i had developing methods on it and i encountered some points to upgrade.
4839dc6 - fixes #827 by matching errors and returning constant values, i also mapped some custom error codes to internal errors as I understood that were allowed by the spec.
29220da- Adds named and null parameters support, I also reviewed some
Options in internal rpc methods that actually had internal defaults, created a getter for that case.fix #827
fix #704
How to verify the changes you have done?
Pushed some extensive tests regarding request and result parsing and behavior, checking that calls are accepted when expected and when refused we assert the error response.
Contributor Checklist
just pcc(recommended but slower)just lint-features '-- -D warnings' && cargo test --releaseFinally, you are encouraged to sign all your commits (it proves authorship and guards against tampering—see How (and why) to sign Git commits and GitHub's guide to signing commits).