Merge commit 'refs/pull/409/head' of github.com:bitcoindevkit/bdk

This commit is contained in:
Steve Myers 2021-08-19 14:08:05 +02:00
commit 0e10952b80
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
5 changed files with 16 additions and 0 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `RpcBlockchain` in the `AnyBlockchain` struct to allow using Rpc backend where `AnyBlockchain` is used (eg `bdk-cli`) - Added `RpcBlockchain` in the `AnyBlockchain` struct to allow using Rpc backend where `AnyBlockchain` is used (eg `bdk-cli`)
- Removed hard dependency on `tokio`. - Removed hard dependency on `tokio`.
- Added `flush` method to the `Database` trait to explicitly flush to disk latest changes on the db.
### Wallet ### Wallet

View File

@ -233,6 +233,10 @@ impl Database for AnyDatabase {
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> { fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> {
impl_inner_method!(AnyDatabase, self, increment_last_index, keychain) impl_inner_method!(AnyDatabase, self, increment_last_index, keychain)
} }
fn flush(&mut self) -> Result<(), Error> {
impl_inner_method!(AnyDatabase, self, flush)
}
} }
impl BatchOperations for AnyBatch { impl BatchOperations for AnyBatch {

View File

@ -367,6 +367,10 @@ impl Database for Tree {
Ok(val) Ok(val)
}) })
} }
fn flush(&mut self) -> Result<(), Error> {
Ok(Tree::flush(self).map(|_| ())?)
}
} }
impl BatchDatabase for Tree { impl BatchDatabase for Tree {

View File

@ -419,6 +419,10 @@ impl Database for MemoryDatabase {
Ok(*value) Ok(*value)
} }
fn flush(&mut self) -> Result<(), Error> {
Ok(())
}
} }
impl BatchDatabase for MemoryDatabase { impl BatchDatabase for MemoryDatabase {

View File

@ -134,6 +134,9 @@ pub trait Database: BatchOperations {
/// ///
/// It should insert and return `0` if not present in the database /// It should insert and return `0` if not present in the database
fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>; fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>;
/// Force changes to be written to disk
fn flush(&mut self) -> Result<(), Error>;
} }
/// Trait for a database that supports batch operations /// Trait for a database that supports batch operations