Upgrade rusqlite to version 0.25

This commit is contained in:
Kris Nuttycombe 2022-10-02 09:09:52 -06:00
parent 81e0d482d0
commit f7aa7b2c84
12 changed files with 143 additions and 157 deletions

View File

@ -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" }

View File

@ -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"

View File

@ -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::<Result<Vec<_>, _>>();
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<Option<BlockHeight>, 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<u32> = 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<u32> = row.get(0)?;
Ok(h.map(BlockHeight::from))
})
}
/// Implements a traversal of `limit` blocks of the filesystem-backed

View File

@ -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(())
}

View File

@ -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<A, SqliteClientError>,
{
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

View File

@ -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(())
}
}

View File

@ -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<P: consensus::Parameters>(
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<P>(
) -> Result<Option<AccountId>, 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<u32> = row.get(0)?;
Ok(account_id.map(AccountId::from))
})
@ -207,12 +207,12 @@ pub(crate) fn add_account_internal<P: consensus::Parameters, E: From<rusqlite::E
key: &UnifiedFullViewingKey,
) -> 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", &<u32>::from(account)), (":ufvk", &ufvk_str)],
named_params![":account": &<u32>::from(account), ":ufvk": &ufvk_str],
)?;
// Always derive the default Unified Address for the account.
@ -220,13 +220,13 @@ pub(crate) fn add_account_internal<P: consensus::Parameters, E: From<rusqlite::E
let address_str: String = address.encode(network);
// the diversifier index is stored in big-endian order to allow sorting
idx.0.reverse();
conn.execute_named(
conn.execute(
"INSERT INTO addresses (account, diversifier_index_be, address)
VALUES (:account, :diversifier_index_be, :address)",
&[
(":account", &<u32>::from(account)),
(":diversifier_index_be", &&idx.0[..]),
(":address", &address_str),
named_params![
":account": &<u32>::from(account),
":diversifier_index_be": &&idx.0[..],
":address": &address_str,
],
)?;
@ -240,12 +240,12 @@ pub(crate) fn get_current_address<P: consensus::Parameters>(
// This returns the most recently generated address.
let addr: Option<(String, Vec<u8>)> = 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<P: consensus::Parameters>(
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<P: consensus::Parameters>(
// 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<P: consensus::Parameters>(
.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<P: consensus::Parameters>(
) -> Result<bool, SqliteClientError> {
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<P>(wdb: &WalletDb<P>, account: AccountId) -> Result<Amount, S
"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 IS NOT NULL",
&[u32::from(account)],
[u32::from(account)],
|row| row.get(0).or(Ok(0)),
)?;
@ -464,7 +464,7 @@ pub fn get_balance_at<P>(
"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<P>(wdb: &WalletDb<P>, id_note: i64) -> Result<Memo, Sql
let memo_bytes: Vec<_> = 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<P: Parameters>(
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<P>(wdb: &WalletDb<P>, id_note: i64) -> Result<Memo, SqliteC
let memo_bytes: Vec<_> = 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<P>(
wdb: &WalletDb<P>,
) -> Result<Option<(BlockHeight, BlockHeight)>, 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<P>(
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<P>(
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<P>(wdb: &WalletDb<P>) -> Result<Option<BlockHeight>, 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<u32>| maybe_height.map(|height| height.into()))
@ -715,13 +711,13 @@ pub(crate) fn rewind_to_height<P: consensus::Parameters>(
.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<P: consensus::Parameters>(
// 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<P: consensus::Parameters>(
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<P: consensus::Parameters>(
// 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<P>(
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<u8> = row.get(0)?;
CommitmentTree::read(&row_data[..]).map_err(|e| {
@ -850,7 +846,7 @@ pub fn get_witnesses<P>(
.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<u8> = row.get(1)?;
Ok(IncrementalWitness::read(&wdb[..]).map(|witness| (id_note, witness)))
@ -879,7 +875,7 @@ pub fn get_nullifiers<P>(
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<u8> = row.get(2)?;
Ok((
@ -901,7 +897,7 @@ pub(crate) fn get_all_nullifiers<P>(
"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<u8> = row.get(2)?;
Ok((

View File

@ -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<P: consensus::Parameters + 'static>(
target_migration: Option<Uuid>,
) -> Result<(), MigratorError<WalletMigrationError>> {
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<P: consensus::Parameters + 'static>(
.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<P: consensus::Parameters>(
keys: &HashMap<AccountId, UnifiedFullViewingKey>,
) -> 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<P: consensus::Parameters>(
}
// 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<P>(
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<P>(
#[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(())

View File

@ -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<P: consensus::Parameters> RusqliteMigration for Migration<P> {
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<Vec<u8>> = row.get(1)?;
@ -77,7 +77,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
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<P: consensus::Parameters> RusqliteMigration for Migration<P> {
)
})?;
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<P: consensus::Parameters> RusqliteMigration for Migration<P> {
#[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());

View File

@ -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<P: consensus::Parameters> RusqliteMigration for Migration<P> {
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);

View File

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

View File

@ -79,7 +79,7 @@ pub fn get_spendable_sapling_notes<P>(
)?;
// 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<P>(
)?;
// 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();