Skip to content

Commit

Permalink
Merge pull request #18 from BP-WG/cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky authored Feb 27, 2024
2 parents 3e848d8 + 52f9376 commit 54c39fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/indexers/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Indexer for BlockingClient {
&self,
_descr: &WalletDescr<K, D, L2::Descr>,
_cache: &mut WalletCache<L2::Cache>,
) -> (usize, Vec<Self::Error>) {
) -> MayError<usize, Vec<Self::Error>> {
todo!()
}
}
2 changes: 1 addition & 1 deletion src/indexers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ pub trait Indexer {
&self,
descr: &WalletDescr<K, D, L2::Descr>,
cache: &mut WalletCache<L2::Cache>,
) -> (usize, Vec<Self::Error>);
) -> MayError<usize, Vec<Self::Error>>;
}
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<K, D: Descriptor<K>, L2: Layer2> Runtime<D, K, L2> {
}
pub fn set_name(&mut self, name: String) { self.wallet.set_name(name) }

pub fn sync<I: Indexer>(&mut self, indexer: &I) -> Result<(), Vec<I::Error>> {
pub fn sync<I: Indexer>(&mut self, indexer: &I) -> Result<usize, Vec<I::Error>> {
self.wallet.update(indexer).into_result()
}

Expand Down
20 changes: 10 additions & 10 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ pub struct WalletData<L2: Layer2Data> {
)]
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct WalletCache<L2: Layer2Cache> {
pub(crate) last_block: MiningInfo,
pub(crate) last_change: NormalIndex,
pub(crate) headers: BTreeSet<BlockInfo>,
pub(crate) tx: BTreeMap<Txid, WalletTx>,
pub(crate) utxo: BTreeSet<Outpoint>,
pub(crate) addr: BTreeMap<Keychain, BTreeSet<WalletAddr>>,
pub(crate) layer2: L2,
pub last_block: MiningInfo,
pub last_change: NormalIndex,
pub headers: BTreeSet<BlockInfo>,
pub tx: BTreeMap<Txid, WalletTx>,
pub utxo: BTreeSet<Outpoint>,
pub addr: BTreeMap<Keychain, BTreeSet<WalletAddr>>,
pub layer2: L2,
}

impl<L2: Layer2Cache> Default for WalletCache<L2> {
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<L2C: Layer2Cache> WalletCache<L2C> {
&mut self,
descriptor: &WalletDescr<K, D, L2::Descr>,
indexer: &I,
) -> (usize, Vec<I::Error>) {
) -> MayError<usize, Vec<I::Error>> {
indexer.update::<K, D, L2>(descriptor, self)
}

Expand Down Expand Up @@ -322,8 +322,8 @@ impl<K, D: Descriptor<K>, L2: Layer2> Wallet<K, D, L2> {

pub fn set_name(&mut self, name: String) { self.data.name = name; }

pub fn update<B: Indexer>(&mut self, blockchain: &B) -> MayError<(), Vec<B::Error>> {
WalletCache::with::<_, K, _, L2>(&self.descr, blockchain).map(|cache| self.cache = cache)
pub fn update<B: Indexer>(&mut self, indexer: &B) -> MayError<usize, Vec<B::Error>> {
self.cache.update::<B, K, D, L2>(&self.descr, indexer)
}

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

0 comments on commit 54c39fb

Please sign in to comment.