Use explicit arguments for internal `suggest_scan_ranges` helper

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Jack Grigg 2023-07-12 03:56:37 +01:00
parent ed4b6dc9b9
commit 2c0acac1bd
2 changed files with 6 additions and 7 deletions

View File

@ -57,7 +57,7 @@ use zcash_client_backend::{
data_api::{ data_api::{
self, self,
chain::{BlockSource, CommitmentTreeRoot}, chain::{BlockSource, CommitmentTreeRoot},
scanning::ScanRange, scanning::{ScanPriority, ScanRange},
BlockMetadata, DecryptedTransaction, NullifierQuery, PoolType, Recipient, ScannedBlock, BlockMetadata, DecryptedTransaction, NullifierQuery, PoolType, Recipient, ScannedBlock,
SentTransaction, ShieldedProtocol, WalletCommitmentTrees, WalletRead, WalletWrite, SentTransaction, ShieldedProtocol, WalletCommitmentTrees, WalletRead, WalletWrite,
SAPLING_SHARD_HEIGHT, SAPLING_SHARD_HEIGHT,
@ -173,7 +173,7 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> WalletRead for W
} }
fn suggest_scan_ranges(&self) -> Result<Vec<ScanRange>, Self::Error> { fn suggest_scan_ranges(&self) -> Result<Vec<ScanRange>, Self::Error> {
wallet::scanning::suggest_scan_ranges(self.conn.borrow(), None) wallet::scanning::suggest_scan_ranges(self.conn.borrow(), ScanPriority::Historic)
.map_err(SqliteClientError::from) .map_err(SqliteClientError::from)
} }

View File

@ -75,7 +75,7 @@ pub(crate) fn priority_code(priority: &ScanPriority) -> i64 {
pub(crate) fn suggest_scan_ranges( pub(crate) fn suggest_scan_ranges(
conn: &rusqlite::Connection, conn: &rusqlite::Connection,
min_priority: Option<ScanPriority>, min_priority: ScanPriority,
) -> Result<Vec<ScanRange>, SqliteClientError> { ) -> Result<Vec<ScanRange>, SqliteClientError> {
let mut stmt_scan_ranges = conn.prepare_cached( let mut stmt_scan_ranges = conn.prepare_cached(
"SELECT block_range_start, block_range_end, priority "SELECT block_range_start, block_range_end, priority
@ -84,9 +84,8 @@ pub(crate) fn suggest_scan_ranges(
ORDER BY priority DESC, block_range_end DESC", ORDER BY priority DESC, block_range_end DESC",
)?; )?;
let mut rows = stmt_scan_ranges.query(named_params![ let mut rows =
":min_priority": priority_code(&min_priority.unwrap_or(ScanPriority::Historic)) stmt_scan_ranges.query(named_params![":min_priority": priority_code(&min_priority)])?;
])?;
let mut result = vec![]; let mut result = vec![];
while let Some(row) = rows.next()? { while let Some(row) = rows.next()? {
@ -1066,7 +1065,7 @@ mod tests {
// Check that the scanned range has been properly persisted // Check that the scanned range has been properly persisted
assert_matches!( assert_matches!(
suggest_scan_ranges(&db_data.conn, Some(Scanned)), suggest_scan_ranges(&db_data.conn, Scanned),
Ok(scan_ranges) if scan_ranges == vec![ Ok(scan_ranges) if scan_ranges == vec![
scan_range((sap_active + 300)..(sap_active + 310), FoundNote), scan_range((sap_active + 300)..(sap_active + 310), FoundNote),
scan_range((sap_active + 310)..(sap_active + 320), Scanned) scan_range((sap_active + 310)..(sap_active + 320), Scanned)