Get keychain for script#1201
Closed
vladimirfomene wants to merge 2 commits intobitcoindevkit:masterfrom
Closed
Conversation
a6433a1 to
bfd1bd4
Compare
bfd1bd4 to
3674bd2
Compare
3674bd2 to
e2ec6ff
Compare
54 tasks
55 tasks
| let addr = taproot_wallet.get_address(New); | ||
| let script = addr.script_pubkey(); | ||
| let keychain = segwit_wallet.which_keychain_derived(&script); | ||
| assert!(keychain.is_none()); |
Collaborator
There was a problem hiding this comment.
In addition to checking the keychain, we could possibly also check the correct spk index is returned from which_keychain_derived.
diff
fn test_which_keychain_derived_script() {
let (mut segwit_wallet, _) = get_funded_wallet(get_test_wpkh());
let addr = segwit_wallet.get_address(New);
let script = addr.script_pubkey();
let keychain = segwit_wallet.which_keychain_derived(&script).unwrap();
assert_eq!(keychain.0, KeychainKind::External);
let (mut taproot_wallet, _) = get_funded_wallet(get_test_tr_single_sig());
let addr = taproot_wallet.get_address(New);
let script = addr.script_pubkey();
let keychain = segwit_wallet.which_keychain_derived(&script);
assert!(keychain.is_none());
+
+ // find correct derivation index from spk
+ let desc = get_test_tr_single_sig_xprv();
+ let mut wallet = Wallet::new_no_persist(desc, None, Network::Testnet).unwrap();
+ let spk = wallet.get_address(New).address.script_pubkey();
+ let (_k, i) = wallet.which_keychain_derived(&spk).unwrap();
+ assert_eq!(i, &0);
+
+ // reveal more addresses. the last revealed index should now be 10.
+ for _ in 0..10 {
+ let _ = wallet.get_address(New);
+ }
+ let spk = wallet.get_address(Peek(10)).address.script_pubkey();
+ let (_k, i) = wallet.which_keychain_derived(&spk).unwrap();
+ assert_eq!(i, &10);
}
Member
|
This is the exact same thing as bdk/crates/bdk/src/wallet/mod.rs Lines 822 to 827 in ba76247 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes #1042.
Notes to the reviewers
Changelog notice
It adds a method
which_keychain_derivedthat tells us which keychain derived a particular script. This is helpful when trying to figure out if a particular script belongs to our wallet.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
Bugfixes: