Skip to content

Commit 300526b

Browse files
committed
chore(chain): rename fields in KeychainTxOutIndex struct
Rename `descriptor_ids_to_descriptors` to `descriptors`. Rename `descriptor_ids_to_keychains` to `keychains`.
1 parent 78e3264 commit 300526b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

crates/chain/src/keychain/txout_index.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ pub struct KeychainTxOutIndex<K> {
219219
// a keychain, we return it with the highest-ranked keychain with it. We rank keychains by
220220
// `Ord`, therefore the keychain set is a `BTreeSet`. The earliest keychain variant (according
221221
// to `Ord`) has precedence.
222-
descriptor_ids_to_keychains: HashMap<DescriptorId, BTreeSet<K>>,
222+
keychains: HashMap<DescriptorId, BTreeSet<K>>,
223223
// descriptor_id -> descriptor map
224224
// This is a "monotone" map, meaning that its size keeps growing, i.e., we never delete
225225
// descriptors from it. This is useful for revealing spks for descriptors that don't have
226226
// keychains associated.
227-
descriptor_ids_to_descriptors: BTreeMap<DescriptorId, Descriptor<DescriptorPublicKey>>,
227+
descriptors: BTreeMap<DescriptorId, Descriptor<DescriptorPublicKey>>,
228228
// last revealed indexes
229229
last_revealed: BTreeMap<DescriptorId, u32>,
230230
// lookahead settings for each keychain
@@ -246,7 +246,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
246246
// We want to reveal spks for descriptors that aren't tracked by any keychain, and
247247
// so we call reveal with descriptor_id
248248
let desc = self
249-
.descriptor_ids_to_descriptors
249+
.descriptors
250250
.get(&descriptor_id)
251251
.cloned()
252252
.expect("descriptors are added monotonically, scanned txout descriptor ids must have associated descriptors");
@@ -299,8 +299,8 @@ impl<K> KeychainTxOutIndex<K> {
299299
Self {
300300
inner: SpkTxOutIndex::default(),
301301
keychains_to_descriptor_ids: BTreeMap::new(),
302-
descriptor_ids_to_keychains: HashMap::new(),
303-
descriptor_ids_to_descriptors: BTreeMap::new(),
302+
keychains: HashMap::new(),
303+
descriptors: BTreeMap::new(),
304304
last_revealed: BTreeMap::new(),
305305
lookahead,
306306
}
@@ -311,7 +311,7 @@ impl<K> KeychainTxOutIndex<K> {
311311
impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
312312
/// Get the highest-ranked keychain that is currently associated with the given `desc_id`.
313313
fn keychain_of_desc_id(&self, desc_id: &DescriptorId) -> Option<&K> {
314-
let keychains = self.descriptor_ids_to_keychains.get(desc_id)?;
314+
let keychains = self.keychains.get(desc_id)?;
315315
keychains.iter().next()
316316
}
317317

@@ -473,7 +473,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
473473
{
474474
self.keychains_to_descriptor_ids.iter().map(|(k, desc_id)| {
475475
let descriptor = self
476-
.descriptor_ids_to_descriptors
476+
.descriptors
477477
.get(desc_id)
478478
.expect("descriptor id cannot be associated with keychain without descriptor");
479479
(k, descriptor)
@@ -510,19 +510,18 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
510510
// is designed to track one descriptor per keychain (however different keychains can
511511
// share the same descriptor)
512512
let _is_keychain_removed = self
513-
.descriptor_ids_to_keychains
513+
.keychains
514514
.get_mut(&old_desc_id)
515515
.expect("we must have already inserted this descriptor")
516516
.remove(&keychain);
517517
debug_assert!(_is_keychain_removed);
518518
}
519519

520-
self.descriptor_ids_to_keychains
520+
self.keychains
521521
.entry(desc_id)
522522
.or_default()
523523
.insert(keychain.clone());
524-
self.descriptor_ids_to_descriptors
525-
.insert(desc_id, descriptor.clone());
524+
self.descriptors.insert(desc_id, descriptor.clone());
526525
self.replenish_lookahead(&keychain, self.lookahead);
527526

528527
changeset
@@ -537,7 +536,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
537536
self.keychains_to_descriptor_ids
538537
.get(keychain)
539538
.map(|desc_id| {
540-
self.descriptor_ids_to_descriptors
539+
self.descriptors
541540
.get(desc_id)
542541
.expect("descriptor id cannot be associated with keychain without descriptor")
543542
})
@@ -571,7 +570,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
571570
let descriptor_id = self.keychains_to_descriptor_ids.get(keychain).copied();
572571
if let Some(descriptor_id) = descriptor_id {
573572
let descriptor = self
574-
.descriptor_ids_to_descriptors
573+
.descriptors
575574
.get(&descriptor_id)
576575
.expect("descriptor id cannot be associated with keychain without descriptor");
577576

@@ -606,7 +605,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
606605
) -> Option<SpkIterator<Descriptor<DescriptorPublicKey>>> {
607606
let desc_id = self.keychains_to_descriptor_ids.get(keychain)?;
608607
let desc = self
609-
.descriptor_ids_to_descriptors
608+
.descriptors
610609
.get(desc_id)
611610
.cloned()
612611
.expect("descriptor id cannot be associated with keychain without descriptor");
@@ -620,11 +619,10 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
620619
self.keychains_to_descriptor_ids
621620
.iter()
622621
.map(|(k, desc_id)| {
623-
let desc = self
624-
.descriptor_ids_to_descriptors
625-
.get(desc_id)
626-
.cloned()
627-
.expect("descriptor id cannot be associated with keychain without descriptor");
622+
let desc =
623+
self.descriptors.get(desc_id).cloned().expect(
624+
"descriptor id cannot be associated with keychain without descriptor",
625+
);
628626
(k.clone(), SpkIterator::new(desc))
629627
})
630628
.collect()
@@ -712,7 +710,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
712710
pub fn next_index(&self, keychain: &K) -> Option<(u32, bool)> {
713711
let descriptor_id = self.keychains_to_descriptor_ids.get(keychain)?;
714712
let descriptor = self
715-
.descriptor_ids_to_descriptors
713+
.descriptors
716714
.get(descriptor_id)
717715
.expect("descriptor id cannot be associated with keychain without descriptor");
718716
Some(self.next_index_with_descriptor(descriptor))
@@ -872,7 +870,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
872870
None => return (None, ChangeSet::default()),
873871
};
874872
let desc = self
875-
.descriptor_ids_to_descriptors
873+
.descriptors
876874
.get(descriptor_id)
877875
.cloned()
878876
.expect("descriptors are added monotonically, scanned txout descriptor ids must have associated descriptors");
@@ -901,7 +899,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
901899
}
902900
};
903901
let descriptor = self
904-
.descriptor_ids_to_descriptors
902+
.descriptors
905903
.get(&descriptor_id)
906904
.expect("descriptor id cannot be associated with keychain without descriptor");
907905
let (next_index, _) = self.next_index_with_descriptor(descriptor);

0 commit comments

Comments
 (0)