Skip to content

Commit

Permalink
added generic wallet errors for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Feb 23, 2024
1 parent 453e62c commit ba0b06b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions zcash_client_backend/src/data_api/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,41 @@ pub trait BlockSource {
with_block: F,
) -> Result<(), error::Error<WalletErrT, Self::Error>>
where
F: FnMut(CompactBlock) -> Result<(), error::Error<WalletErrT, Self::Error>>;
F: FnMut(
CompactBlock,
)
-> Result<(), error::Error<WalletErrT, error::Error<WalletErrT, Self::Error>>>;
}

pub trait BlockCache: BlockSource {
/// Returns a range of compact blocks from the cache.
fn read(&self, range: &ScanRange) -> Result<Vec<CompactBlock>, Self::Error>;
fn read<WalletErrT>(
&self,
range: &ScanRange,
) -> Result<Vec<CompactBlock>, error::Error<WalletErrT, Self::Error>>;

/// Returns the height of highest block known to the block cache, within a specified range.
/// If `range` is `None`, returns the tip of the entire cache.
fn cache_tip(&self, range: Option<&ScanRange>) -> Result<Option<BlockHeight>, Self::Error>;
fn cache_tip<WalletErrT>(
&self,
range: Option<&ScanRange>,
) -> Result<Option<BlockHeight>, error::Error<WalletErrT, Self::Error>>;

/// Inserts a set of compact blocks into the block cache.
/// Returns a `JoinHandle` for async implementations.
fn insert(&self, compact_blocks: Vec<CompactBlock>) -> JoinHandle<()>;

/// Removes all cached blocks above a specified block height.
fn truncate(&self, block_height: BlockHeight) -> Result<(), Self::Error>;
fn truncate<WalletErrT>(
&self,
block_height: BlockHeight,
) -> Result<(), error::Error<WalletErrT, Self::Error>>;

/// Mark a range of blocks as scanned for cache removal.
fn mark_as_scanned(&self, range: &ScanRange) -> Result<(), Self::Error>;
fn mark_as_scanned<WalletErrT>(
&self,
range: &ScanRange,
) -> Result<(), error::Error<WalletErrT, Self::Error>>;

/// Deletes all blocks marked as scanned from the block cache.
/// Returns a `JoinHandle` for async implementations.
Expand Down

0 comments on commit ba0b06b

Please sign in to comment.