Skip to content

Commit 8897a20

Browse files
committed
refactor(store)!: change Store's method and error names
The changes in this commit were motivated due to a bug in the `StoreFile` which caused old data to be lost if the file was `open` instead of created and new data was appended. The bugfix later motivated a general name cleanup in StoreFile's methods and errors and some minor changes in their signatures. IterError was replaced by StoreError, which now includes the `IterError` variants, making it replaceable. The new StoreFile methods are: - create: create file in write only mode or fail if file exists. - load: open existing file, check integrity of content and retrieve Store. - append: add new changesets to Store. Do nothing if changeset is empty. - dump: aggregate and retrieve all stored changesets in store. - load_or_create: load if file exists, create if not, and retrieve Store. refactor: update all call names to bdk_file_store::Store methods
1 parent 0f104cc commit 8897a20

File tree

12 files changed

+324
-256
lines changed

12 files changed

+324
-256
lines changed

crates/file_store/src/entry_iter.rs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::StoreError;
12
use bincode::Options;
23
use std::{
34
fs::File,
@@ -37,7 +38,7 @@ impl<T> Iterator for EntryIter<'_, T>
3738
where
3839
T: serde::de::DeserializeOwned,
3940
{
40-
type Item = Result<T, IterError>;
41+
type Item = Result<T, StoreError>;
4142

4243
fn next(&mut self) -> Option<Self::Item> {
4344
if self.finished {
@@ -63,7 +64,7 @@ where
6364
}
6465
}
6566
self.db_file.seek(io::SeekFrom::Start(pos_before_read))?;
66-
Err(IterError::Bincode(*e))
67+
Err(StoreError::Bincode(*e))
6768
}
6869
}
6970
})()
@@ -80,29 +81,3 @@ impl<T> Drop for EntryIter<'_, T> {
8081
}
8182
}
8283
}
83-
84-
/// Error type for [`EntryIter`].
85-
#[derive(Debug)]
86-
pub enum IterError {
87-
/// Failure to read from the file.
88-
Io(io::Error),
89-
/// Failure to decode data from the file.
90-
Bincode(bincode::ErrorKind),
91-
}
92-
93-
impl core::fmt::Display for IterError {
94-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
95-
match self {
96-
IterError::Io(e) => write!(f, "io error trying to read entry {}", e),
97-
IterError::Bincode(e) => write!(f, "bincode error while reading entry {}", e),
98-
}
99-
}
100-
}
101-
102-
impl From<io::Error> for IterError {
103-
fn from(value: io::Error) -> Self {
104-
IterError::Io(value)
105-
}
106-
}
107-
108-
impl std::error::Error for IterError {}

0 commit comments

Comments
 (0)