-
Notifications
You must be signed in to change notification settings - Fork 31
Implement importmulti method and test #263
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
Conversation
client/src/client_sync/v17/mod.rs
Outdated
/// Args for the `importmulti` method | ||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] | ||
pub struct ImportMultiRequest { |
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.
A question for @tcharding what is the reason for these argument structs being in client
and not in types
?
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.
Because they are used with the client
and if one writes their own client
(which I hope folk will) and just depend on types
we don't want a bunch of 'random' stuff in there. On the other hand wsince we have the client-sync
feature we could expose them and then writers of a client
could still depend on our client to grab them? I'd be open to that. (By expose I mean put them in lib.rs
or someplace so they are not hidden by the feature.)
pub warnings: Option<Vec<String>>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
/// The error. | ||
pub error: Option<JsonRpcError>, |
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.
I don't understand the use of #[serde(default, skip_serializing_if...
, this is the result of the RPC call and therefore deserialized
from json.
If we want fields that are None
in the result types to be omitted from the serialization this should be done crate wide and not have different functionality for different RPC calls. I believe core always omits them?
@tcharding thoughts?
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.
My understanding is, and it may be wrong, that this is a no-op because serde already omits None
when serializing options. I'm guessing you got this from an LLM @GideonBature? I've seen LLMs add this when using them.
I don't think we should use this attribute unless there is some explicit reason to, and if so, like you say @jamillambert it would then have to be done crate wide. And we definitely don't want to do that unless there is a very good reason.
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.
my bad, was not supposed to be for result, only for args.
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.
My understanding is, and it may be wrong, that this is a no-op because serde already omits
None
when serializing options. I'm guessing you got this from an LLM @GideonBature? I've seen LLMs add this when using them.I don't think we should use this attribute unless there is some explicit reason to, and if so, like you say @jamillambert it would then have to be done crate wide. And we definitely don't want to do that unless there is a very good reason.
yes... you are right.
afcf58d
to
b05f196
Compare
Effected suggestions. Also, introduced another type for v18 upwards, which has the warnings field. The v17 doesn't have the warnings field, had to confirm that with the code in core and found out that every thing remains same except that v17 doesn't return the warnings fields in it's response. Also, updated the test accordingly. |
01eeced
to
9d0995a
Compare
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.
Everything looks good except I'd like to see the test improved upon please. Its great that you are testing so thoroughly its just a bit unclear by reading the test exactly what it is testing.
Since we are primarily interested in proving the shape of the returned type perhaps structure the test, and include code comments, around this idea.
E.g, Do some set up and comment what is expected then assert that we get what is expected.
Also please comment if things are version specific, ATM it looks like descriptors are supported all the way back to v17 but the docs don't support that, or is it just undocumented?
Thanks
#[serde(rename = "scriptPubKey", skip_serializing_if = "Option::is_none")] | ||
pub script_pub_key: Option<ImportMultiScriptPubKey>, |
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.
This arg is required by v17 and v29 so shouldn't be Option
, right?
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.
yes, it is required by v17 - v29. Why I made it Option is because for v18 - v29 either scriptPubkey or descriptor is required but not both.
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.
ooo, I missed that. Thanks
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.
Needs rename to script_pubkey
.
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.
will open a patch PR for the renaming.
Yes, descriptors is not mentioned in v17, yet the test still passes, prolly will exclude the test using descriptors for v17. |
5b1f2ad
to
cc79a67
Compare
Implemented the changes suggested and also added more cases to the test... |
2096697
to
1c1bb5d
Compare
Remove redundant code from types and args Add comment and field checks to test Add appropriate type for v17 and v18 Make test more explicit and robust Resolve Bip125Replaceable import issue Resolve assert checks for v17
Format code changes Format code Format code
d6de385
to
ec24420
Compare
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.
ACK ec24420
Good effort man, that test is nice. |
Thank you. :). |
303d8e4 Rename script_pub_key to script_pubkey (GideonBature) Pull request description: This is a follow up PR, that implements the suggestion given in this [comment](#263 (comment)) for PR #263 to rename `script_pub_key` to `script_pubkey` for readability purpose. ACKs for top commit: tcharding: ACK 303d8e4 Tree-SHA512: b6f5f0def9947f8dcfbe2464ffdff295a084dfe634d5e081276ca79b84c31a7569a45db5ba6c8386372ab35ae33cf6154439832fa809b31ee0ba4d7c1aad2568
The JSON-RPC method
importmulti
does return a type. We want to test this to catch any changes in behavior in future Core versions.This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.
Ref: #116