-
Notifications
You must be signed in to change notification settings - Fork 49
Add keychain and derivation index to unspent list #75
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
Open
berserker-systems
wants to merge
1
commit into
RGB-Tools:master
Choose a base branch
from
deedsats:s/ownership
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,27 @@ | ||
| use super::*; | ||
|
|
||
| #[cfg(feature = "electrum")] | ||
| fn check_unspents_derivation(wallet: &Wallet, unspents: &[Unspent]) { | ||
| for unspent in unspents.iter().filter(|u| u.utxo.exists) { | ||
| let keychain = match unspent.utxo.keychain.unwrap() { | ||
| UtxoKeychain::Colored => KeychainKind::External, | ||
| UtxoKeychain::Vanilla => KeychainKind::Internal, | ||
| }; | ||
| let derived_spk = wallet | ||
| .bdk_wallet() | ||
| .public_descriptor(keychain) | ||
| .at_derivation_index(unspent.utxo.derivation_index.unwrap()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests currently only cover Taproot wallets. Would you mind adding a |
||
| .unwrap() | ||
| .script_pubkey(); | ||
| let txid: bdk_wallet::bitcoin::Txid = unspent.utxo.outpoint.txid.parse().unwrap(); | ||
| let tx = wallet.bdk_wallet().get_tx(txid).unwrap(); | ||
| let actual_spk = tx.tx_node.tx.output[unspent.utxo.outpoint.vout as usize] | ||
| .script_pubkey | ||
| .clone(); | ||
| assert_eq!(derived_spk, actual_spk); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "electrum")] | ||
| #[test] | ||
| #[parallel] | ||
|
|
@@ -31,6 +53,10 @@ fn success() { | |
| let unspent_list_all = party.list_unspents(false); | ||
| assert_eq!(unspent_list_all.len(), 1); | ||
| assert!(unspent_list_all.iter().all(|u| !u.utxo.colorable)); | ||
| assert!(unspent_list_all.iter().all( | ||
| |u| u.utxo.keychain == Some(UtxoKeychain::Vanilla) && u.utxo.derivation_index.is_some() | ||
| )); | ||
| check_unspents_derivation(&party.wallet, &unspent_list_all); | ||
|
|
||
| party.create_utxos_default(); | ||
|
|
||
|
|
@@ -51,6 +77,19 @@ fn success() { | |
| .count(), | ||
| 1 | ||
| ); | ||
| let colorable_unspents: Vec<&Unspent> = unspent_list_all | ||
| .iter() | ||
| .filter(|u| u.utxo.colorable) | ||
| .collect(); | ||
| assert!(colorable_unspents.iter().all( | ||
| |u| u.utxo.keychain == Some(UtxoKeychain::Colored) && u.utxo.derivation_index.is_some() | ||
| )); | ||
| let derivation_indexes: HashSet<Option<u32>> = colorable_unspents | ||
| .iter() | ||
| .map(|u| u.utxo.derivation_index) | ||
| .collect(); | ||
| assert_eq!(derivation_indexes.len(), colorable_unspents.len()); | ||
| check_unspents_derivation(&party.wallet, &unspent_list_all); | ||
| let mut settled_allocations = vec![]; | ||
| unspent_list_settled | ||
| .iter() | ||
|
|
@@ -222,6 +261,21 @@ fn success() { | |
| .count(), | ||
| 1 | ||
| ); | ||
| // pending (exists = false) UTXOs are not in the bdk graph yet so their keychain and | ||
| // derivation index are unknown, while all existing UTXOs in the same response have them | ||
| assert!( | ||
| unspent_list_all | ||
| .iter() | ||
| .filter(|u| !u.utxo.exists) | ||
| .all(|u| u.utxo.keychain.is_none() && u.utxo.derivation_index.is_none()) | ||
| ); | ||
| assert!( | ||
| unspent_list_all | ||
| .iter() | ||
| .filter(|u| u.utxo.exists) | ||
| .all(|u| u.utxo.keychain.is_some() && u.utxo.derivation_index.is_some()) | ||
| ); | ||
| check_unspents_derivation(&party.wallet, &unspent_list_all); | ||
| let mut pending_allocations = vec![]; | ||
| let mut settled_allocations = vec![]; | ||
| unspent_list_all | ||
|
|
||
Oops, something went wrong.
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.
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.
list_output()iterates all spent + unspent outputs; that feels heavy for everylist_unspentscall. Could we enrich colored UTXOs withget_tx+derivation_of_spkand keepinternal_unspents()for vanilla? That should also handle almost-spent colored UTXOs without a full graph walk.