From: Steve Myers Date: Mon, 8 Mar 2021 05:54:30 +0000 (-0800) Subject: [wallet] Add fetch_index() helper function X-Git-Tag: v0.6.0~23 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/%22example_cli/enum.FromScriptError.html?a=commitdiff_plain;h=fef61762757ee9a6d1d2d579b0c5fcf43a66f860;p=bdk [wallet] Add fetch_index() helper function --- diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 88831d38..29070bd3 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -967,6 +967,20 @@ where Ok(index) } + fn fetch_index(&self, keychain: KeychainKind) -> Result { + 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,