Skip to content

Commit

Permalink
wallet: save cache upon updates. Closes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Sep 7, 2024
1 parent c58fed0 commit 1aba927
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/indexers/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ impl Indexer for Client {
descriptor: &WalletDescr<K, D, L2::Descr>,
) -> MayError<WalletCache<L2::Cache>, Vec<Self::Error>> {
let mut cache = WalletCache::new_nonsync(descriptor.generator());
self.update::<K, D, L2>(descriptor, &mut cache).map(|_| cache)
}

Check warning on line 71 in src/indexers/electrum.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/electrum.rs#L70-L71

Added lines #L70 - L71 were not covered by tests

fn update<K, D: Descriptor<K>, L2: Layer2>(
&self,
descriptor: &WalletDescr<K, D, L2::Descr>,
cache: &mut WalletCache<L2::Cache>,
) -> MayError<usize, Vec<Self::Error>> {

Check warning on line 77 in src/indexers/electrum.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/electrum.rs#L73-L77

Added lines #L73 - L77 were not covered by tests
let mut errors = Vec::<ElectrumError>::new();

let mut address_index = BTreeMap::new();
Expand Down Expand Up @@ -271,15 +279,7 @@ impl Indexer for Client {
.insert(wallet_addr.expect_transmute());
}

if errors.is_empty() { MayError::ok(cache) } else { MayError::err(cache, errors) }
}

fn update<K, D: Descriptor<K>, L2: Layer2>(
&self,
_descr: &WalletDescr<K, D, L2::Descr>,
_cache: &mut WalletCache<L2::Cache>,
) -> MayError<usize, Vec<Self::Error>> {
todo!()
if errors.is_empty() { MayError::ok(0) } else { MayError::err(0, errors) }

Check warning on line 282 in src/indexers/electrum.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/electrum.rs#L282

Added line #L282 was not covered by tests
}

fn publish(&self, tx: &Tx) -> Result<(), Self::Error> {
Expand Down
18 changes: 9 additions & 9 deletions src/indexers/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ impl Indexer for Client {
descriptor: &WalletDescr<K, D, L2::Descr>,
) -> MayError<WalletCache<L2::Cache>, Vec<Self::Error>> {
let mut cache = WalletCache::new_nonsync(descriptor.generator());
self.update::<K, D, L2>(descriptor, &mut cache).map(|_| cache)
}

Check warning on line 201 in src/indexers/esplora.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/esplora.rs#L200-L201

Added lines #L200 - L201 were not covered by tests

fn update<K, D: Descriptor<K>, L2: Layer2>(
&self,
descriptor: &WalletDescr<K, D, L2::Descr>,
cache: &mut WalletCache<L2::Cache>,
) -> MayError<usize, Vec<Self::Error>> {

Check warning on line 207 in src/indexers/esplora.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/esplora.rs#L203-L207

Added lines #L203 - L207 were not covered by tests
let mut errors = vec![];

let mut address_index = BTreeMap::new();
Expand Down Expand Up @@ -302,15 +310,7 @@ impl Indexer for Client {
.insert(wallet_addr.expect_transmute());
}

if errors.is_empty() { MayError::ok(cache) } else { MayError::err(cache, errors) }
}

fn update<K, D: Descriptor<K>, L2: Layer2>(
&self,
_descr: &WalletDescr<K, D, L2::Descr>,
_cache: &mut WalletCache<L2::Cache>,
) -> MayError<usize, Vec<Self::Error>> {
todo!()
if errors.is_empty() { MayError::ok(0) } else { MayError::err(0, errors) }

Check warning on line 313 in src/indexers/esplora.rs

View check run for this annotation

Codecov / codecov/patch

src/indexers/esplora.rs#L313

Added line #L313 was not covered by tests
}

fn publish(&self, tx: &Tx) -> Result<(), Self::Error> { self.inner.broadcast(tx) }
Expand Down
8 changes: 1 addition & 7 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,7 @@ impl<K, D: Descriptor<K>, L2: Layer2> Wallet<K, D, L2> {
}

pub fn update<I: Indexer>(&mut self, indexer: &I) -> MayError<(), Vec<I::Error>> {
// Not yet implemented:
// self.cache.update::<B, K, D, L2>(&self.descr, &self.indexer)

WalletCache::with::<_, K, _, L2>(&self.descr, indexer).map(|cache| {
self.cache = cache;
self.cache.mark_dirty();
})
self.cache.update::<I, K, D, L2>(&self.descr, indexer).map(|_| ())

Check warning on line 468 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L468

Added line #L468 was not covered by tests
}

pub fn to_deriver(&self) -> D
Expand Down

0 comments on commit 1aba927

Please sign in to comment.