From f7aa7b2c84ea277ad299ff56e2dfcb03c6e5b89f Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Sun, 2 Oct 2022 09:09:52 -0600 Subject: [PATCH] Upgrade rusqlite to version 0.25 --- Cargo.toml | 2 + zcash_client_sqlite/Cargo.toml | 2 +- zcash_client_sqlite/src/chain.rs | 24 ++--- zcash_client_sqlite/src/chain/init.rs | 4 +- zcash_client_sqlite/src/lib.rs | 8 +- zcash_client_sqlite/src/prepared.rs | 25 ++--- zcash_client_sqlite/src/wallet.rs | 100 +++++++++--------- zcash_client_sqlite/src/wallet/init.rs | 78 +++++++------- .../init/migrations/add_transaction_views.rs | 25 ++--- .../wallet/init/migrations/addresses_table.rs | 4 +- .../wallet/init/migrations/ufvk_support.rs | 20 ++-- zcash_client_sqlite/src/wallet/transact.rs | 8 +- 12 files changed, 143 insertions(+), 157 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cdaea6941..d4e2baa8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,5 @@ zcash_encoding = { path = "components/zcash_encoding" } zcash_note_encryption = { path = "components/zcash_note_encryption" } orchard = { git = "https://github.com/zcash/orchard.git", rev = "33f1c1141e50adb68715f3359bd75378b4756cca" } group = { git = "https://github.com/zkcrypto/group.git", rev = "f61e3e420ed1220c8f1f80988f8c6c5e202d8715" } +schemer = { git = "https://github.com/nuttycom/schemer.git", rev = "6726b60f43f72c6e24a18d31be0ec7d42829e5e1" } +schemer-rusqlite = { git = "https://github.com/nuttycom/schemer.git", rev = "6726b60f43f72c6e24a18d31be0ec7d42829e5e1" } diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 192ba50c1..7644da4ce 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -21,7 +21,7 @@ hdwallet = { version = "0.3.1", optional = true } jubjub = "0.9" protobuf = "~2.27.1" # MSRV 1.52.1 rand_core = "0.6" -rusqlite = { version = "0.24", features = ["bundled", "time"] } +rusqlite = { version = "0.25", features = ["bundled", "time"] } secp256k1 = { version = "0.21" } schemer = "0.2" schemer-rusqlite = "0.2" diff --git a/zcash_client_sqlite/src/chain.rs b/zcash_client_sqlite/src/chain.rs index 80442092d..ce8a4a9a4 100644 --- a/zcash_client_sqlite/src/chain.rs +++ b/zcash_client_sqlite/src/chain.rs @@ -12,7 +12,7 @@ use crate::{error::SqliteClientError, BlockDb}; #[cfg(feature = "unstable")] use { crate::{BlockHash, FsBlockDb}, - rusqlite::{Connection, NO_PARAMS}, + rusqlite::Connection, std::fs::File, std::io::BufReader, std::path::{Path, PathBuf}, @@ -107,7 +107,7 @@ pub(crate) fn blockmetadb_insert( VALUES (?, ?, ?, ?, ?)" )?; - conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?; + conn.execute("BEGIN IMMEDIATE", [])?; let result = block_meta .iter() .map(|m| { @@ -122,11 +122,11 @@ pub(crate) fn blockmetadb_insert( .collect::, _>>(); match result { Ok(_) => { - conn.execute("COMMIT", NO_PARAMS)?; + conn.execute("COMMIT", [])?; Ok(()) } Err(error) => { - match conn.execute("ROLLBACK", NO_PARAMS) { + match conn.execute("ROLLBACK", []) { Ok(_) => Err(error), Err(e) => // Panicking here is probably the right thing to do, because it @@ -145,16 +145,12 @@ pub(crate) fn blockmetadb_insert( pub(crate) fn blockmetadb_get_max_cached_height( conn: &Connection, ) -> Result, rusqlite::Error> { - conn.query_row( - "SELECT MAX(height) FROM compactblocks_meta", - NO_PARAMS, - |row| { - // `SELECT MAX(_)` will always return a row, but it will return `null` if the - // table is empty, which has no integer type. We handle the optionality here. - let h: Option = row.get(0)?; - Ok(h.map(BlockHeight::from)) - }, - ) + conn.query_row("SELECT MAX(height) FROM compactblocks_meta", [], |row| { + // `SELECT MAX(_)` will always return a row, but it will return `null` if the + // table is empty, which has no integer type. We handle the optionality here. + let h: Option = row.get(0)?; + Ok(h.map(BlockHeight::from)) + }) } /// Implements a traversal of `limit` blocks of the filesystem-backed diff --git a/zcash_client_sqlite/src/chain/init.rs b/zcash_client_sqlite/src/chain/init.rs index b5f88e29c..8bb40aec4 100644 --- a/zcash_client_sqlite/src/chain/init.rs +++ b/zcash_client_sqlite/src/chain/init.rs @@ -1,6 +1,4 @@ //! Functions for initializing the various databases. -use rusqlite::NO_PARAMS; - use crate::BlockDb; #[cfg(feature = "unstable")] @@ -32,7 +30,7 @@ pub fn init_cache_database(db_cache: &BlockDb) -> Result<(), rusqlite::Error> { height INTEGER PRIMARY KEY, data BLOB NOT NULL )", - NO_PARAMS, + [], )?; Ok(()) } diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 2083f75ba..02817f80a 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -40,7 +40,7 @@ use std::path::Path; #[cfg(feature = "transparent-inputs")] use std::collections::HashSet; -use rusqlite::{Connection, NO_PARAMS}; +use rusqlite::Connection; use zcash_primitives::{ block::BlockHash, @@ -385,14 +385,14 @@ impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> { where F: FnOnce(&mut Self) -> Result, { - self.wallet_db.conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?; + self.wallet_db.conn.execute("BEGIN IMMEDIATE", [])?; match f(self) { Ok(result) => { - self.wallet_db.conn.execute("COMMIT", NO_PARAMS)?; + self.wallet_db.conn.execute("COMMIT", [])?; Ok(result) } Err(error) => { - match self.wallet_db.conn.execute("ROLLBACK", NO_PARAMS) { + match self.wallet_db.conn.execute("ROLLBACK", []) { Ok(_) => Err(error), Err(e) => // Panicking here is probably the right thing to do, because it diff --git a/zcash_client_sqlite/src/prepared.rs b/zcash_client_sqlite/src/prepared.rs index a61fc1e9a..94887c1ff 100644 --- a/zcash_client_sqlite/src/prepared.rs +++ b/zcash_client_sqlite/src/prepared.rs @@ -271,7 +271,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { (":fee", &fee.map(i64::from)), (":txid", &&txid.as_ref()[..]), ]; - match self.stmt_update_tx_data.execute_named(sql_args)? { + match self.stmt_update_tx_data.execute(sql_args)? { 0 => Ok(false), 1 => Ok(true), _ => unreachable!("txid column is marked as UNIQUE"), @@ -322,10 +322,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { (":prevout_idx", &outpoint.n()), ]; - match self - .stmt_mark_transparent_utxo_spent - .execute_named(sql_args)? - { + match self.stmt_mark_transparent_utxo_spent.execute(sql_args)? { 0 => Ok(false), 1 => Ok(true), _ => unreachable!("tx_outpoint constraint is marked as UNIQUE"), @@ -353,7 +350,7 @@ impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> { ]; self.stmt_insert_received_transparent_utxo - .execute_named(sql_args)?; + .execute(sql_args)?; Ok(self.wallet_db.conn.last_insert_rowid()) } @@ -373,7 +370,7 @@ impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> { (":above_height", &u32::from(height)), ]; - let rows = self.stmt_delete_utxos.execute_named(sql_args)?; + let rows = self.stmt_delete_utxos.execute(sql_args)?; Ok(rows) } @@ -394,7 +391,7 @@ impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> { (":address", &address.encode(&self.wallet_db.params)), ]; - self.stmt_insert_address.execute_named(sql_args)?; + self.stmt_insert_address.execute(sql_args)?; Ok(self.wallet_db.conn.last_insert_rowid()) } @@ -439,7 +436,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { (":is_change", &is_change), ]; - self.stmt_insert_received_note.execute_named(sql_args)?; + self.stmt_insert_received_note.execute(sql_args)?; Ok(NoteId::ReceivedNoteId( self.wallet_db.conn.last_insert_rowid(), @@ -483,7 +480,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { (":output_index", &(output_index as i64)), ]; - match self.stmt_update_received_note.execute_named(sql_args)? { + match self.stmt_update_received_note.execute(sql_args)? { 0 => Ok(false), 1 => Ok(true), _ => unreachable!("tx_output constraint is marked as UNIQUE"), @@ -536,7 +533,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { .map(|m| m.as_slice()), ), ]; - self.stmt_insert_sent_note.execute_named(sql_args)?; + self.stmt_insert_sent_note.execute(sql_args)?; Ok(()) } @@ -568,7 +565,7 @@ impl<'a, P> DataConnStmtCache<'a, P> { (":output_pool", &pool_type.typecode()), (":output_index", &i64::try_from(output_index).unwrap()), ]; - match self.stmt_update_sent_note.execute_named(sql_args)? { + match self.stmt_update_sent_note.execute(sql_args)? { 0 => Ok(false), 1 => Ok(true), _ => unreachable!("tx_output constraint is marked as UNIQUE"), @@ -605,14 +602,14 @@ impl<'a, P> DataConnStmtCache<'a, P> { below_height: BlockHeight, ) -> Result<(), SqliteClientError> { self.stmt_prune_witnesses - .execute(&[u32::from(below_height)])?; + .execute([u32::from(below_height)])?; Ok(()) } /// Marks notes that have not been mined in transactions as expired, up to the given /// block height. pub fn stmt_update_expired(&mut self, height: BlockHeight) -> Result<(), SqliteClientError> { - self.stmt_update_expired.execute(&[u32::from(height)])?; + self.stmt_update_expired.execute([u32::from(height)])?; Ok(()) } } diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 6020943f3..5e73a0fcd 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -8,7 +8,7 @@ //! [`WalletWrite`]: zcash_client_backend::data_api::WalletWrite use group::ff::PrimeField; -use rusqlite::{OptionalExtension, ToSql, NO_PARAMS}; +use rusqlite::{named_params, OptionalExtension, ToSql}; use std::collections::HashMap; use std::convert::TryFrom; @@ -164,7 +164,7 @@ pub fn get_address( FROM addresses WHERE account = ? ORDER BY diversifier_index_be DESC LIMIT 1", - &[u32::from(account)], + [u32::from(account)], |row| row.get(0), )?; @@ -184,7 +184,7 @@ pub(crate) fn get_max_account_id

