Add descriptor code sample#77
Conversation
✅ Deploy Preview for awesome-golick-685c88 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
|
|
||
|
|
||
| // Wrap the derived key with the "wpkh()" string to produce a descriptor text | ||
| if let Secret(key, _, _) = derived_xprv_descriptor_key { |
There was a problem hiding this comment.
A bit cleaner way to do this is to use the bip84 template, details here:
https://docs.rs/bdk/0.15.0/bdk/descriptor/template/struct.Bip84.html
There was a problem hiding this comment.
I think the example in Bip84 template is useful to show how we can use bitcoin::utill to do the same thing. Where as here we wanna show how to use bdk api to do it. I was looking for the same and ended up doing it this way in my rpc tutorial, to only use things exposed in bdk.
I am still not fully satisfied with the amount of code it needs to create descriptors. And probably there's room to compact this out further.
There was a problem hiding this comment.
I also have another version with the code below:
pub fn mnemonic_to_xprv(network: &Network, mnemonic_words: &str) -> ExtendedPrivKey {
let mnemonic = Mnemonic::parse(mnemonic_words).unwrap();
let xkey: ExtendedKey = mnemonic.into_extended_key().unwrap();
let xprv = xkey.into_xprv(*network).unwrap();
xprv
}
let wallet_name = wallet_name_from_descriptor(
Bip84(xpriv.clone(), KeychainKind::External),
Some(Bip84(*xpriv, KeychainKind::Internal)),
*network,
&Secp256k1::new()
).unwrap();
println!("mnemonic: {}\n\nrecv desc (pub key): {:#?}\n\nchng desc (pub key): {:#?}",
mnemonic_words,
wallet.get_descriptor_for_keychain(KeychainKind::External).to_string(),
wallet.get_descriptor_for_keychain(KeychainKind::Internal).to_string());I can change this PR to this version, but this one requires a wallet instance to be created before the descriptors are extracted.
There was a problem hiding this comment.
Ah I see. I think I missunderstood @notmandatory 's comment. Yes it makes sense to use Bip84 template derivation instead of manually wrapping in wpkh string.
This will be a good modification to have..
There was a problem hiding this comment.
I updated the PR with this code in 60b72fe
rajarshimaitra
left a comment
There was a problem hiding this comment.
Concept ACK 4d3c467
It does make sense to expose the descriptor generation code in getting started page.
I found few more improvements that can be made in other part of the doc. Probably will open a separate PR for that.
Tested that the code works.
Just one nit.
There was a problem hiding this comment.
tACK e2da710
Changes looks good. Would be great to have this code in the tutorial #77 (comment).
|
PR updated with the code suggested in #77 (comment) |
|
Is it possible to add this to the |
|
@ConorOkus I added this code to the |
|
Looks like this one is ready to go but needs a final rebase. Sorry for the long delay! |
|
No problem. Rebased. |
There's a
Descriptorsection inGetting Startedpage, but there is no code showing how to use descriptors with BDK.This PR adds a code example. This is based on this video.
But the video uses BDK 0.10.
This code uses the latest version, 0.15.