diff --git a/zcash_client_backend/src/encoding.rs b/zcash_client_backend/src/encoding.rs index 64be51b460..d181c604cf 100644 --- a/zcash_client_backend/src/encoding.rs +++ b/zcash_client_backend/src/encoding.rs @@ -11,7 +11,7 @@ use std::convert::TryInto; use std::io::{self, Write}; use zcash_primitives::{ legacy::TransparentAddress, - sapling::{{keys::OutgoingViewingKey}, PaymentAddress}, + sapling::{keys::OutgoingViewingKey, PaymentAddress}, zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, }; @@ -104,10 +104,12 @@ pub fn decode_outgoing_viewing_key( hrp: &str, s: &str, ) -> Result, Error> { - bech32_decode(hrp, s, |data| if data.len() == 32 { - Some(OutgoingViewingKey(data.try_into().expect("length is 32"))) - } else { - None + bech32_decode(hrp, s, |data| { + if data.len() == 32 { + Some(OutgoingViewingKey(data.try_into().expect("length is 32"))) + } else { + None + } }) } diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 30034cbdf2..015029e1d5 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -20,7 +20,7 @@ group = "0.8" jubjub = "0.5.1" protobuf = "2.20" rand_core = "0.5.1" -rusqlite = { version = "0.24", features = ["bundled", "time"] } +rusqlite = { version = "0.25", features = ["bundled", "time"] } time = "0.2" zcash_client_backend = { version = "0.5", path = "../zcash_client_backend" } zcash_primitives = { version = "0.5", path = "../zcash_primitives" } diff --git a/zcash_client_sqlite/src/chain/init.rs b/zcash_client_sqlite/src/chain/init.rs index ed60b452e4..341951e679 100644 --- a/zcash_client_sqlite/src/chain/init.rs +++ b/zcash_client_sqlite/src/chain/init.rs @@ -1,7 +1,5 @@ //! Functions for initializing the various databases. -use rusqlite::NO_PARAMS; - use crate::BlockDb; /// Sets up the internal structure of the cache database. @@ -25,7 +23,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 d64f2b3d75..b2f4218a53 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -36,7 +36,7 @@ use std::collections::HashMap; use std::fmt; use std::path::Path; -use rusqlite::{Connection, Statement, NO_PARAMS}; +use rusqlite::{Connection, Statement}; use zcash_primitives::{ block::BlockHash, @@ -383,14 +383,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/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 9fbc41185f..c134417da2 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 ff::PrimeField; -use rusqlite::{params, OptionalExtension, ToSql, NO_PARAMS}; +use rusqlite::{params, OptionalExtension, ToSql}; use std::collections::HashMap; use std::convert::TryFrom; @@ -124,7 +124,7 @@ pub fn get_address( let addr: String = wdb.conn.query_row( "SELECT address FROM accounts WHERE account = ?", - &[account.0], + [account.0], |row| row.get(0), )?; @@ -144,7 +144,7 @@ pub fn get_extended_full_viewing_keys( .prepare("SELECT account, extfvk FROM accounts ORDER BY account ASC")?; let rows = stmt_fetch_accounts - .query_map(NO_PARAMS, |row| { + .query_map([], |row| { let acct = row.get(0).map(AccountId)?; let extfvk = row.get(1).map(|extfvk: String| { decode_extended_full_viewing_key( @@ -179,7 +179,7 @@ pub fn is_valid_account_extfvk( ) -> Result { wdb.conn .prepare("SELECT * FROM accounts WHERE account = ? AND extfvk = ?")? - .exists(&[ + .exists([ account.0.to_sql()?, encode_extended_full_viewing_key( wdb.params.hrp_sapling_extended_full_viewing_key(), @@ -218,7 +218,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 <= ?", - &[account.0, u32::from(anchor_height)], + [account.0, u32::from(anchor_height)], |row| row.get(0).or(Ok(0)), )?; @@ -294,7 +294,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), )?; @@ -327,7 +327,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), )?; @@ -356,18 +356,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)) @@ -398,7 +394,7 @@ pub fn get_tx_height

( wdb.conn .query_row( "SELECT block FROM transactions WHERE txid = ?", - &[txid.0.to_vec()], + [txid.0.to_vec()], |row| row.get(0).map(u32::into), ) .optional() @@ -428,7 +424,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)) @@ -453,13 +449,13 @@ pub 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(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(Ok(sapling_activation_height - 1)) + })?; // nothing to do if we're deleting back down to the max height if block_height >= last_scanned_height { @@ -468,19 +464,19 @@ pub fn rewind_to_height( // Decrement witnesses. wdb.conn.execute( "DELETE FROM sapling_witnesses WHERE block > ?", - &[u32::from(block_height)], + [u32::from(block_height)], )?; // Un-mine transactions. wdb.conn.execute( "UPDATE transactions SET block = NULL, tx_index = NULL WHERE 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)], )?; Ok(()) @@ -511,7 +507,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| { @@ -552,7 +548,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))) @@ -578,7 +574,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 = AccountId(row.get(1)?); let nf_bytes: Vec = row.get(2)?; Ok((account, Nullifier::from_slice(&nf_bytes).unwrap())) @@ -632,7 +628,7 @@ pub fn put_tx_meta<'a, P, N>( // It was there, so grab its row number. stmts .stmt_select_tx_ref - .query_row(&[txid], |row| row.get(0)) + .query_row([txid], |row| row.get(0)) .map_err(SqliteClientError::from) } } @@ -666,7 +662,7 @@ pub fn put_tx_data<'a, P>( // It was there, so grab its row number. stmts .stmt_select_tx_ref - .query_row(&[txid], |row| row.get(0)) + .query_row([txid], |row| row.get(0)) .map_err(SqliteClientError::from) } } @@ -683,7 +679,7 @@ pub fn mark_spent<'a, P>( ) -> Result<(), SqliteClientError> { stmts .stmt_mark_recived_note_spent - .execute(&[tx_ref.to_sql()?, nf.0.to_sql()?])?; + .execute([tx_ref.to_sql()?, nf.0.to_sql()?])?; Ok(()) } @@ -763,7 +759,7 @@ pub fn prune_witnesses

