diff --git a/components/zcash_address/src/kind/unified/ivk.rs b/components/zcash_address/src/kind/unified/ivk.rs index fa613faf3..7b776b000 100644 --- a/components/zcash_address/src/kind/unified/ivk.rs +++ b/components/zcash_address/src/kind/unified/ivk.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; -use zcash_protocol::constants; use core::convert::{TryFrom, TryInto}; +use zcash_protocol::constants; use super::{ private::{SealedContainer, SealedItem}, diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index e86ddb67a..133dfa3fc 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -733,6 +733,73 @@ pub(crate) fn get_unified_full_viewing_keys( Ok(res) } +fn parse_account_row( + row: &rusqlite::Row<'_>, + params: &P, +) -> Result { + let account_name = row.get("name")?; + let account_uuid = AccountUuid(row.get("uuid")?); + let kind = parse_account_source( + row.get("account_kind")?, + row.get("hd_seed_fingerprint")?, + row.get("hd_account_index")?, + row.get("has_spend_key")?, + row.get("key_source")?, + )?; + + let ufvk_str: Option = row.get("ufvk")?; + let viewing_key = if let Some(ufvk_str) = ufvk_str { + ViewingKey::Full(Box::new( + UnifiedFullViewingKey::decode(params, &ufvk_str).map_err(|e| { + SqliteClientError::CorruptedData(format!( + "Could not decode unified full viewing key for account {}: {}", + account_uuid.0, e + )) + })?, + )) + } else { + let uivk_str: String = row.get("uivk")?; + ViewingKey::Incoming(Box::new( + UnifiedIncomingViewingKey::decode(params, &uivk_str).map_err(|e| { + SqliteClientError::CorruptedData(format!( + "Could not decode unified incoming viewing key for account {}: {}", + account_uuid.0, e + )) + })?, + )) + }; + + Ok(Account { + name: account_name, + uuid: account_uuid, + kind, + viewing_key, + }) +} + +pub(crate) fn get_account( + conn: &rusqlite::Connection, + params: &P, + account_uuid: AccountUuid, +) -> Result, SqliteClientError> { + let mut stmt = conn.prepare_cached( + r#" + SELECT name, uuid, account_kind, + hd_seed_fingerprint, hd_account_index, key_source, + ufvk, uivk, has_spend_key + FROM accounts + WHERE uuid = :account_uuid + "#, + )?; + + let mut rows = stmt.query_and_then::<_, SqliteClientError, _, _>( + named_params![":account_uuid": account_uuid.0], + |row| parse_account_row(row, params), + )?; + + rows.next().transpose() +} + /// Returns the account id corresponding to a given [`UnifiedFullViewingKey`], /// if any. pub(crate) fn get_account_for_ufvk( @@ -782,50 +849,6 @@ pub(crate) fn get_account_for_ufvk( } } -fn parse_account_row( - row: &rusqlite::Row<'_>, - params: &P, -) -> Result { - let account_name = row.get("name")?; - let account_uuid = AccountUuid(row.get("uuid")?); - let kind = parse_account_source( - row.get("account_kind")?, - row.get("hd_seed_fingerprint")?, - row.get("hd_account_index")?, - row.get("has_spend_key")?, - row.get("key_source")?, - )?; - - let ufvk_str: Option = row.get("ufvk")?; - let viewing_key = if let Some(ufvk_str) = ufvk_str { - ViewingKey::Full(Box::new( - UnifiedFullViewingKey::decode(params, &ufvk_str).map_err(|e| { - SqliteClientError::CorruptedData(format!( - "Could not decode unified full viewing key for account {}: {}", - account_uuid.0, e - )) - })?, - )) - } else { - let uivk_str: String = row.get("uivk")?; - ViewingKey::Incoming(Box::new( - UnifiedIncomingViewingKey::decode(params, &uivk_str).map_err(|e| { - SqliteClientError::CorruptedData(format!( - "Could not decode unified incoming viewing key for account {}: {}", - account_uuid.0, e - )) - })?, - )) - }; - - Ok(Account { - name: account_name, - uuid: account_uuid, - kind, - viewing_key, - }) -} - /// Returns the account id corresponding to a given [`SeedFingerprint`] /// and [`zip32::AccountId`], if any. pub(crate) fn get_derived_account( @@ -1929,29 +1952,6 @@ pub(crate) fn get_account_uuid( .ok_or(SqliteClientError::AccountUnknown) } -pub(crate) fn get_account( - conn: &rusqlite::Connection, - params: &P, - account_uuid: AccountUuid, -) -> Result, SqliteClientError> { - let mut stmt = conn.prepare_cached( - r#" - SELECT name, uuid, account_kind, - hd_seed_fingerprint, hd_account_index, key_source, - ufvk, uivk, has_spend_key - FROM accounts - WHERE uuid = :account_uuid - "#, - )?; - - let mut rows = stmt.query_and_then::<_, SqliteClientError, _, _>( - named_params![":account_uuid": account_uuid.0], - |row| parse_account_row(row, params), - )?; - - rows.next().transpose() -} - /// Returns the minimum and maximum heights of blocks in the chain which may be scanned. pub(crate) fn chain_tip_height( conn: &rusqlite::Connection,