( ) -> Result, SqliteClientError> { // This returns the most recently generated address. wdb.conn - .query_row("SELECT MAX(account) FROM accounts", NO_PARAMS, |row| { + .query_row("SELECT MAX(account) FROM accounts", [], |row| { let account_id: Option = row.get(0)?; Ok(account_id.map(AccountId::from)) }) @@ -207,12 +207,12 @@ pub(crate) fn add_account_internal Result<(), E> { let ufvk_str: String = key.encode(network); - conn.execute_named( + conn.execute( &format!( "INSERT INTO {} (account, ufvk) VALUES (:account, :ufvk)", accounts_table ), - &[(":account", &::from(account)), (":ufvk", &ufvk_str)], + named_params![":account": &::from(account), ":ufvk": &ufvk_str], )?; // Always derive the default Unified Address for the account. @@ -220,13 +220,13 @@ pub(crate) fn add_account_internal::from(account)), - (":diversifier_index_be", &&idx.0[..]), - (":address", &address_str), + named_params![ + ":account": &::from(account), + ":diversifier_index_be": &&idx.0[..], + ":address": &address_str, ], )?; @@ -240,12 +240,12 @@ pub(crate) fn get_current_address( // This returns the most recently generated address. let addr: Option<(String, Vec)> = wdb .conn - .query_row_named( + .query_row( "SELECT address, diversifier_index_be FROM addresses WHERE account = :account ORDER BY diversifier_index_be DESC LIMIT 1", - &[(":account", &u32::from(account))], + named_params![":account": &u32::from(account)], |row| Ok((row.get(0)?, row.get(1)?)), ) .optional()?; @@ -285,7 +285,7 @@ pub(crate) fn get_transparent_receivers( let mut ua_query = wdb .conn .prepare("SELECT address FROM addresses WHERE account = :account")?; - let mut rows = ua_query.query_named(&[(":account", &u32::from(account))])?; + let mut rows = ua_query.query(named_params![":account": &u32::from(account)])?; while let Some(row) = rows.next()? { let ua_str: String = row.get(0)?; @@ -308,7 +308,7 @@ pub(crate) fn get_transparent_receivers( // Get the UFVK for the account. let ufvk_str: String = wdb.conn.query_row( "SELECT ufvk FROM accounts WHERE account = :account", - &[u32::from(account)], + [u32::from(account)], |row| row.get(0), )?; let ufvk = UnifiedFullViewingKey::decode(&wdb.params, &ufvk_str) @@ -333,7 +333,7 @@ pub(crate) fn get_unified_full_viewing_keys( .conn .prepare("SELECT account, ufvk FROM accounts ORDER BY account ASC")?; - let rows = stmt_fetch_accounts.query_map(NO_PARAMS, |row| { + let rows = stmt_fetch_accounts.query_map([], |row| { let acct: u32 = row.get(0)?; let account = AccountId::from(acct); let ufvk_str: String = row.get(1)?; @@ -366,7 +366,7 @@ pub fn is_valid_account_extfvk( ) -> Result { wdb.conn .prepare("SELECT ufvk FROM accounts WHERE account = ?")? - .query_row(&[u32::from(account).to_sql()?], |row| { + .query_row([u32::from(account).to_sql()?], |row| { row.get(0).map(|ufvk_str: String| { UnifiedFullViewingKey::decode(&wdb.params, &ufvk_str) .map_err(SqliteClientError::CorruptedData) @@ -419,7 +419,7 @@ pub fn get_balance

(wdb: &WalletDb

, account: AccountId) -> Result( "SELECT SUM(value) FROM received_notes INNER JOIN transactions ON transactions.id_tx = received_notes.tx WHERE account = ? AND spent IS NULL AND transactions.block <= ?", - &[u32::from(account), u32::from(anchor_height)], + [u32::from(account), u32::from(anchor_height)], |row| row.get(0).or(Ok(0)), )?; @@ -503,7 +503,7 @@ pub fn get_received_memo

(wdb: &WalletDb

, id_note: i64) -> Result = wdb.conn.query_row( "SELECT memo FROM received_notes WHERE id_note = ?", - &[id_note], + [id_note], |row| row.get(0), )?; @@ -520,7 +520,7 @@ pub(crate) fn get_transaction( let (tx_bytes, block_height): (Vec<_>, BlockHeight) = wdb.conn.query_row( "SELECT raw, block FROM transactions WHERE id_tx = ?", - &[id_tx], + [id_tx], |row| { let h: u32 = row.get(1)?; Ok((row.get(0)?, BlockHeight::from(h))) @@ -561,7 +561,7 @@ pub fn get_sent_memo

(wdb: &WalletDb

, id_note: i64) -> Result = wdb.conn.query_row( "SELECT memo FROM sent_notes WHERE id_note = ?", - &[id_note], + [id_note], |row| row.get(0), )?; @@ -593,18 +593,14 @@ pub fn block_height_extrema

( wdb: &WalletDb

, ) -> Result, rusqlite::Error> { wdb.conn - .query_row( - "SELECT MIN(height), MAX(height) FROM blocks", - NO_PARAMS, - |row| { - let min_height: u32 = row.get(0)?; - let max_height: u32 = row.get(1)?; - Ok(Some(( - BlockHeight::from(min_height), - BlockHeight::from(max_height), - ))) - }, - ) + .query_row("SELECT MIN(height), MAX(height) FROM blocks", [], |row| { + let min_height: u32 = row.get(0)?; + let max_height: u32 = row.get(1)?; + Ok(Some(( + BlockHeight::from(min_height), + BlockHeight::from(max_height), + ))) + }) //.optional() doesn't work here because a failed aggregate function //produces a runtime error, not an empty set of rows. .or(Ok(None)) @@ -638,7 +634,7 @@ pub fn get_tx_height

( wdb.conn .query_row( "SELECT block FROM transactions WHERE txid = ?", - &[txid.as_ref().to_vec()], + [txid.as_ref().to_vec()], |row| row.get(0).map(u32::into), ) .optional() @@ -671,7 +667,7 @@ pub fn get_block_hash

( wdb.conn .query_row( "SELECT hash FROM blocks WHERE height = ?", - &[u32::from(block_height)], + [u32::from(block_height)], |row| { let row_data = row.get::<_, Vec<_>>(0)?; Ok(BlockHash::from_slice(&row_data)) @@ -690,7 +686,7 @@ pub fn get_rewind_height

(wdb: &WalletDb

) -> Result, Sq FROM received_notes n JOIN transactions tx ON tx.id_tx = n.tx WHERE n.spent IS NULL", - NO_PARAMS, + [], |row| { row.get(0) .map(|maybe_height: Option| maybe_height.map(|height| height.into())) @@ -715,13 +711,13 @@ pub(crate) fn rewind_to_height( .ok_or(SqliteClientError::BackendError(Error::SaplingNotActive))?; // Recall where we synced up to previously. - let last_scanned_height = - wdb.conn - .query_row("SELECT MAX(height) FROM blocks", NO_PARAMS, |row| { - row.get(0) - .map(|h: u32| h.into()) - .or_else(|_| Ok(sapling_activation_height - 1)) - })?; + let last_scanned_height = wdb + .conn + .query_row("SELECT MAX(height) FROM blocks", [], |row| { + row.get(0) + .map(|h: u32| h.into()) + .or_else(|_| Ok(sapling_activation_height - 1)) + })?; if block_height < last_scanned_height - PRUNING_HEIGHT { #[allow(deprecated)] @@ -737,7 +733,7 @@ pub(crate) fn rewind_to_height( // Decrement witnesses. wdb.conn.execute( "DELETE FROM sapling_witnesses WHERE block > ?", - &[u32::from(block_height)], + [u32::from(block_height)], )?; // Rewind received notes @@ -750,7 +746,7 @@ pub(crate) fn rewind_to_height( ON tx.id_tx = rn.tx WHERE tx.block IS NOT NULL AND tx.block > ? );", - &[u32::from(block_height)], + [u32::from(block_height)], )?; // Do not delete sent notes; this can contain data that is not recoverable @@ -760,19 +756,19 @@ pub(crate) fn rewind_to_height( // Rewind utxos wdb.conn.execute( "DELETE FROM utxos WHERE height > ?", - &[u32::from(block_height)], + [u32::from(block_height)], )?; // Un-mine transactions. wdb.conn.execute( "UPDATE transactions SET block = NULL, tx_index = NULL WHERE block IS NOT NULL AND block > ?", - &[u32::from(block_height)], + [u32::from(block_height)], )?; // Now that they aren't depended on, delete scanned blocks. wdb.conn.execute( "DELETE FROM blocks WHERE height > ?", - &[u32::from(block_height)], + [u32::from(block_height)], )?; } @@ -806,7 +802,7 @@ pub fn get_commitment_tree

( wdb.conn .query_row_and_then( "SELECT sapling_tree FROM blocks WHERE height = ?", - &[u32::from(block_height)], + [u32::from(block_height)], |row| { let row_data: Vec = row.get(0)?; CommitmentTree::read(&row_data[..]).map_err(|e| { @@ -850,7 +846,7 @@ pub fn get_witnesses

( .conn .prepare("SELECT note, witness FROM sapling_witnesses WHERE block = ?")?; let witnesses = stmt_fetch_witnesses - .query_map(&[u32::from(block_height)], |row| { + .query_map([u32::from(block_height)], |row| { let id_note = NoteId::ReceivedNoteId(row.get(0)?); let wdb: Vec = row.get(1)?; Ok(IncrementalWitness::read(&wdb[..]).map(|witness| (id_note, witness))) @@ -879,7 +875,7 @@ pub fn get_nullifiers

( ON tx.id_tx = rn.spent WHERE block IS NULL", )?; - let nullifiers = stmt_fetch_nullifiers.query_map(NO_PARAMS, |row| { + let nullifiers = stmt_fetch_nullifiers.query_map([], |row| { let account: u32 = row.get(1)?; let nf_bytes: Vec = row.get(2)?; Ok(( @@ -901,7 +897,7 @@ pub(crate) fn get_all_nullifiers

( "SELECT rn.id_note, rn.account, rn.nf FROM received_notes rn", )?; - let nullifiers = stmt_fetch_nullifiers.query_map(NO_PARAMS, |row| { + let nullifiers = stmt_fetch_nullifiers.query_map([], |row| { let account: u32 = row.get(1)?; let nf_bytes: Vec = row.get(2)?; Ok(( diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index b854b369b..a9431f68f 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::fmt; -use rusqlite::{self, types::ToSql, NO_PARAMS}; +use rusqlite::{self, types::ToSql}; use schemer::{Migrator, MigratorError}; use schemer_rusqlite::RusqliteAdapter; use secrecy::SecretVec; @@ -123,7 +123,7 @@ fn init_wallet_db_internal( target_migration: Option, ) -> Result<(), MigratorError> { wdb.conn - .execute("PRAGMA foreign_keys = OFF", NO_PARAMS) + .execute("PRAGMA foreign_keys = OFF", []) .map_err(|e| MigratorError::Adapter(WalletMigrationError::from(e)))?; let adapter = RusqliteAdapter::new(&mut wdb.conn, Some("schemer_migrations".to_string())); adapter.init().expect("Migrations table setup succeeds."); @@ -134,7 +134,7 @@ fn init_wallet_db_internal( .expect("Wallet migration registration should have been successful."); migrator.up(target_migration)?; wdb.conn - .execute("PRAGMA foreign_keys = ON", NO_PARAMS) + .execute("PRAGMA foreign_keys = ON", []) .map_err(|e| MigratorError::Adapter(WalletMigrationError::from(e)))?; Ok(()) } @@ -201,7 +201,7 @@ pub fn init_accounts_table( keys: &HashMap, ) -> Result<(), SqliteClientError> { let mut empty_check = wdb.conn.prepare("SELECT * FROM accounts LIMIT 1")?; - if empty_check.exists(NO_PARAMS)? { + if empty_check.exists([])? { return Err(SqliteClientError::TableNotEmpty); } @@ -213,11 +213,11 @@ pub fn init_accounts_table( } // Insert accounts atomically - wdb.conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?; + wdb.conn.execute("BEGIN IMMEDIATE", [])?; for (account, key) in keys.iter() { wallet::add_account(wdb, *account, key)?; } - wdb.conn.execute("COMMIT", NO_PARAMS)?; + wdb.conn.execute("COMMIT", [])?; Ok(()) } @@ -262,14 +262,14 @@ pub fn init_blocks_table

( sapling_tree: &[u8], ) -> Result<(), SqliteClientError> { let mut empty_check = wdb.conn.prepare("SELECT * FROM blocks LIMIT 1")?; - if empty_check.exists(NO_PARAMS)? { + if empty_check.exists([])? { return Err(SqliteClientError::TableNotEmpty); } wdb.conn.execute( "INSERT INTO blocks (height, hash, time, sapling_tree) VALUES (?, ?, ?, ?)", - &[ + [ u32::from(height).to_sql()?, hash.0.to_sql()?, time.to_sql()?, @@ -283,7 +283,7 @@ pub fn init_blocks_table

( #[cfg(test)] #[allow(deprecated)] mod tests { - use rusqlite::{self, ToSql, NO_PARAMS}; + use rusqlite::{self, ToSql}; use secrecy::Secret; use std::collections::HashMap; use tempfile::NamedTempFile; @@ -412,7 +412,7 @@ mod tests { .conn .prepare("SELECT sql FROM sqlite_schema WHERE type = 'table' ORDER BY tbl_name") .unwrap(); - let mut rows = tables_query.query(NO_PARAMS).unwrap(); + let mut rows = tables_query.query([]).unwrap(); let mut expected_idx = 0; while let Some(row) = rows.next().unwrap() { let sql: String = row.get(0).unwrap(); @@ -519,7 +519,7 @@ mod tests { .conn .prepare("SELECT sql FROM sqlite_schema WHERE type = 'view' ORDER BY tbl_name") .unwrap(); - let mut rows = views_query.query(NO_PARAMS).unwrap(); + let mut rows = views_query.query([]).unwrap(); let mut expected_idx = 0; while let Some(row) = rows.next().unwrap() { let sql: String = row.get(0).unwrap(); @@ -544,7 +544,7 @@ mod tests { extfvk TEXT NOT NULL, address TEXT NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE blocks ( @@ -553,7 +553,7 @@ mod tests { time INTEGER NOT NULL, sapling_tree BLOB NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE transactions ( @@ -566,7 +566,7 @@ mod tests { raw BLOB, FOREIGN KEY (block) REFERENCES blocks(height) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE received_notes ( @@ -586,7 +586,7 @@ mod tests { FOREIGN KEY (spent) REFERENCES transactions(id_tx), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sapling_witnesses ( @@ -598,7 +598,7 @@ mod tests { FOREIGN KEY (block) REFERENCES blocks(height), CONSTRAINT witness_height UNIQUE (note, block) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sent_notes ( @@ -613,7 +613,7 @@ mod tests { FOREIGN KEY (from_account) REFERENCES accounts(account), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; let address = encode_payment_address( @@ -627,7 +627,7 @@ mod tests { wdb.conn.execute( "INSERT INTO accounts (account, extfvk, address) VALUES (?, ?, ?)", - &[ + [ u32::from(account).to_sql()?, extfvk.to_sql()?, address.to_sql()?, @@ -661,7 +661,7 @@ mod tests { address TEXT NOT NULL, transparent_address TEXT NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE blocks ( @@ -670,7 +670,7 @@ mod tests { time INTEGER NOT NULL, sapling_tree BLOB NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE transactions ( @@ -683,7 +683,7 @@ mod tests { raw BLOB, FOREIGN KEY (block) REFERENCES blocks(height) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE received_notes ( @@ -703,7 +703,7 @@ mod tests { FOREIGN KEY (spent) REFERENCES transactions(id_tx), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sapling_witnesses ( @@ -715,7 +715,7 @@ mod tests { FOREIGN KEY (block) REFERENCES blocks(height), CONSTRAINT witness_height UNIQUE (note, block) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sent_notes ( @@ -730,7 +730,7 @@ mod tests { FOREIGN KEY (from_account) REFERENCES accounts(account), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE utxos ( @@ -745,7 +745,7 @@ mod tests { FOREIGN KEY (spent_in_tx) REFERENCES transactions(id_tx), CONSTRAINT tx_outpoint UNIQUE (prevout_txid, prevout_idx) )", - NO_PARAMS, + [], )?; let address = encode_payment_address( @@ -759,7 +759,7 @@ mod tests { wdb.conn.execute( "INSERT INTO accounts (account, extfvk, address, transparent_address) VALUES (?, ?, ?, '')", - &[ + [ u32::from(account).to_sql()?, extfvk.to_sql()?, address.to_sql()?, @@ -769,7 +769,7 @@ mod tests { // add a sapling sent note wdb.conn.execute( "INSERT INTO blocks (height, hash, time, sapling_tree) VALUES (0, 0, 0, '')", - NO_PARAMS, + [], )?; let tx = TransactionData::from_parts( @@ -794,7 +794,7 @@ mod tests { wdb.conn.execute( "INSERT INTO sent_notes (tx, output_index, from_account, address, value) VALUES (0, 0, ?, ?, 0)", - &[u32::from(account).to_sql()?, address.to_sql()?], + [u32::from(account).to_sql()?, address.to_sql()?], )?; Ok(()) @@ -824,7 +824,7 @@ mod tests { address TEXT, transparent_address TEXT )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE blocks ( @@ -833,7 +833,7 @@ mod tests { time INTEGER NOT NULL, sapling_tree BLOB NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE transactions ( @@ -846,7 +846,7 @@ mod tests { raw BLOB, FOREIGN KEY (block) REFERENCES blocks(height) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE received_notes ( @@ -866,7 +866,7 @@ mod tests { FOREIGN KEY (spent) REFERENCES transactions(id_tx), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sapling_witnesses ( @@ -878,7 +878,7 @@ mod tests { FOREIGN KEY (block) REFERENCES blocks(height), CONSTRAINT witness_height UNIQUE (note, block) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE sent_notes ( @@ -894,7 +894,7 @@ mod tests { FOREIGN KEY (from_account) REFERENCES accounts(account), CONSTRAINT tx_output UNIQUE (tx, output_pool, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE utxos ( @@ -909,7 +909,7 @@ mod tests { FOREIGN KEY (spent_in_tx) REFERENCES transactions(id_tx), CONSTRAINT tx_outpoint UNIQUE (prevout_txid, prevout_idx) )", - NO_PARAMS, + [], )?; let ufvk_str = ufvk.encode(&tests::network()); @@ -918,7 +918,7 @@ mod tests { wdb.conn.execute( "INSERT INTO accounts (account, ufvk, address, transparent_address) VALUES (?, ?, ?, '')", - &[ + [ u32::from(account).to_sql()?, ufvk_str.to_sql()?, address_str.to_sql()?, @@ -933,16 +933,16 @@ mod tests { .encode(&tests::network()); wdb.conn.execute( "INSERT INTO blocks (height, hash, time, sapling_tree) VALUES (0, 0, 0, '')", - NO_PARAMS, + [], )?; wdb.conn.execute( "INSERT INTO transactions (block, id_tx, txid) VALUES (0, 0, '')", - NO_PARAMS, + [], )?; wdb.conn.execute( "INSERT INTO sent_notes (tx, output_pool, output_index, from_account, address, value) VALUES (0, ?, 0, ?, ?, 0)", - &[PoolType::Transparent.typecode().to_sql()?, u32::from(account).to_sql()?, taddr.to_sql()?])?; + [PoolType::Transparent.typecode().to_sql()?, u32::from(account).to_sql()?, taddr.to_sql()?])?; } Ok(()) diff --git a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs index e443bab60..2bfb9de4f 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs @@ -1,7 +1,7 @@ //! Migration that adds transaction summary views & add fee information to transactions. use std::collections::HashSet; -use rusqlite::{self, types::ToSql, OptionalExtension, NO_PARAMS}; +use rusqlite::{self, types::ToSql, OptionalExtension}; use schemer::{self}; use schemer_rusqlite::RusqliteMigration; use uuid::Uuid; @@ -56,7 +56,7 @@ impl RusqliteMigration for Migration

{ let mut stmt_find_utxo_value = transaction .prepare("SELECT value_zat FROM utxos WHERE prevout_txid = ? AND prevout_idx = ?")?; - let mut tx_rows = stmt_list_txs.query(NO_PARAMS)?; + let mut tx_rows = stmt_list_txs.query([])?; while let Some(row) = tx_rows.next()? { let id_tx: i64 = row.get(0)?; let tx_bytes: Option> = row.get(1)?; @@ -77,7 +77,7 @@ impl RusqliteMigration for Migration

{ let fee_paid = tx.fee_paid(|op| { let op_amount = stmt_find_utxo_value - .query_row(&[op.hash().to_sql()?, op.n().to_sql()?], |row| { + .query_row([op.hash().to_sql()?, op.n().to_sql()?], |row| { row.get::<_, i64>(0) }) .optional() @@ -101,7 +101,7 @@ impl RusqliteMigration for Migration

{ ) })?; - stmt_set_fee.execute(&[i64::from(fee_paid), id_tx])?; + stmt_set_fee.execute([i64::from(fee_paid), id_tx])?; } } @@ -214,7 +214,6 @@ impl RusqliteMigration for Migration

{ #[cfg(test)] mod tests { - use rusqlite::{self, NO_PARAMS}; use tempfile::NamedTempFile; #[cfg(feature = "transparent-inputs")] @@ -274,7 +273,7 @@ mod tests { .conn .prepare("SELECT received_total, received_note_count, memo_count FROM v_tx_received") .unwrap(); - let mut rows = q.query(NO_PARAMS).unwrap(); + let mut rows = q.query([]).unwrap(); let mut row_count = 0; while let Some(row) = rows.next().unwrap() { row_count += 1; @@ -291,7 +290,7 @@ mod tests { .conn .prepare("SELECT sent_total, sent_note_count, memo_count FROM v_tx_sent") .unwrap(); - let mut rows = q.query(NO_PARAMS).unwrap(); + let mut rows = q.query([]).unwrap(); let mut row_count = 0; while let Some(row) = rows.next().unwrap() { row_count += 1; @@ -308,7 +307,7 @@ mod tests { .conn .prepare("SELECT net_value, has_change, memo_count FROM v_transactions") .unwrap(); - let mut rows = q.query(NO_PARAMS).unwrap(); + let mut rows = q.query([]).unwrap(); let mut row_count = 0; while let Some(row) = rows.next().unwrap() { row_count += 1; @@ -384,7 +383,7 @@ mod tests { db_data.conn.execute( "INSERT INTO utxos (address, prevout_txid, prevout_idx, script, value_zat, height) VALUES (?, X'0101010101010101010101010101010101010101010101010101010101010101', 1, X'', 1400000000, 1)", - &[taddr] + [taddr] ).unwrap(); db_data .conn @@ -398,11 +397,9 @@ mod tests { let fee = db_data .conn - .query_row( - "SELECT fee FROM transactions WHERE id_tx = 0", - NO_PARAMS, - |row| Ok(Amount::from_i64(row.get(0)?).unwrap()), - ) + .query_row("SELECT fee FROM transactions WHERE id_tx = 0", [], |row| { + Ok(Amount::from_i64(row.get(0)?).unwrap()) + }) .unwrap(); assert_eq!(fee, Amount::from_i64(300000000).unwrap()); diff --git a/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs b/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs index bae550091..511877082 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use rusqlite::{Transaction, NO_PARAMS}; +use rusqlite::Transaction; use schemer; use schemer_rusqlite::RusqliteMigration; use uuid::Uuid; @@ -64,7 +64,7 @@ impl RusqliteMigration for Migration

{ let mut stmt_fetch_accounts = transaction .prepare("SELECT account, ufvk, address, transparent_address FROM accounts")?; - let mut rows = stmt_fetch_accounts.query(NO_PARAMS)?; + let mut rows = stmt_fetch_accounts.query([])?; while let Some(row) = rows.next()? { let account: u32 = row.get(0)?; let account = AccountId::from(account); diff --git a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs index e5ee31c4e..24936b590 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs @@ -1,7 +1,7 @@ //! Migration that adds support for unified full viewing keys. use std::collections::HashSet; -use rusqlite::{self, params, NO_PARAMS}; +use rusqlite::{self, named_params, params}; use schemer; use schemer_rusqlite::RusqliteMigration; use secrecy::{ExposeSecret, SecretVec}; @@ -67,7 +67,7 @@ impl RusqliteMigration for Migration

{ let mut stmt_fetch_accounts = transaction.prepare("SELECT account, address FROM accounts")?; - let mut rows = stmt_fetch_accounts.query(NO_PARAMS)?; + let mut rows = stmt_fetch_accounts.query([])?; while let Some(row) = rows.next()? { // We only need to check for the presence of the seed if we have keys that // need to be migrated; otherwise, it's fine to not supply the seed if this @@ -137,14 +137,14 @@ impl RusqliteMigration for Migration

{ #[cfg(not(feature = "transparent-inputs"))] let taddress_str: Option = None; - transaction.execute_named( + transaction.execute( "INSERT INTO accounts_new (account, ufvk, address, transparent_address) VALUES (:account, :ufvk, :address, :transparent_address)", - &[ - (":account", &::from(account)), - (":ufvk", &ufvk_str), - (":address", &address_str), - (":transparent_address", &taddress_str), + named_params![ + ":account": &::from(account), + ":ufvk": &ufvk_str, + ":address": &address_str, + ":transparent_address": &taddress_str, ], )?; } else { @@ -182,7 +182,7 @@ impl RusqliteMigration for Migration

{ // dropped and doesn't maintain a lock on the table. let has_output_pool = { let mut stmt_fetch_columns = transaction.prepare("PRAGMA TABLE_INFO('sent_notes')")?; - let mut col_names = stmt_fetch_columns.query_map(NO_PARAMS, |row| { + let mut col_names = stmt_fetch_columns.query_map([], |row| { let col_name: String = row.get(1)?; Ok(col_name) })?; @@ -209,7 +209,7 @@ impl RusqliteMigration for Migration

{ VALUES (?, ?, ?, ?, ?, ?, ?, ?)", )?; - let mut rows = stmt_fetch_sent_notes.query(NO_PARAMS)?; + let mut rows = stmt_fetch_sent_notes.query([])?; while let Some(row) = rows.next()? { let id_note: i64 = row.get(0)?; let tx_ref: i64 = row.get(1)?; diff --git a/zcash_client_sqlite/src/wallet/transact.rs b/zcash_client_sqlite/src/wallet/transact.rs index db2cd9a3c..640ea5d56 100644 --- a/zcash_client_sqlite/src/wallet/transact.rs +++ b/zcash_client_sqlite/src/wallet/transact.rs @@ -79,7 +79,7 @@ pub fn get_spendable_sapling_notes

( )?; // Select notes - let notes = stmt_select_notes.query_and_then_named::<_, SqliteClientError, _>( + let notes = stmt_select_notes.query_and_then( named_params![ ":account": &u32::from(account), ":anchor_height": &u32::from(anchor_height), @@ -140,7 +140,7 @@ pub fn select_spendable_sapling_notes

( )?; // Select notes - let notes = stmt_select_notes.query_and_then_named::<_, SqliteClientError, _>( + let notes = stmt_select_notes.query_and_then( named_params![ ":account": &u32::from(account), ":anchor_height": &u32::from(anchor_height), @@ -698,7 +698,7 @@ mod tests { .query_row( "SELECT raw FROM transactions WHERE id_tx = ?", - &[tx_row], + [tx_row], |row| row.get(0), ) .unwrap(); @@ -711,7 +711,7 @@ mod tests { .query_row( "SELECT output_index FROM sent_notes WHERE tx = ?", - &[tx_row], + [tx_row], |row| row.get(0), ) .unwrap();