Skip to content

Add missing v18 wallet methods #237

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

Merged
merged 2 commits into from
Jun 13, 2025

Conversation

jamillambert
Copy link
Collaborator

Add getreceivedbylabel, listreceivedbylabel and getdescriptorinfo methods, models and tests.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I don't think we should have arguments to client functions that are optional, unless we need them for some test. E.g I hacked impl_client_v18__list_received_by_label and was able to remove all three args.

Comment on lines 267 to 277
let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();
let label = "test-label";
let _ = node.client.new_address_with_label(label).unwrap();

// Send some coins to the label
let amount = Amount::from_sat(10_000);
let address = node.client.new_address_with_label(label).unwrap();
let address = address.assume_checked();
let _ = node.client.send_to_address(&address, amount).unwrap();
node.mine_a_block();

let json: ListReceivedByLabel = node.client.list_received_by_label(None, None, None).expect("listreceivedbylabel");
let model: Result<mtype::ListReceivedByLabel, ListReceivedByLabelError> = json.into_model();
let model = model.unwrap();
assert!(model.0.iter().any(|item| item.label == label));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this cleaner?

    let node = Node::with_wallet(Wallet::Default, &[]);
    node.fund_wallet();
    let label = "test-label";

    // Send some coins to the label
    let amount = Amount::from_sat(10_000);
    let address = node.client.new_address_with_label(label).unwrap().assume_checked();
    let _ = node.client.send_to_address(&address, amount).unwrap();
    node.mine_a_block();

    let json: ListReceivedByLabel = node.client.list_received_by_label().expect("listreceivedbylabel");
    let model: Result<mtype::ListReceivedByLabel, ListReceivedByLabelError> = json.into_model();
    let model = model.unwrap();
    assert!(model.0.iter().any(|item| item.label == label));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed.

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ListReceivedByLabelItem {
/// Only returned if imported addresses were involved in transaction.
pub involves_watchonly: Option<bool>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub involves_watchonly: Option<bool>,
pub involves_watch_only: Option<bool>,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure of this but we have one instance already: is_watch_only. If you feel strongly you could change them both.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah core is inconsistent e.g. as one word This functionality is only intended for use with non-watchonly addresses., but also with a dash enforced watch-only wallet. And also as involvesWatchonly even though all other RPC return variables are all lowercase.

I think with an _ fits better with the rest of the crate, so I changed it as suggested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we shouldn't follow too closely what Core does re word splitting, we have a totally different philosophy here.

let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();
let label = "test-label";
let _ = node.client.new_address_with_label(label).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was from a previous version of the test, removed now.

Comment on lines 235 to 236
let address = node.client.new_address_with_label(label).unwrap();
let address = address.assume_checked();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let address = node.client.new_address_with_label(label).unwrap();
let address = address.assume_checked();
let address = node.client.new_address_with_label(label).unwrap().assume_checked();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 242 to 243
let model = model.unwrap();
assert!(model.0 == amount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let model = model.unwrap();
assert!(model.0 == amount);
assert!(model.unwrap().0 == amount);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to assert_eq! too, the assert! was from a previous iteration that was >= amount in case there were already funds before the send to address.

let model: Result<mtype::ListReceivedByLabel, ListReceivedByLabelError> = json.into_model();
let model = model.unwrap();
assert!(model.0.iter().any(|item| item.label == label));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you used my suggestion here but didn't follow along in wallet__get_received_by_label__modelled, my bad I thought you'd notice that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got thoroughly confused just then, I swear I changed this, but then realised that it was wallet__list_received_by_label__modelled. They are so similar I think my brain just merged them into one. Definitely my bad I missed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No stress, I got confused too actually when checking it.

Add `getreceivedbylabel`, `listreceivedbylabel` and `getdescriptorinfo`
methods, models and tests.
Reorganising the reexports alphabetically, no other changes.
Copy link
Collaborator Author

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes all made

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ef5dda8

@tcharding tcharding merged commit 1a524eb into rust-bitcoin:master Jun 13, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants