]> Untitled Git - bdk/commitdiff
[wallet] Add fetch_index() helper function
authorSteve Myers <steve@notmandatory.org>
Mon, 8 Mar 2021 05:54:30 +0000 (21:54 -0800)
committerSteve Myers <steve@notmandatory.org>
Mon, 15 Mar 2021 15:58:07 +0000 (08:58 -0700)
src/wallet/mod.rs

index 88831d388d923f8c9c90cd7743ce4cd85b1c3fe4..29070bd3e7b9951e16df7f99243a21517d337595 100644 (file)
@@ -967,6 +967,20 @@ where
         Ok(index)
     }
 
+    fn fetch_index(&self, keychain: KeychainKind) -> Result<u32, Error> {
+        let (descriptor, keychain) = self._get_descriptor_for_keychain(keychain);
+        let index = match descriptor.is_deriveable() {
+            false => Some(0),
+            true => self.database.borrow_mut().get_last_index(keychain)?,
+        };
+
+        if let Some(i) = index {
+            Ok(i)
+        } else {
+            self.fetch_and_increment_index(keychain)
+        }
+    }
+
     fn cache_addresses(
         &self,
         keychain: KeychainKind,