-
Notifications
You must be signed in to change notification settings - Fork 324
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
Get keychain for script #1201
Get keychain for script #1201
Conversation
a6433a1
to
bfd1bd4
Compare
bfd1bd4
to
3674bd2
Compare
3674bd2
to
e2ec6ff
Compare
let addr = taproot_wallet.get_address(New); | ||
let script = addr.script_pubkey(); | ||
let keychain = segwit_wallet.which_keychain_derived(&script); | ||
assert!(keychain.is_none()); |
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.
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);
}
This is the exact same thing as bdk/crates/bdk/src/wallet/mod.rs Lines 822 to 827 in ba76247
|
Description
This PR fixes #1042.
Notes to the reviewers
Changelog notice
It adds a method
which_keychain_derived
that 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 fmt
andcargo clippy
before committingNew Features:
Bugfixes: