Type Definition example_bitcoind_rpc_polling::ChangeSet
source · pub(crate) type ChangeSet = (ChangeSet, ChangeSet<ConfirmationTimeHeightAnchor, ChangeSet<Keychain>>);From: github-actions
Return a reference to the internal SpkTxOutIndex.
Return a reference to the internal SpkTxOutIndex.
Get a reference to the set of indexed outpoints.
Return a reference to the internal map of the keychain to descriptors.
Add a keychain to the trackerâs txout_index with a descriptor to derive addresses.
Refer to new for more information on the lookahead.
Store lookahead scripts until target_index.
This does not change the lookahead setting.
Generates script pubkey iterators for every keychain. The iterators iterate over all
+
Generates script pubkey iterators for every keychain. The iterators iterate over all
derivable script pubkeys.
Generates a script pubkey iterator for the given keychainâs descriptor (if it exists). The
+
Generates a script pubkey iterator for the given keychainâs descriptor (if it exists). The
iterator iterates over all derivable scripts of the keychainâs descriptor.
This will panic if the keychain does not exist.
Convenience method to get revealed_spks_of_keychain of all keychains.
Iterates over the script pubkeys revealed by this index under keychain.
Get the next derivation index for keychain. The next index is the index after the last revealed
+
Convenience method to get revealed_spks_of_keychain of all keychains.
Iterates over the script pubkeys revealed by this index under keychain.
Get the next derivation index for keychain. The next index is the index after the last revealed
derivation index.
The second field in the returned tuple represents whether the next derivation index is new. There are two scenarios where the next derivation index is reused (not new):
@@ -65,11 +65,11 @@ There are two scenarios where the next derivation index is reused (not new):Not checking the second field of the tuple may result in address reuse.
Panics if the keychain does not exist.
Get the last derivation index that is revealed for each keychain.
+Get the last derivation index that is revealed for each keychain.
Keychains with no revealed indices will not be included in the returned BTreeMap.
Get the last derivation index revealed for keychain.
Convenience method to call Self::reveal_to_target on multiple keychains.
Reveals script pubkeys of the keychainâs descriptor up to and including the
+
Get the last derivation index revealed for keychain.
Convenience method to call Self::reveal_to_target on multiple keychains.
Reveals script pubkeys of the keychainâs descriptor up to and including the
target_index.
If the target_index cannot be reached (due to the descriptor having no wildcard and/or
the target_index is in the hardened index range), this method will make a best-effort and
@@ -79,7 +79,7 @@ reveal up to the last possible index.
Panics if keychain does not exist.
Attempts to reveal the next script pubkey for keychain.
Attempts to reveal the next script pubkey for keychain.
Returns the derivation index of the revealed script pubkey, the revealed script pubkey and a
super::ChangeSet which represents changes in the last revealed index (if any).
When a new script cannot be revealed, we return the last revealed script and an empty @@ -90,7 +90,7 @@ pubkeys are revealed, then both of these will be empty.
Panics if the keychain does not exist.
Gets the next unused script pubkey in the keychain. I.e., the script pubkey with the lowest +
Gets the next unused script pubkey in the keychain. I.e., the script pubkey with the lowest index that has not been used yet.
This will derive and reveal a new script pubkey if no more unused script pubkeys exist.
If the descriptor has no wildcard and already has a used script pubkey or if a descriptor @@ -98,24 +98,24 @@ has used all scripts up to the derivation bounds, then the last derived script p returned.
Panics if keychain has never been added to the index
Marks the script pubkey at index as used even though the tracker hasnât seen an output with it.
+
Marks the script pubkey at index as used even though the tracker hasnât seen an output with it.
This only has an effect when the index had been added to self already and was unused.
Returns whether the index was initially present as unused.
This is useful when you want to reserve a script pubkey for something but donât want to add
the transaction output using it to the index yet. Other callers will consider index on
keychain used until you call unmark_used.
Undoes the effect of mark_used. Returns whether the index is inserted back into
+
Undoes the effect of mark_used. Returns whether the index is inserted back into
unused.
Note that if self has scanned an output with this script pubkey, then this will have no
effect.
Iterates over all unused script pubkeys for a keychain stored in the index.
Iterates over all the [OutPoint] that have a TxOut with a script pubkey derived from
+
Iterates over all unused script pubkeys for a keychain stored in the index.
Iterates over all the [OutPoint] that have a TxOut with a script pubkey derived from
keychain.
Returns the highest derivation index of the keychain where KeychainTxOutIndex has
+
Returns the highest derivation index of the keychain where KeychainTxOutIndex has
found a [TxOut] with itâs script pubkey.
Returns the highest derivation index of each keychain that KeychainTxOutIndex has found
+
Returns the highest derivation index of each keychain that KeychainTxOutIndex has found
a [TxOut] with itâs script pubkey.
Applies the derivation changeset to the KeychainTxOutIndex, extending the number of
+
Applies the derivation changeset to the KeychainTxOutIndex, extending the number of
derived scripts per keychain, as specified in the changeset.
Get a reference to the set of indexed outpoints.
Iterate over all known txouts that spend to tracked script pubkeys.
diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/example_bitcoind_rpc_polling/type.ChangeSet.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/example_bitcoind_rpc_polling/type.ChangeSet.html index cacf4366b1..c650b3daca 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/example_bitcoind_rpc_polling/type.ChangeSet.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/example_bitcoind_rpc_polling/type.ChangeSet.html @@ -1 +1 @@ -pub(crate) type ChangeSet = (ChangeSet, ChangeSet<ConfirmationTimeHeightAnchor, ChangeSet<Keychain>>);pub(crate) type ChangeSet = (ChangeSet, ChangeSet<ConfirmationTimeHeightAnchor, ChangeSet<Keychain>>);pub fn planned_utxos<A: Anchor, O: ChainOracle, K: Clone + CanDerive>(
graph: &KeychainTxGraph<A>,
chain: &O,
assets: &Assets<K>
) -> Result<Vec<(Plan<K>, FullTxOut<A>)>, O::Error>pub(crate) type ChangeSet = (ChangeSet, ChangeSet<ConfirmationTimeHeightAnchor, ChangeSet<Keychain>>);pub(crate) type ChangeSet = (ChangeSet, ChangeSet<ConfirmationTimeHeightAnchor, ChangeSet<Keychain>>);use crate::{
collections::*,
indexed_tx_graph::Indexer,
@@ -740,9 +736,11 @@
fn next_store_index(&self, keychain: &K) -> u32 {
self.inner()
.all_spks()
- .range((keychain.clone(), u32::MIN)..(keychain.clone(), u32::MAX))
+ // This range is filtering out the spks with a keychain different than
+ // `keychain`. We don't use filter here as range is more optimized.
+ .range((keychain.clone(), u32::MIN)..(keychain.clone(), u32::MAX))
.last()
- .map_or(0, |((_, v), _)| *v + 1)
+ .map_or(0, |((_, index), _)| *index + 1)
}
/// Generates script pubkey iterators for every `keychain`. The iterators iterate over all
@@ -896,51 +894,45 @@
let has_wildcard = descriptor.has_wildcard();
let target_index = if has_wildcard { target_index } else { 0 };
- let next_reveal_index = self.last_revealed.get(keychain).map_or(0, |v| *v + 1);
+ let next_reveal_index = self
+ .last_revealed
+ .get(keychain)
+ .map_or(0, |index| *index + 1);
debug_assert!(next_reveal_index + self.lookahead >= self.next_store_index(keychain));
- // if we need to reveal new indices, the latest revealed index goes here
- let mut reveal_to_index = None;
-
- // if the target is not yet revealed, but is already stored (due to lookahead), we need to
- // set the `reveal_to_index` as target here (as the `for` loop below only updates
- // `reveal_to_index` for indexes that are NOT stored)
- if next_reveal_index <= target_index && target_index < next_reveal_index + self.lookahead {
- reveal_to_index = Some(target_index);
+ // If the target_index is already revealed, we are done
+ if next_reveal_index > target_index {
+ return (
+ SpkIterator::new_with_range(
+ descriptor.clone(),
+ next_reveal_index..next_reveal_index,
+ ),
+ super::ChangeSet::default(),
+ );
}
- // we range over indexes that are not stored
+ // We range over the indexes that are not stored and insert their spks in the index.
+ // Indexes from next_reveal_index to next_reveal_index + lookahead are already stored (due
+ // to lookahead), so we only range from next_reveal_index + lookahead to target + lookahead
let range = next_reveal_index + self.lookahead..=target_index + self.lookahead;
for (new_index, new_spk) in SpkIterator::new_with_range(descriptor, range) {
let _inserted = self
.inner
.insert_spk((keychain.clone(), new_index), new_spk);
- debug_assert!(_inserted, "must not have existing spk",);
-
- // everything after `target_index` is stored for lookahead only
- if new_index <= target_index {
- reveal_to_index = Some(new_index);
- }
+ debug_assert!(_inserted, "must not have existing spk");
+ debug_assert!(
+ has_wildcard || new_index == 0,
+ "non-wildcard descriptors must not iterate past index 0"
+ );
}
- match reveal_to_index {
- Some(index) => {
- let _old_index = self.last_revealed.insert(keychain.clone(), index);
- debug_assert!(_old_index < Some(index));
- (
- SpkIterator::new_with_range(descriptor.clone(), next_reveal_index..index + 1),
- super::ChangeSet(core::iter::once((keychain.clone(), index)).collect()),
- )
- }
- None => (
- SpkIterator::new_with_range(
- descriptor.clone(),
- next_reveal_index..next_reveal_index,
- ),
- super::ChangeSet::default(),
- ),
- }
+ let _old_index = self.last_revealed.insert(keychain.clone(), target_index);
+ debug_assert!(_old_index < Some(target_index));
+ (
+ SpkIterator::new_with_range(descriptor.clone(), next_reveal_index..target_index + 1),
+ super::ChangeSet(core::iter::once((keychain.clone(), target_index)).collect()),
+ )
}
/// Attempts to reveal the next script pubkey for `keychain`.