Skip to content

Commit

Permalink
add sync_from_scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Feb 5, 2025
1 parent 3ec46b6 commit d861cab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ impl<L2C: Layer2Cache> WalletCache<L2C> {
res
}

pub fn sync_from_scratch<I: Indexer, K, D: Descriptor<K>, L2: Layer2<Cache = L2C>>(
&mut self,
descriptor: &WalletDescr<K, D, L2::Descr>,
indexer: &I,
) -> MayError<(), Vec<I::Error>> {
let res = indexer.create::<K, D, L2>(descriptor);
let (ok, err) = res.split();
*self = ok;
self.mark_dirty();
MayError { ok: (), err }
}

Check warning on line 350 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L340-L350

Added lines #L340 - L350 were not covered by tests

pub fn addresses_on(&self, keychain: Keychain) -> &BTreeSet<WalletAddr> {
self.addr.get(&keychain).unwrap_or_else(|| {
panic!("keychain #{keychain} is not supported by the wallet descriptor")
Expand Down Expand Up @@ -547,6 +559,10 @@ impl<K, D: Descriptor<K>, L2: Layer2> Wallet<K, D, L2> {
self.cache.update::<I, K, D, L2>(&self.descr, indexer).map(|_| ())
}

pub fn sync_from_scratch<I: Indexer>(&mut self, indexer: &I) -> MayError<(), Vec<I::Error>> {
self.cache.sync_from_scratch::<I, K, D, L2>(&self.descr, indexer).map(|_| ())
}

Check warning on line 564 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L562-L564

Added lines #L562 - L564 were not covered by tests

pub fn to_deriver(&self) -> D
where
D: Clone,
Expand Down

0 comments on commit d861cab

Please sign in to comment.