( ) -> Result<(), SqliteClientError> { stmts .stmt_prune_witnesses - .execute(&[u32::from(below_height)])?; + .execute([u32::from(below_height)])?; Ok(()) } @@ -773,7 +769,7 @@ pub fn update_expired_notes

( stmts: &mut DataConnStmtCache<'_, P>, height: BlockHeight, ) -> Result<(), SqliteClientError> { - stmts.stmt_update_expired.execute(&[u32::from(height)])?; + stmts.stmt_update_expired.execute([u32::from(height)])?; Ok(()) } diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index f21f53182c..c28e884aee 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -1,6 +1,6 @@ //! Functions for initializing the various databases. -use rusqlite::{types::ToSql, NO_PARAMS}; +use rusqlite::types::ToSql; use zcash_primitives::{ block::BlockHash, @@ -35,7 +35,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { extfvk TEXT NOT NULL, address TEXT NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE IF NOT EXISTS blocks ( @@ -44,7 +44,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { time INTEGER NOT NULL, sapling_tree BLOB NOT NULL )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE IF NOT EXISTS transactions ( @@ -57,7 +57,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { raw BLOB, FOREIGN KEY (block) REFERENCES blocks(height) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE IF NOT EXISTS received_notes ( @@ -77,7 +77,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { FOREIGN KEY (spent) REFERENCES transactions(id_tx), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE IF NOT EXISTS sapling_witnesses ( @@ -89,7 +89,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { FOREIGN KEY (block) REFERENCES blocks(height), CONSTRAINT witness_height UNIQUE (note, block) )", - NO_PARAMS, + [], )?; wdb.conn.execute( "CREATE TABLE IF NOT EXISTS sent_notes ( @@ -104,7 +104,7 @@ pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { FOREIGN KEY (from_account) REFERENCES accounts(account), CONSTRAINT tx_output UNIQUE (tx, output_index) )", - NO_PARAMS, + [], )?; Ok(()) } @@ -148,12 +148,12 @@ pub fn init_accounts_table( extfvks: &[ExtendedFullViewingKey], ) -> 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); } // Insert accounts atomically - wdb.conn.execute("BEGIN IMMEDIATE", NO_PARAMS)?; + wdb.conn.execute("BEGIN IMMEDIATE", [])?; for (account, extfvk) in extfvks.iter().enumerate() { let extfvk_str = encode_extended_full_viewing_key( wdb.params.hrp_sapling_extended_full_viewing_key(), @@ -165,14 +165,14 @@ pub fn init_accounts_table( wdb.conn.execute( "INSERT INTO accounts (account, extfvk, address) VALUES (?, ?, ?)", - &[ + [ (account as u32).to_sql()?, extfvk_str.to_sql()?, address_str.to_sql()?, ], )?; } - wdb.conn.execute("COMMIT", NO_PARAMS)?; + wdb.conn.execute("COMMIT", [])?; Ok(()) } @@ -217,14 +217,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()?, diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 7a45456cbb..0b9eac4f9e 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -225,12 +225,22 @@ struct TransparentInputs; impl TransparentInputs { #[cfg(feature = "transparent-inputs")] - fn push(&mut self, sk: secp256k1::SecretKey, script_data: Script, coin: TxOut) -> Result<(), Error> { + fn push( + &mut self, + sk: secp256k1::SecretKey, + script_data: Script, + coin: TxOut, + ) -> Result<(), Error> { if coin.value.is_negative() { return Err(Error::InvalidAmount); } - self.inputs.push(TransparentInputInfo { sk, script_data, redeem_script: coin.script_pubkey.clone(), coin }); + self.inputs.push(TransparentInputInfo { + sk, + script_data, + redeem_script: coin.script_pubkey.clone(), + coin, + }); Ok(()) } @@ -565,10 +575,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> { } /// Adds a TxOut - pub fn add_tx_out( - &mut self, - out: TxOut, - ) { + pub fn add_tx_out(&mut self, out: TxOut) { self.mtx.vout.push(out); }