-
Notifications
You must be signed in to change notification settings - Fork 32
Follow up to v21 TODO #293
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
base: master
Are you sure you want to change the base?
Conversation
f414272
to
6876edc
Compare
integration_test/tests/wallet.rs
Outdated
let request = ImportDescriptorsRequest { | ||
desc: descriptor, | ||
timestamp: serde_json::Value::String("now".to_string()), | ||
timestamp: serde_json::Value::Number(serde_json::Number::from(start_time)), | ||
}; | ||
|
||
let _: ImportDescriptors = node.client.import_descriptors(&[request]).expect("importdescriptors"); |
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.
We want to check that the list isn't empty, right? Otherwise all the good work above is not validated.
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.
True. When I checked the list it turns out the RPC was returning an error message "Cannot import descriptor without private keys to a wallet with private keys enabled". So I have modified the test to create a descriptor with a private key.
integration_test/tests/wallet.rs
Outdated
@@ -314,17 +314,37 @@ fn wallet__import_address() { | |||
#[cfg(not(feature = "v20_and_below"))] | |||
fn wallet__import_descriptors() { | |||
use node::{serde_json, ImportDescriptorsRequest}; | |||
use std::time::{SystemTime, UNIX_EPOCH}; | |||
|
|||
let node = Node::with_wallet(Wallet::None, &[]); | |||
let wallet_name = "desc_wallet"; | |||
node.client.create_wallet_with_descriptors(wallet_name).expect("create descriptor wallet"); |
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.
Perhaps feature gate and then we only need to call the macro that defines this function in v21 and v22, making the default descriptor wallet thing explicit.
#[cfg(feature = "v22_and_below")]
node.client.create_wallet_with_descriptors(wallet_name).expect("create descriptor wallet");
// v23 onwards uses descriptor wallets by default.
#[cfg(not(feature = "v22_and_below"))]
node.client.create_wallet(wallet_name).expect("create wallet");
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.
Done
6876edc
to
6e86402
Compare
I added a new commit that addresses #292, I put it before the rewrite of the test, since the test uses the function. This also made one commit redundant, which has been dropped. |
11a0201
to
f0d18f9
Compare
integration_test/tests/util.rs
Outdated
let txindex_info = index_info.0.get("txindex").unwrap(); | ||
let _ = txindex_info.synced; // The synced field is a bool, accessing it validates the JSON deserialization |
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.
It doesn't matter all that much but just for educational purposes this comment is incorrect. Its the unwrap
that validates that we got a non-empty map. Which means that the let index_info: GetIndexInfo ...
line that validates the deserialization. Accessing the field doesn't do anything.
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 removed this line.
client/src/client_sync/v23/wallet.rs
Outdated
/// Calls `createwallet` with `wallet` as the only argument. | ||
/// In v23 and later this creates a descriptor wallet. Use `create_legacy_wallet` to create | ||
/// a legacy wallet. |
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.
/// Calls `createwallet` with `wallet` as the only argument. | |
/// In v23 and later this creates a descriptor wallet. Use `create_legacy_wallet` to create | |
/// a legacy wallet. | |
/// Calls `createwallet` with `wallet` as the only argument. | |
/// | |
/// In v23 and later this creates a descriptor wallet. Use `create_legacy_wallet` to create | |
/// a legacy wallet. |
Bit nit-picky and I wouldn't bother rebasing just for this.
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.
Done
/// > 5. avoid_reuse (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind. | ||
/// > 6. descriptors (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation | ||
/// > 7. load_on_startup (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged. | ||
pub fn create_descriptor_wallet(&self, wallet: &str) -> Result<CreateWallet> { |
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 is waaay better, nice one man.
let _txid = node.client.send_to_address(&address, amount).expect("sendtoaddress"); | ||
|
||
// 3. Get the descriptor from the private key. | ||
let raw_descriptor = format!("wpkh({})", privkey.to_wif()); |
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.
For my education, why does the descriptor use wpkh
but the address above is a p2pkh address?
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 one bit was copied from another test 😊. I have changed it now so both are native SegWit.
integration_test/tests/wallet.rs
Outdated
let request = ImportDescriptorsRequest { | ||
desc: descriptor, | ||
timestamp: serde_json::Value::String("now".to_string()), | ||
timestamp: serde_json::Value::Number(serde_json::Number::from(start_time)), |
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.
nit: This whole thing is pretty ugly, would be nicer if the ImportDescriptorRequest
had a constructor that took start_time
and did the serde wrapping. Totally not required, just an observation.
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.
Created a constructor in a new commit, and also moved the imports to the top of the file.
let info = node.client.get_descriptor_info(&raw_descriptor).expect("get_descriptor_info"); | ||
let descriptor = format!("{}#{}", raw_descriptor, info.checksum); |
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.
Clever!
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 took me a bit to figure out. It kept complaining that that the descriptor had no private key when it looked like it should.
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'm ok to merge this as is if you want or if you want. I'll give you a chance to polish it if you feel like it.
2635d52
to
7defbf1
Compare
I made changes to address all of your comments. |
7defbf1
to
02216a7
Compare
Rebased to remove merge conflict. |
02216a7
to
a6ddd2e
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 a6ddd2e
Needs rebase. |
The current test passes if the returned map is empty. Update the test to access the values and ensure the deserialization worked.
Change the client macro for v21 to match the style of the v23 definition. Only use this for v21 and v22 where the default wallet is a legacy wallet. Change the test to use the new function. Add a comment to the v23 definition clarifying why the legacy wallet function is needed.
The current test of the RPC always returns true due to scanning for the timestamp `now`. Move imports to the top of the file and allow unused. Improve the test to be more thorough by creating a new address and then scanning for the descriptor at a later time.
a6ddd2e
to
e396ad0
Compare
Rebased. It was the adding full stops patch that caused it. |
There were a couple of points in the review of #289 that needed to be addressed.
Improve the tests as suggested, and add a comment to the rustdocs.
Redefine the
create_wallet
client macro so that for v21 and v22 where the default is a legacy wallet there is a separate function to create a descriptor wallet. Similarly for v23 and above where the default is a descriptor wallet there is a separate function to create a legacy wallet.Closes #292