]> Untitled Git - bdk/commitdiff
Add flush method to Database trait
authorRiccardo Casatta <riccardo@casatta.it>
Tue, 27 Jul 2021 09:38:11 +0000 (11:38 +0200)
committerRiccardo Casatta <riccardo@casatta.it>
Tue, 3 Aug 2021 10:33:31 +0000 (12:33 +0200)
src/database/any.rs
src/database/keyvalue.rs
src/database/memory.rs
src/database/mod.rs

index cc5fcc1c9b893cef83e4aa80d99cd393914ae6c8..dbdd2d09e7d56af85544a58861b6f863157d6b78 100644 (file)
@@ -233,6 +233,10 @@ impl Database for AnyDatabase {
     fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error> {
         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 {
index 9978497dbe41af7f8f633bd27cb49c98945daed4..2da92f2285262a0e02f427bda72ced26a521fd3a 100644 (file)
@@ -367,6 +367,10 @@ impl Database for Tree {
             Ok(val)
         })
     }
+
+    fn flush(&mut self) -> Result<(), Error> {
+        Ok(Tree::flush(self).map(|_| ())?)
+    }
 }
 
 impl BatchDatabase for Tree {
index df56ef634a5880f28cc121792b324d55fe3d2001..c42518dbe20dd730891f3a354310ae4cf28abc8a 100644 (file)
@@ -419,6 +419,10 @@ impl Database for MemoryDatabase {
 
         Ok(*value)
     }
+
+    fn flush(&mut self) -> Result<(), Error> {
+        Ok(())
+    }
 }
 
 impl BatchDatabase for MemoryDatabase {
index 217153fda5213dc2527efe3c2308feef6c51c8e4..38c6d3bdf56e91970257a71eebb8a7cd46c0c881 100644 (file)
@@ -134,6 +134,9 @@ pub trait Database: BatchOperations {
     ///
     /// It should insert and return `0` if not present in the database
     fn increment_last_index(&mut self, keychain: KeychainKind) -> Result<u32, Error>;
+
+    /// Force changes to be written to disk, returning the number of bytes written
+    fn flush(&mut self) -> Result<(), Error>;
 }
 
 /// Trait for a database that supports batch operations