From 636845d0f93d9b797ed9686ae43d7abff11b1783 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Mar 2021 18:17:54 +1300 Subject: [PATCH 1/5] Renames to use lower-case abbreviations (matching Rust convention) As of our MSRV bump to 1.51.0, we get lints for this. --- zcash_client_backend/CHANGELOG.md | 4 + zcash_client_backend/src/data_api.rs | 6 +- zcash_client_backend/src/data_api/chain.rs | 16 ++-- zcash_client_backend/src/data_api/error.rs | 4 +- zcash_client_backend/src/data_api/wallet.rs | 6 +- zcash_client_sqlite/CHANGELOG.md | 6 ++ zcash_client_sqlite/src/chain.rs | 34 ++++----- zcash_client_sqlite/src/chain/init.rs | 8 +- zcash_client_sqlite/src/error.rs | 4 +- zcash_client_sqlite/src/lib.rs | 22 +++--- zcash_client_sqlite/src/wallet.rs | 76 +++++++++---------- zcash_client_sqlite/src/wallet/init.rs | 28 +++---- zcash_client_sqlite/src/wallet/transact.rs | 30 ++++---- zcash_primitives/CHANGELOG.md | 4 + .../src/transaction/components.rs | 2 +- .../src/transaction/components/sprout.rs | 16 ++-- zcash_primitives/src/transaction/mod.rs | 6 +- zcash_primitives/src/transaction/sighash.rs | 4 +- zcash_primitives/src/zip32.rs | 34 ++++----- zcash_proofs/CHANGELOG.md | 4 + zcash_proofs/src/circuit/sprout/mod.rs | 12 +-- zcash_proofs/src/sprout.rs | 4 +- 22 files changed, 174 insertions(+), 156 deletions(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 9c44282d7..5ead377da 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -8,6 +8,10 @@ and this library adheres to Rust's notion of ## [Unreleased] ### Changed - MSRV is now 1.51.0. +- Renamed the following in `zcash_client_backend::data_api` to use lower-case + abbreviations (matching Rust naming conventions): + - `error::Error::InvalidExtSK` to `Error::InvalidExtSk` + - `testing::MockWalletDB` to `testing::MockWalletDb` ## [0.5.0] - 2021-03-26 ### Added diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 94d192055..166fd80cb 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -309,9 +309,9 @@ pub mod testing { } } - pub struct MockWalletDB {} + pub struct MockWalletDb {} - impl WalletRead for MockWalletDB { + impl WalletRead for MockWalletDb { type Error = Error; type NoteRef = u32; type TxRef = TxId; @@ -398,7 +398,7 @@ pub mod testing { } } - impl WalletWrite for MockWalletDB { + impl WalletWrite for MockWalletDb { #[allow(clippy::type_complexity)] fn advance_by_block( &mut self, diff --git a/zcash_client_backend/src/data_api/chain.rs b/zcash_client_backend/src/data_api/chain.rs index 14580cf47..38a47007f 100644 --- a/zcash_client_backend/src/data_api/chain.rs +++ b/zcash_client_backend/src/data_api/chain.rs @@ -21,8 +21,8 @@ //! }; //! //! use zcash_client_sqlite::{ -//! BlockDB, -//! WalletDB, +//! BlockDb, +//! WalletDb, //! error::SqliteClientError, //! wallet::{rewind_to_height}, //! wallet::init::{init_wallet_db}, @@ -37,9 +37,9 @@ //! # fn test() -> Result<(), SqliteClientError> { //! let network = Network::TestNetwork; //! let cache_file = NamedTempFile::new()?; -//! let db_cache = BlockDB::for_path(cache_file)?; +//! let db_cache = BlockDb::for_path(cache_file)?; //! let db_file = NamedTempFile::new()?; -//! let db_read = WalletDB::for_path(db_file, network)?; +//! let db_read = WalletDb::for_path(db_file, network)?; //! init_wallet_db(&db_read)?; //! //! let mut db_data = db_read.get_update_ops()?; @@ -211,8 +211,8 @@ where /// data_api::chain::scan_cached_blocks, /// }; /// use zcash_client_sqlite::{ -/// BlockDB, -/// WalletDB, +/// BlockDb, +/// WalletDb, /// error::SqliteClientError, /// wallet::init::init_wallet_db, /// }; @@ -225,10 +225,10 @@ where /// # /// # fn test() -> Result<(), SqliteClientError> { /// let cache_file = NamedTempFile::new().unwrap(); -/// let cache = BlockDB::for_path(cache_file).unwrap(); +/// let cache = BlockDb::for_path(cache_file).unwrap(); /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db_read = WalletDB::for_path(data_file, Network::TestNetwork)?; +/// let db_read = WalletDb::for_path(data_file, Network::TestNetwork)?; /// init_wallet_db(&db_read)?; /// /// let mut data = db_read.get_update_ops()?; diff --git a/zcash_client_backend/src/data_api/error.rs b/zcash_client_backend/src/data_api/error.rs index 0a55ea7b3..1968af8f9 100644 --- a/zcash_client_backend/src/data_api/error.rs +++ b/zcash_client_backend/src/data_api/error.rs @@ -31,7 +31,7 @@ pub enum Error { InvalidChain(BlockHeight, ChainInvalid), /// A provided extsk is not associated with the specified account. - InvalidExtSK(AccountId), + InvalidExtSk(AccountId), /// The root of an output's witness tree in a newly arrived transaction does /// not correspond to root of the stored commitment tree at the recorded height. @@ -80,7 +80,7 @@ impl fmt::Display for Error { Error::InvalidChain(upper_bound, cause) => { write!(f, "Invalid chain (upper bound: {}): {:?}", u32::from(*upper_bound), cause) } - Error::InvalidExtSK(account) => { + Error::InvalidExtSk(account) => { write!(f, "Incorrect ExtendedSpendingKey for account {}", account.0) } Error::InvalidNewWitnessAnchor(output, txid, last_height, anchor) => write!( diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index d61c1d537..85b1028e6 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -103,7 +103,7 @@ where /// wallet::{AccountId, OvkPolicy}, /// }; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// error::SqliteClientError, /// wallet::init::init_wallet_db, /// }; @@ -127,7 +127,7 @@ where /// let to = extsk.default_address().unwrap().1.into(); /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db_read = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db_read = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// init_wallet_db(&db_read)?; /// let mut db = db_read.get_update_ops()?; /// @@ -168,7 +168,7 @@ where // ExtendedFullViewingKey for the account we are spending from. let extfvk = ExtendedFullViewingKey::from(extsk); if !wallet_db.is_valid_account_extfvk(account, &extfvk)? { - return Err(E::from(Error::InvalidExtSK(account))); + return Err(E::from(Error::InvalidExtSk(account))); } // Apply the outgoing viewing key policy. diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 84722f475..7ac5cefa8 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -8,6 +8,12 @@ and this library adheres to Rust's notion of ## [Unreleased] ### Changed - MSRV is now 1.51.0. +- Renamed the following to use lower-case abbreviations (matching Rust + naming conventions): + - `zcash_client_sqlite::BlockDB` to `BlockDb` + - `zcash_client_sqlite::WalletDB` to `WalletDb` + - `zcash_client_sqlite::error::SqliteClientError::IncorrectHRPExtFVK` to + `IncorrectHrpExtFvk`. ## [0.3.0] - 2021-03-26 This release contains a major refactor of the APIs to leverage the new Data diff --git a/zcash_client_sqlite/src/chain.rs b/zcash_client_sqlite/src/chain.rs index fdc3ca6f2..b416ebe88 100644 --- a/zcash_client_sqlite/src/chain.rs +++ b/zcash_client_sqlite/src/chain.rs @@ -7,7 +7,7 @@ use zcash_primitives::consensus::BlockHeight; use zcash_client_backend::{data_api::error::Error, proto::compact_formats::CompactBlock}; -use crate::{error::SqliteClientError, BlockDB}; +use crate::{error::SqliteClientError, BlockDb}; pub mod init; @@ -23,7 +23,7 @@ struct CompactBlockRow { /// value provided is `None`, all blocks are traversed up to the /// maximum height. pub fn with_blocks( - cache: &BlockDB, + cache: &BlockDb, from_height: BlockHeight, limit: Option, mut with_row: F, @@ -92,17 +92,17 @@ mod tests { init::{init_accounts_table, init_wallet_db}, rewind_to_height, }, - AccountId, BlockDB, NoteId, WalletDB, + AccountId, BlockDb, NoteId, WalletDb, }; #[test] fn valid_chain_states() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -179,11 +179,11 @@ mod tests { #[test] fn invalid_chain_cache_disconnected() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -251,11 +251,11 @@ mod tests { #[test] fn invalid_chain_cache_reorg() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -323,11 +323,11 @@ mod tests { #[test] fn data_db_rewinding() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -382,11 +382,11 @@ mod tests { #[test] fn scan_cached_blocks_requires_sequential_blocks() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -443,11 +443,11 @@ mod tests { #[test] fn scan_cached_blocks_finds_received_notes() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -491,11 +491,11 @@ mod tests { #[test] fn scan_cached_blocks_finds_change_notes() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB::for_path(cache_file.path()).unwrap(); + let db_cache = BlockDb::for_path(cache_file.path()).unwrap(); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet diff --git a/zcash_client_sqlite/src/chain/init.rs b/zcash_client_sqlite/src/chain/init.rs index 5a37a8d4a..ed60b452e 100644 --- a/zcash_client_sqlite/src/chain/init.rs +++ b/zcash_client_sqlite/src/chain/init.rs @@ -2,7 +2,7 @@ use rusqlite::NO_PARAMS; -use crate::BlockDB; +use crate::BlockDb; /// Sets up the internal structure of the cache database. /// @@ -11,15 +11,15 @@ use crate::BlockDB; /// ``` /// use tempfile::NamedTempFile; /// use zcash_client_sqlite::{ -/// BlockDB, +/// BlockDb, /// chain::init::init_cache_database, /// }; /// /// let cache_file = NamedTempFile::new().unwrap(); -/// let db = BlockDB::for_path(cache_file.path()).unwrap(); +/// let db = BlockDb::for_path(cache_file.path()).unwrap(); /// init_cache_database(&db).unwrap(); /// ``` -pub fn init_cache_database(db_cache: &BlockDB) -> Result<(), rusqlite::Error> { +pub fn init_cache_database(db_cache: &BlockDb) -> Result<(), rusqlite::Error> { db_cache.0.execute( "CREATE TABLE IF NOT EXISTS compactblocks ( height INTEGER PRIMARY KEY, diff --git a/zcash_client_sqlite/src/error.rs b/zcash_client_sqlite/src/error.rs index e67f3dcf0..e83c20e5d 100644 --- a/zcash_client_sqlite/src/error.rs +++ b/zcash_client_sqlite/src/error.rs @@ -14,7 +14,7 @@ pub enum SqliteClientError { CorruptedData(String), /// Decoding of the extended full viewing key has failed (for the specified network) - IncorrectHRPExtFVK, + IncorrectHrpExtFvk, /// The rcm value for a note cannot be decoded to a valid JubJub point. InvalidNote, @@ -63,7 +63,7 @@ impl fmt::Display for SqliteClientError { SqliteClientError::CorruptedData(reason) => { write!(f, "Data DB is corrupted: {}", reason) } - SqliteClientError::IncorrectHRPExtFVK => write!(f, "Incorrect HRP for extfvk"), + SqliteClientError::IncorrectHrpExtFvk => write!(f, "Incorrect HRP for extfvk"), SqliteClientError::InvalidNote => write!(f, "Invalid note"), SqliteClientError::InvalidNoteId => write!(f, "The note ID associated with an inserted witness must correspond to a received note."), SqliteClientError::Bech32(e) => write!(f, "{}", e), diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 399af9ac8..d9cb368dc 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -81,15 +81,15 @@ impl fmt::Display for NoteId { } /// A wrapper for the SQLite connection to the wallet database. -pub struct WalletDB

{ +pub struct WalletDb

{ conn: Connection, params: P, } -impl WalletDB

{ +impl WalletDb

{ /// Construct a connection to the wallet database stored at the specified path. pub fn for_path>(path: F, params: P) -> Result { - Connection::open(path).map(move |conn| WalletDB { conn, params }) + Connection::open(path).map(move |conn| WalletDb { conn, params }) } /// Given a wallet database connection, obtain a handle for the write operations @@ -170,7 +170,7 @@ impl WalletDB

{ } } -impl WalletRead for WalletDB

{ +impl WalletRead for WalletDb

{ type Error = SqliteClientError; type NoteRef = NoteId; type TxRef = i64; @@ -265,7 +265,7 @@ impl WalletRead for WalletDB

{ /// /// [`WalletWrite`]: zcash_client_backend::data_api::WalletWrite pub struct DataConnStmtCache<'a, P> { - wallet_db: &'a WalletDB

, + wallet_db: &'a WalletDb

, stmt_insert_block: Statement<'a>, stmt_insert_tx_meta: Statement<'a>, @@ -514,16 +514,16 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> { } /// A wrapper for the SQLite connection to the block cache database. -pub struct BlockDB(Connection); +pub struct BlockDb(Connection); -impl BlockDB { +impl BlockDb { /// Opens a connection to the wallet database stored at the specified path. pub fn for_path>(path: P) -> Result { - Connection::open(path).map(BlockDB) + Connection::open(path).map(BlockDb) } } -impl BlockSource for BlockDB { +impl BlockSource for BlockDb { type Error = SqliteClientError; fn with_blocks( @@ -569,7 +569,7 @@ mod tests { zip32::ExtendedFullViewingKey, }; - use super::BlockDB; + use super::BlockDb; #[cfg(feature = "mainnet")] pub(crate) fn network() -> Network { @@ -730,7 +730,7 @@ mod tests { } /// Insert a fake CompactBlock into the cache DB. - pub(crate) fn insert_into_cache(db_cache: &BlockDB, cb: &CompactBlock) { + pub(crate) fn insert_into_cache(db_cache: &BlockDb, cb: &CompactBlock) { let cb_bytes = cb.write_to_bytes().unwrap(); db_cache .0 diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 8edd8806d..9fbc41185 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -33,7 +33,7 @@ use zcash_client_backend::{ DecryptedOutput, }; -use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, WalletDB}; +use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, WalletDb}; pub mod init; pub mod transact; @@ -109,16 +109,16 @@ impl ShieldedOutput for DecryptedOutput { /// }; /// use zcash_client_backend::wallet::AccountId; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_address, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let addr = get_address(&db, AccountId(0)); /// ``` pub fn get_address( - wdb: &WalletDB

, + wdb: &WalletDb

, account: AccountId, ) -> Result, SqliteClientError> { let addr: String = wdb.conn.query_row( @@ -136,7 +136,7 @@ pub fn get_address( /// /// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey pub fn get_extended_full_viewing_keys( - wdb: &WalletDB

, + wdb: &WalletDb

, ) -> Result, SqliteClientError> { // Fetch the ExtendedFullViewingKeys we are tracking let mut stmt_fetch_accounts = wdb @@ -152,7 +152,7 @@ pub fn get_extended_full_viewing_keys( &extfvk, ) .map_err(SqliteClientError::Bech32) - .and_then(|k| k.ok_or(SqliteClientError::IncorrectHRPExtFVK)) + .and_then(|k| k.ok_or(SqliteClientError::IncorrectHrpExtFvk)) })?; Ok((acct, extfvk)) @@ -173,7 +173,7 @@ pub fn get_extended_full_viewing_keys( /// /// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey pub fn is_valid_account_extfvk( - wdb: &WalletDB

, + wdb: &WalletDb

, account: AccountId, extfvk: &ExtendedFullViewingKey, ) -> Result { @@ -205,15 +205,15 @@ pub fn is_valid_account_extfvk( /// use zcash_primitives::consensus::Network; /// use zcash_client_backend::wallet::AccountId; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_balance, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let addr = get_balance(&db, AccountId(0)); /// ``` -pub fn get_balance

(wdb: &WalletDB

, account: AccountId) -> Result { +pub fn get_balance

(wdb: &WalletDb

, account: AccountId) -> Result { let balance = wdb.conn.query_row( "SELECT SUM(value) FROM received_notes INNER JOIN transactions ON transactions.id_tx = received_notes.tx @@ -241,16 +241,16 @@ pub fn get_balance

(wdb: &WalletDB

, account: AccountId) -> Result( - wdb: &WalletDB

, + wdb: &WalletDb

, account: AccountId, anchor_height: BlockHeight, ) -> Result { @@ -282,15 +282,15 @@ pub fn get_balance_at

( /// use zcash_primitives::consensus::Network; /// use zcash_client_sqlite::{ /// NoteId, -/// WalletDB, +/// WalletDb, /// wallet::get_received_memo, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let memo = get_received_memo(&db, 27); /// ``` -pub fn get_received_memo

(wdb: &WalletDB

, id_note: i64) -> Result { +pub fn get_received_memo

(wdb: &WalletDb

, id_note: i64) -> Result { let memo_bytes: Vec<_> = wdb.conn.query_row( "SELECT memo FROM received_notes WHERE id_note = ?", @@ -315,15 +315,15 @@ pub fn get_received_memo

(wdb: &WalletDB

, id_note: i64) -> Result(wdb: &WalletDB

, id_note: i64) -> Result { +pub fn get_sent_memo

(wdb: &WalletDb

, id_note: i64) -> Result { let memo_bytes: Vec<_> = wdb.conn.query_row( "SELECT memo FROM sent_notes WHERE id_note = ?", @@ -344,16 +344,16 @@ pub fn get_sent_memo

(wdb: &WalletDB

, id_note: i64) -> Result( - wdb: &WalletDB

, + wdb: &WalletDb

, ) -> Result, rusqlite::Error> { wdb.conn .query_row( @@ -383,16 +383,16 @@ pub fn block_height_extrema

( /// use zcash_primitives::consensus::Network; /// use zcash_primitives::transaction::TxId; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_tx_height, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let height = get_tx_height(&db, TxId([0u8; 32])); /// ``` pub fn get_tx_height

( - wdb: &WalletDB

, + wdb: &WalletDb

, txid: TxId, ) -> Result, rusqlite::Error> { wdb.conn @@ -413,16 +413,16 @@ pub fn get_tx_height

( /// use tempfile::NamedTempFile; /// use zcash_primitives::consensus::{H0, Network}; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_block_hash, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let hash = get_block_hash(&db, H0); /// ``` pub fn get_block_hash

( - wdb: &WalletDB

, + wdb: &WalletDb

, block_height: BlockHeight, ) -> Result, rusqlite::Error> { wdb.conn @@ -444,7 +444,7 @@ pub fn get_block_hash

( /// /// This should only be executed inside a transactional context. pub fn rewind_to_height( - wdb: &WalletDB

, + wdb: &WalletDb

, block_height: BlockHeight, ) -> Result<(), SqliteClientError> { let sapling_activation_height = wdb @@ -496,16 +496,16 @@ pub fn rewind_to_height( /// use tempfile::NamedTempFile; /// use zcash_primitives::consensus::{Network, H0}; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_commitment_tree, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let tree = get_commitment_tree(&db, H0); /// ``` pub fn get_commitment_tree

( - wdb: &WalletDB

, + wdb: &WalletDb

, block_height: BlockHeight, ) -> Result>, SqliteClientError> { wdb.conn @@ -536,16 +536,16 @@ pub fn get_commitment_tree

( /// use tempfile::NamedTempFile; /// use zcash_primitives::consensus::{Network, H0}; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::get_witnesses, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file, Network::TestNetwork).unwrap(); /// let witnesses = get_witnesses(&db, H0); /// ``` pub fn get_witnesses

( - wdb: &WalletDB

, + wdb: &WalletDb

, block_height: BlockHeight, ) -> Result)>, SqliteClientError> { let mut stmt_fetch_witnesses = wdb @@ -568,7 +568,7 @@ pub fn get_witnesses

( /// that have not yet been confirmed as a consequence of the spending /// transaction being included in a block. pub fn get_nullifiers

( - wdb: &WalletDB

, + wdb: &WalletDb

, ) -> Result, SqliteClientError> { // Get the nullifiers for the notes we are tracking let mut stmt_fetch_nullifiers = wdb.conn.prepare( @@ -862,7 +862,7 @@ mod tests { use crate::{ tests, wallet::init::{init_accounts_table, init_wallet_db}, - AccountId, WalletDB, + AccountId, WalletDb, }; use super::{get_address, get_balance}; @@ -870,7 +870,7 @@ mod tests { #[test] fn empty_database_has_no_balance() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index 1924105bc..f21f53182 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -10,7 +10,7 @@ use zcash_primitives::{ use zcash_client_backend::encoding::encode_extended_full_viewing_key; -use crate::{address_from_extfvk, error::SqliteClientError, WalletDB}; +use crate::{address_from_extfvk, error::SqliteClientError, WalletDb}; /// Sets up the internal structure of the data database. /// @@ -20,15 +20,15 @@ use crate::{address_from_extfvk, error::SqliteClientError, WalletDB}; /// use tempfile::NamedTempFile; /// use zcash_primitives::consensus::Network; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::init::init_wallet_db, /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file.path(), Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap(); /// init_wallet_db(&db).unwrap(); /// ``` -pub fn init_wallet_db

(wdb: &WalletDB

) -> Result<(), rusqlite::Error> { +pub fn init_wallet_db

(wdb: &WalletDb

) -> Result<(), rusqlite::Error> { wdb.conn.execute( "CREATE TABLE IF NOT EXISTS accounts ( account INTEGER PRIMARY KEY, @@ -127,12 +127,12 @@ pub fn init_wallet_db

(wdb: &WalletDB

) -> Result<(), rusqlite::Error> { /// }; /// /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::init::{init_accounts_table, init_wallet_db} /// }; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db_data = WalletDB::for_path(data_file.path(), Network::TestNetwork).unwrap(); +/// let db_data = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap(); /// init_wallet_db(&db_data).unwrap(); /// /// let extsk = ExtendedSpendingKey::master(&[]); @@ -144,7 +144,7 @@ pub fn init_wallet_db

(wdb: &WalletDB

) -> Result<(), rusqlite::Error> { /// [`scan_cached_blocks`]: zcash_client_backend::data_api::chain::scan_cached_blocks /// [`create_spend_to_address`]: zcash_client_backend::data_api::wallet::create_spend_to_address pub fn init_accounts_table( - wdb: &WalletDB

, + wdb: &WalletDb

, extfvks: &[ExtendedFullViewingKey], ) -> Result<(), SqliteClientError> { let mut empty_check = wdb.conn.prepare("SELECT * FROM accounts LIMIT 1")?; @@ -191,7 +191,7 @@ pub fn init_accounts_table( /// consensus::{BlockHeight, Network}, /// }; /// use zcash_client_sqlite::{ -/// WalletDB, +/// WalletDb, /// wallet::init::init_blocks_table, /// }; /// @@ -206,11 +206,11 @@ pub fn init_accounts_table( /// let sapling_tree = &[]; /// /// let data_file = NamedTempFile::new().unwrap(); -/// let db = WalletDB::for_path(data_file.path(), Network::TestNetwork).unwrap(); +/// let db = WalletDb::for_path(data_file.path(), Network::TestNetwork).unwrap(); /// init_blocks_table(&db, height, hash, time, sapling_tree); /// ``` pub fn init_blocks_table

( - wdb: &WalletDB

, + wdb: &WalletDb

, height: BlockHeight, hash: BlockHash, time: u32, @@ -245,14 +245,14 @@ mod tests { zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, }; - use crate::{tests, wallet::get_address, AccountId, WalletDB}; + use crate::{tests, wallet::get_address, AccountId, WalletDb}; use super::{init_accounts_table, init_blocks_table, init_wallet_db}; #[test] fn init_accounts_table_only_works_once() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // We can call the function as many times as we want with no data @@ -273,7 +273,7 @@ mod tests { #[test] fn init_blocks_table_only_works_once() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // First call with data should initialise the blocks table @@ -300,7 +300,7 @@ mod tests { #[test] fn init_accounts_table_stores_correct_address() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet diff --git a/zcash_client_sqlite/src/wallet/transact.rs b/zcash_client_sqlite/src/wallet/transact.rs index e46426833..1a77a6637 100644 --- a/zcash_client_sqlite/src/wallet/transact.rs +++ b/zcash_client_sqlite/src/wallet/transact.rs @@ -14,7 +14,7 @@ use zcash_primitives::{ use zcash_client_backend::wallet::{AccountId, SpendableNote}; -use crate::{error::SqliteClientError, WalletDB}; +use crate::{error::SqliteClientError, WalletDb}; fn to_spendable_note(row: &Row) -> Result { let diversifier = { @@ -60,7 +60,7 @@ fn to_spendable_note(row: &Row) -> Result { } pub fn get_spendable_notes

( - wdb: &WalletDB

, + wdb: &WalletDb

, account: AccountId, anchor_height: BlockHeight, ) -> Result, SqliteClientError> { @@ -88,7 +88,7 @@ pub fn get_spendable_notes

( } pub fn select_spendable_notes

( - wdb: &WalletDB

, + wdb: &WalletDb

, account: AccountId, target_value: Amount, anchor_height: BlockHeight, @@ -175,7 +175,7 @@ mod tests { get_balance, get_balance_at, init::{init_accounts_table, init_blocks_table, init_wallet_db}, }, - AccountId, BlockDB, DataConnStmtCache, WalletDB, + AccountId, BlockDb, DataConnStmtCache, WalletDb, }; fn test_prover() -> impl TxProver { @@ -190,7 +190,7 @@ mod tests { #[test] fn create_to_address_fails_on_incorrect_extsk() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add two accounts to the wallet @@ -239,7 +239,7 @@ mod tests { #[test] fn create_to_address_fails_with_no_blocks() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -269,7 +269,7 @@ mod tests { #[test] fn create_to_address_fails_on_insufficient_balance() { let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); init_blocks_table( &db_data, @@ -313,11 +313,11 @@ mod tests { #[test] fn create_to_address_fails_on_unverified_notes() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB(Connection::open(cache_file.path()).unwrap()); + let db_cache = BlockDb(Connection::open(cache_file.path()).unwrap()); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -440,11 +440,11 @@ mod tests { #[test] fn create_to_address_fails_on_locked_notes() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB(Connection::open(cache_file.path()).unwrap()); + let db_cache = BlockDb(Connection::open(cache_file.path()).unwrap()); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -561,11 +561,11 @@ mod tests { fn ovk_policy_prevents_recovery_from_chain() { let network = tests::network(); let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB(Connection::open(cache_file.path()).unwrap()); + let db_cache = BlockDb(Connection::open(cache_file.path()).unwrap()); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), network).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), network).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet @@ -670,11 +670,11 @@ mod tests { #[test] fn create_to_address_succeeds_to_t_addr_zero_change() { let cache_file = NamedTempFile::new().unwrap(); - let db_cache = BlockDB(Connection::open(cache_file.path()).unwrap()); + let db_cache = BlockDb(Connection::open(cache_file.path()).unwrap()); init_cache_database(&db_cache).unwrap(); let data_file = NamedTempFile::new().unwrap(); - let db_data = WalletDB::for_path(data_file.path(), tests::network()).unwrap(); + let db_data = WalletDb::for_path(data_file.path(), tests::network()).unwrap(); init_wallet_db(&db_data).unwrap(); // Add an account to the wallet diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 713f73a22..fe3dceb7e 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -17,6 +17,10 @@ and this library adheres to Rust's notion of - `zcash_primitives::prover` - `zcash_primitives::redjubjub` - `zcash_primitives::util::{hash_to_scalar, generate_random_rseed}` +- Renamed the following in `zcash_primitives::transaction::components` to use + lower-case abbreviations (matching Rust naming conventions): + - `JSDescription` to `JsDescription` + - `SproutProof::PHGR` to `SproutProof::Phgr` ## [0.5.0] - 2021-03-26 ### Added diff --git a/zcash_primitives/src/transaction/components.rs b/zcash_primitives/src/transaction/components.rs index 352166a93..258381ab0 100644 --- a/zcash_primitives/src/transaction/components.rs +++ b/zcash_primitives/src/transaction/components.rs @@ -8,7 +8,7 @@ pub mod tze; pub use self::{ amount::Amount, sapling::{OutputDescription, SpendDescription}, - sprout::JSDescription, + sprout::JsDescription, transparent::{OutPoint, TxIn, TxOut}, }; diff --git a/zcash_primitives/src/transaction/components/sprout.rs b/zcash_primitives/src/transaction/components/sprout.rs index d57afc82b..7c72b39e9 100644 --- a/zcash_primitives/src/transaction/components/sprout.rs +++ b/zcash_primitives/src/transaction/components/sprout.rs @@ -13,20 +13,20 @@ const ZC_NUM_JS_OUTPUTS: usize = 2; #[derive(Clone)] pub(crate) enum SproutProof { Groth([u8; GROTH_PROOF_SIZE]), - PHGR([u8; PHGR_PROOF_SIZE]), + Phgr([u8; PHGR_PROOF_SIZE]), } impl std::fmt::Debug for SproutProof { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match self { SproutProof::Groth(_) => write!(f, "SproutProof::Groth"), - SproutProof::PHGR(_) => write!(f, "SproutProof::PHGR"), + SproutProof::Phgr(_) => write!(f, "SproutProof::PHGR"), } } } #[derive(Clone)] -pub struct JSDescription { +pub struct JsDescription { pub(crate) vpub_old: Amount, pub(crate) vpub_new: Amount, pub(crate) anchor: [u8; 32], @@ -39,7 +39,7 @@ pub struct JSDescription { pub(crate) ciphertexts: [[u8; 601]; ZC_NUM_JS_OUTPUTS], } -impl std::fmt::Debug for JSDescription { +impl std::fmt::Debug for JsDescription { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { write!( f, @@ -63,7 +63,7 @@ impl std::fmt::Debug for JSDescription { } } -impl JSDescription { +impl JsDescription { pub fn read(mut reader: R, use_groth: bool) -> io::Result { // Consensus rule (§4.3): Canonical encoding is enforced here let vpub_old = { @@ -125,7 +125,7 @@ impl JSDescription { // - Proof validity is enforced by JSDescription::Verify() in zcashd let mut proof = [0u8; PHGR_PROOF_SIZE]; reader.read_exact(&mut proof)?; - SproutProof::PHGR(proof) + SproutProof::Phgr(proof) }; let mut ciphertexts = [[0u8; 601]; ZC_NUM_JS_OUTPUTS]; @@ -134,7 +134,7 @@ impl JSDescription { .map(|ct| reader.read_exact(ct)) .collect::>()?; - Ok(JSDescription { + Ok(JsDescription { vpub_old, vpub_new, anchor, @@ -163,7 +163,7 @@ impl JSDescription { match &self.proof { SproutProof::Groth(p) => writer.write_all(p)?, - SproutProof::PHGR(p) => writer.write_all(p)?, + SproutProof::Phgr(p) => writer.write_all(p)?, } writer.write_all(&self.ciphertexts[0])?; diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index c705e275d..78bdf9546 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -19,7 +19,7 @@ mod tests; pub use self::sighash::{signature_hash, signature_hash_data, SignableInput, SIGHASH_ALL}; -use self::components::{Amount, JSDescription, OutputDescription, SpendDescription, TxIn, TxOut}; +use self::components::{Amount, JsDescription, OutputDescription, SpendDescription, TxIn, TxOut}; #[cfg(feature = "zfuture")] use self::components::{TzeIn, TzeOut}; @@ -183,7 +183,7 @@ pub struct TransactionData { pub value_balance: Amount, pub shielded_spends: Vec, pub shielded_outputs: Vec, - pub joinsplits: Vec, + pub joinsplits: Vec, pub joinsplit_pubkey: Option<[u8; 32]>, pub joinsplit_sig: Option<[u8; 64]>, pub binding_sig: Option, @@ -349,7 +349,7 @@ impl Transaction { let (joinsplits, joinsplit_pubkey, joinsplit_sig) = if version.has_sprout() { let jss = Vector::read(&mut reader, |r| { - JSDescription::read(r, version.uses_groth_proofs()) + JsDescription::read(r, version.uses_groth_proofs()) })?; let (pubkey, sig) = if !jss.is_empty() { let mut joinsplit_pubkey = [0; 32]; diff --git a/zcash_primitives/src/transaction/sighash.rs b/zcash_primitives/src/transaction/sighash.rs index a0ed20f7b..7189e6d7f 100644 --- a/zcash_primitives/src/transaction/sighash.rs +++ b/zcash_primitives/src/transaction/sighash.rs @@ -15,7 +15,7 @@ use crate::{ }; use super::{ - components::{Amount, JSDescription, OutputDescription, SpendDescription, TxIn, TxOut}, + components::{Amount, JsDescription, OutputDescription, SpendDescription, TxIn, TxOut}, Transaction, TransactionData, TxVersion, }; @@ -122,7 +122,7 @@ fn single_output_hash(tx_out: &TxOut) -> Blake2bHash { fn joinsplits_hash( txversion: TxVersion, - joinsplits: &[JSDescription], + joinsplits: &[JsDescription], joinsplit_pubkey: &[u8; 32], ) -> Blake2bHash { let mut data = Vec::with_capacity( diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index c5c4f3532..ec957a918 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -32,9 +32,9 @@ fn derive_child_ovk(parent: &OutgoingViewingKey, i_l: &[u8]) -> OutgoingViewingK // ZIP 32 structures /// A Sapling full viewing key fingerprint -struct FVKFingerprint([u8; 32]); +struct FvkFingerprint([u8; 32]); -impl From<&FullViewingKey> for FVKFingerprint { +impl From<&FullViewingKey> for FvkFingerprint { fn from(fvk: &FullViewingKey) -> Self { let mut h = Blake2bParams::new() .hash_length(32) @@ -43,25 +43,25 @@ impl From<&FullViewingKey> for FVKFingerprint { h.update(&fvk.to_bytes()); let mut fvfp = [0u8; 32]; fvfp.copy_from_slice(h.finalize().as_bytes()); - FVKFingerprint(fvfp) + FvkFingerprint(fvfp) } } /// A Sapling full viewing key tag #[derive(Clone, Copy, Debug, PartialEq)] -struct FVKTag([u8; 4]); +struct FvkTag([u8; 4]); -impl FVKFingerprint { - fn tag(&self) -> FVKTag { +impl FvkFingerprint { + fn tag(&self) -> FvkTag { let mut tag = [0u8; 4]; tag.copy_from_slice(&self.0[..4]); - FVKTag(tag) + FvkTag(tag) } } -impl FVKTag { +impl FvkTag { fn master() -> Self { - FVKTag([0u8; 4]) + FvkTag([0u8; 4]) } } @@ -174,7 +174,7 @@ impl DiversifierKey { #[derive(Clone)] pub struct ExtendedSpendingKey { depth: u8, - parent_fvk_tag: FVKTag, + parent_fvk_tag: FvkTag, child_index: ChildIndex, chain_code: ChainCode, pub expsk: ExpandedSpendingKey, @@ -185,7 +185,7 @@ pub struct ExtendedSpendingKey { #[derive(Clone)] pub struct ExtendedFullViewingKey { depth: u8, - parent_fvk_tag: FVKTag, + parent_fvk_tag: FvkTag, child_index: ChildIndex, chain_code: ChainCode, pub fvk: FullViewingKey, @@ -251,7 +251,7 @@ impl ExtendedSpendingKey { ExtendedSpendingKey { depth: 0, - parent_fvk_tag: FVKTag::master(), + parent_fvk_tag: FvkTag::master(), child_index: ChildIndex::master(), chain_code: ChainCode(c_m), expsk: ExpandedSpendingKey::from_spending_key(sk_m), @@ -272,7 +272,7 @@ impl ExtendedSpendingKey { Ok(ExtendedSpendingKey { depth, - parent_fvk_tag: FVKTag(tag), + parent_fvk_tag: FvkTag(tag), child_index: ChildIndex::from_index(i), chain_code: ChainCode(c), expsk, @@ -326,7 +326,7 @@ impl ExtendedSpendingKey { ExtendedSpendingKey { depth: self.depth + 1, - parent_fvk_tag: FVKFingerprint::from(&fvk).tag(), + parent_fvk_tag: FvkFingerprint::from(&fvk).tag(), child_index: i, chain_code: ChainCode(c_i), expsk: { @@ -373,7 +373,7 @@ impl ExtendedFullViewingKey { Ok(ExtendedFullViewingKey { depth, - parent_fvk_tag: FVKTag(tag), + parent_fvk_tag: FvkTag(tag), child_index: ChildIndex::from_index(i), chain_code: ChainCode(c), fvk, @@ -410,7 +410,7 @@ impl ExtendedFullViewingKey { Ok(ExtendedFullViewingKey { depth: self.depth + 1, - parent_fvk_tag: FVKFingerprint::from(&self.fvk).tag(), + parent_fvk_tag: FvkFingerprint::from(&self.fvk).tag(), child_index: i, chain_code: ChainCode(c_i), fvk: { @@ -1035,7 +1035,7 @@ mod tests { let mut ser = vec![]; xfvk.write(&mut ser).unwrap(); assert_eq!(&ser[..], &tv.xfvk[..]); - assert_eq!(FVKFingerprint::from(&xfvk.fvk).0, tv.fp); + assert_eq!(FvkFingerprint::from(&xfvk.fvk).0, tv.fp); // d0 let mut di = DiversifierIndex::new(); diff --git a/zcash_proofs/CHANGELOG.md b/zcash_proofs/CHANGELOG.md index 0ffb5f94a..ff0305fb4 100644 --- a/zcash_proofs/CHANGELOG.md +++ b/zcash_proofs/CHANGELOG.md @@ -8,6 +8,10 @@ and this library adheres to Rust's notion of ## [Unreleased] ### Changed - MSRV is now 1.51.0. +- Renamed the following in `zcash_proofs::circuit::sprout` to use lower-case + abbreviations (matching Rust naming conventions): + - `JSInput` to `JsInput` + - `JSOutput` to `JsOutput` ## [0.5.0] - 2021-03-26 ### Added diff --git a/zcash_proofs/src/circuit/sprout/mod.rs b/zcash_proofs/src/circuit/sprout/mod.rs index 97ad21db4..427456fee 100644 --- a/zcash_proofs/src/circuit/sprout/mod.rs +++ b/zcash_proofs/src/circuit/sprout/mod.rs @@ -35,12 +35,12 @@ pub struct JoinSplit { pub vpub_new: Option, pub h_sig: Option<[u8; 32]>, pub phi: Option<[u8; 32]>, - pub inputs: Vec, - pub outputs: Vec, + pub inputs: Vec, + pub outputs: Vec, pub rt: Option<[u8; 32]>, } -pub struct JSInput { +pub struct JsInput { pub value: Option, pub a_sk: Option, pub rho: Option, @@ -48,7 +48,7 @@ pub struct JSInput { pub auth_path: [Option<([u8; 32], bool)>; TREE_DEPTH], } -pub struct JSOutput { +pub struct JsOutput { pub value: Option, pub a_pk: Option, pub r: Option, @@ -389,7 +389,7 @@ fn test_sprout_constraints() { let r = Some(CommitmentRandomness(get_u256(&mut test_vector))); let a_sk = Some(SpendingKey(get_u256(&mut test_vector))); - inputs.push(JSInput { + inputs.push(JsInput { value, a_sk, rho, @@ -406,7 +406,7 @@ fn test_sprout_constraints() { get_u256(&mut test_vector); let r = Some(CommitmentRandomness(get_u256(&mut test_vector))); - outputs.push(JSOutput { value, a_pk, r }); + outputs.push(JsOutput { value, a_pk, r }); } let vpub_old = Some(test_vector.read_u64::().unwrap()); diff --git a/zcash_proofs/src/sprout.rs b/zcash_proofs/src/sprout.rs index e3fcdd9a4..832be3873 100644 --- a/zcash_proofs/src/sprout.rs +++ b/zcash_proofs/src/sprout.rs @@ -90,7 +90,7 @@ pub fn create_proof( position >>= 1; } - inputs.push(JSInput { + inputs.push(JsInput { value, a_sk, rho, @@ -106,7 +106,7 @@ pub fn create_proof( let mut outputs = Vec::with_capacity(2); { let mut handle_output = |a_pk, value, r| { - outputs.push(JSOutput { + outputs.push(JsOutput { value: Some(value), a_pk: Some(PayingKey(a_pk)), r: Some(CommitmentRandomness(r)), From 564c2714fe9e01c2adc62ea0c75cdc5d19b4c571 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Mar 2021 18:33:02 +1300 Subject: [PATCH 2/5] clippy: Use Iterator::try_for_each --- zcash_primitives/src/serialize.rs | 2 +- .../src/transaction/components/sprout.rs | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/zcash_primitives/src/serialize.rs b/zcash_primitives/src/serialize.rs index 46ee9a1c3..e09fc44d1 100644 --- a/zcash_primitives/src/serialize.rs +++ b/zcash_primitives/src/serialize.rs @@ -78,7 +78,7 @@ impl Vector { F: Fn(&mut W, &E) -> io::Result<()>, { CompactSize::write(&mut writer, vec.len())?; - vec.iter().map(|e| func(&mut writer, e)).collect() + vec.iter().try_for_each(|e| func(&mut writer, e)) } } diff --git a/zcash_primitives/src/transaction/components/sprout.rs b/zcash_primitives/src/transaction/components/sprout.rs index 7c72b39e9..88b212ce7 100644 --- a/zcash_primitives/src/transaction/components/sprout.rs +++ b/zcash_primitives/src/transaction/components/sprout.rs @@ -90,14 +90,12 @@ impl JsDescription { let mut nullifiers = [[0u8; 32]; ZC_NUM_JS_INPUTS]; nullifiers .iter_mut() - .map(|nf| reader.read_exact(nf)) - .collect::>()?; + .try_for_each(|nf| reader.read_exact(nf))?; let mut commitments = [[0u8; 32]; ZC_NUM_JS_OUTPUTS]; commitments .iter_mut() - .map(|cm| reader.read_exact(cm)) - .collect::>()?; + .try_for_each(|cm| reader.read_exact(cm))?; // Consensus rule (§4.3): Canonical encoding is enforced by // ZCNoteDecryption::decrypt() in zcashd @@ -108,9 +106,7 @@ impl JsDescription { reader.read_exact(&mut random_seed)?; let mut macs = [[0u8; 32]; ZC_NUM_JS_INPUTS]; - macs.iter_mut() - .map(|mac| reader.read_exact(mac)) - .collect::>()?; + macs.iter_mut().try_for_each(|mac| reader.read_exact(mac))?; let proof = if use_groth { // Consensus rules (§4.3): @@ -131,8 +127,7 @@ impl JsDescription { let mut ciphertexts = [[0u8; 601]; ZC_NUM_JS_OUTPUTS]; ciphertexts .iter_mut() - .map(|ct| reader.read_exact(ct)) - .collect::>()?; + .try_for_each(|ct| reader.read_exact(ct))?; Ok(JsDescription { vpub_old, From 56b577b31eba34dc501f8ae95025a48071e623fb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Mar 2021 18:33:39 +1300 Subject: [PATCH 3/5] clippy: Fix small lints --- components/zcash_note_encryption/src/lib.rs | 1 + zcash_client_backend/src/zip321.rs | 6 +++--- zcash_history/src/node_data.rs | 6 ++++-- zcash_history/src/tree.rs | 4 ++-- zcash_primitives/src/transaction/components/amount.rs | 2 +- zcash_primitives/src/transaction/sighash.rs | 8 ++++---- zcash_primitives/src/zip32.rs | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/zcash_note_encryption/src/lib.rs b/components/zcash_note_encryption/src/lib.rs index 31e1bb209..0ee39e7ab 100644 --- a/components/zcash_note_encryption/src/lib.rs +++ b/components/zcash_note_encryption/src/lib.rs @@ -1,5 +1,6 @@ #[cfg(test)] mod tests { + #[allow(clippy::eq_op)] #[test] fn it_works() { assert_eq!(2 + 2, 4); diff --git a/zcash_client_backend/src/zip321.rs b/zcash_client_backend/src/zip321.rs index 801cb009d..bc2d8300b 100644 --- a/zcash_client_backend/src/zip321.rs +++ b/zcash_client_backend/src/zip321.rs @@ -80,9 +80,9 @@ impl Payment { /// internally, so payments must be normalized prior to being passed to the comparison function /// returned from this method. #[cfg(any(test, feature = "test-dependencies"))] - pub(in crate::zip321) fn compare_normalized<'a, P: consensus::Parameters>( - params: &'a P, - ) -> impl Fn(&Payment, &Payment) -> Ordering + 'a { + pub(in crate::zip321) fn compare_normalized( + params: &P, + ) -> impl Fn(&Payment, &Payment) -> Ordering + '_ { move |a: &Payment, b: &Payment| { let a_addr = a.recipient_address.encode(params); let b_addr = b.recipient_address.encode(params); diff --git a/zcash_history/src/node_data.rs b/zcash_history/src/node_data.rs index 8e1f10440..0c93c9f78 100644 --- a/zcash_history/src/node_data.rs +++ b/zcash_history/src/node_data.rs @@ -207,8 +207,10 @@ impl NodeData { #[cfg(test)] impl quickcheck::Arbitrary for NodeData { fn arbitrary(gen: &mut G) -> Self { - let mut node_data = NodeData::default(); - node_data.consensus_branch_id = 0; + let mut node_data = NodeData { + consensus_branch_id: 0, + ..Default::default() + }; gen.fill_bytes(&mut node_data.subtree_commitment[..]); node_data.start_time = gen.next_u32(); node_data.end_time = gen.next_u32(); diff --git a/zcash_history/src/tree.rs b/zcash_history/src/tree.rs index 71daa1144..666623741 100644 --- a/zcash_history/src/tree.rs +++ b/zcash_history/src/tree.rs @@ -651,7 +651,7 @@ mod tests { } fn leaf_count(number: u32) -> TestResult { - if number > 1024 * 1024 || number < 3 { + if !(3..=1024 * 1024).contains(&number) { TestResult::discard() } else { let mut tree = initial(); @@ -666,7 +666,7 @@ mod tests { } fn parity(number: u32) -> TestResult { - if number > 2048 * 2048 || number < 3 { + if !(3..=2048 * 2048).contains(&number) { TestResult::discard() } else { let mut tree = initial(); diff --git a/zcash_primitives/src/transaction/components/amount.rs b/zcash_primitives/src/transaction/components/amount.rs index f46c0b820..f47b485f7 100644 --- a/zcash_primitives/src/transaction/components/amount.rs +++ b/zcash_primitives/src/transaction/components/amount.rs @@ -41,7 +41,7 @@ impl Amount { /// /// Returns an error if the amount is outside the range `{0..MAX_MONEY}`. pub fn from_nonnegative_i64(amount: i64) -> Result { - if 0 <= amount && amount <= MAX_MONEY { + if (0..=MAX_MONEY).contains(&amount) { Ok(Amount(amount)) } else { Err(()) diff --git a/zcash_primitives/src/transaction/sighash.rs b/zcash_primitives/src/transaction/sighash.rs index 7189e6d7f..604e33b2f 100644 --- a/zcash_primitives/src/transaction/sighash.rs +++ b/zcash_primitives/src/transaction/sighash.rs @@ -227,11 +227,11 @@ impl<'a> SignableInput<'a> { } } -pub fn signature_hash_data<'a>( +pub fn signature_hash_data( tx: &TransactionData, consensus_branch_id: consensus::BranchId, hash_type: u32, - signable_input: SignableInput<'a>, + signable_input: SignableInput<'_>, ) -> Vec { if has_overwinter_components(&tx.version) { let mut personal = [0; 16]; @@ -372,11 +372,11 @@ pub fn signature_hash_data<'a>( } } -pub fn signature_hash<'a>( +pub fn signature_hash( tx: &Transaction, consensus_branch_id: consensus::BranchId, hash_type: u32, - signable_input: SignableInput<'a>, + signable_input: SignableInput<'_>, ) -> Vec { signature_hash_data(tx, consensus_branch_id, hash_type, signable_input) } diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index ec957a918..8fb1ee402 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -586,7 +586,7 @@ mod tests { d1: Option<[u8; 11]>, d2: Option<[u8; 11]>, dmax: Option<[u8; 11]>, - }; + } // From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_zip32.py let test_vectors = vec![ From 63db2729e9fc2cc52bd9d1eb108e7cef2ca3d491 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Mar 2021 18:54:29 +1300 Subject: [PATCH 4/5] Temporarily allow clippy::result_unit_err lint Fixing these lints is deferred to zcash/librustzcash#367. --- zcash_client_backend/src/lib.rs | 2 ++ zcash_primitives/src/lib.rs | 2 ++ zcash_proofs/src/lib.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/zcash_client_backend/src/lib.rs b/zcash_client_backend/src/lib.rs index 9d72cb471..085070c13 100644 --- a/zcash_client_backend/src/lib.rs +++ b/zcash_client_backend/src/lib.rs @@ -5,6 +5,8 @@ // Catch documentation errors caused by code changes. #![deny(broken_intra_doc_links)] +// Temporary until we have addressed all Result cases. +#![allow(clippy::result_unit_err)] pub mod address; pub mod data_api; diff --git a/zcash_primitives/src/lib.rs b/zcash_primitives/src/lib.rs index af4a48714..67d0f3f7b 100644 --- a/zcash_primitives/src/lib.rs +++ b/zcash_primitives/src/lib.rs @@ -6,6 +6,8 @@ #![cfg_attr(docsrs, feature(doc_cfg))] // Catch documentation errors caused by code changes. #![deny(broken_intra_doc_links)] +// Temporary until we have addressed all Result cases. +#![allow(clippy::result_unit_err)] pub mod block; pub mod consensus; diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 4decc0d3b..1479f54f9 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -6,6 +6,8 @@ #![cfg_attr(docsrs, feature(doc_cfg))] // Catch documentation errors caused by code changes. #![deny(broken_intra_doc_links)] +// Temporary until we have addressed all Result cases. +#![allow(clippy::result_unit_err)] use bellman::groth16::{prepare_verifying_key, Parameters, PreparedVerifyingKey, VerifyingKey}; use bls12_381::Bls12; From 2f3847638d3ef3536e53443214299353e5a5b152 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 2 Apr 2021 10:39:25 +1300 Subject: [PATCH 5/5] zcash_primitives: Revert to SproutProof::PHGR Unlike regular acronyms or abbreviations, this is author initials, which we've decided to keep capitalised. --- zcash_primitives/CHANGELOG.md | 6 ++---- zcash_primitives/src/transaction/components/sprout.rs | 9 +++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index fe3dceb7e..f87f53d1f 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -17,10 +17,8 @@ and this library adheres to Rust's notion of - `zcash_primitives::prover` - `zcash_primitives::redjubjub` - `zcash_primitives::util::{hash_to_scalar, generate_random_rseed}` -- Renamed the following in `zcash_primitives::transaction::components` to use - lower-case abbreviations (matching Rust naming conventions): - - `JSDescription` to `JsDescription` - - `SproutProof::PHGR` to `SproutProof::Phgr` +- Renamed `zcash_primitives::transaction::components::JSDescription` to + `JsDescription` (matching Rust naming conventions). ## [0.5.0] - 2021-03-26 ### Added diff --git a/zcash_primitives/src/transaction/components/sprout.rs b/zcash_primitives/src/transaction/components/sprout.rs index 88b212ce7..a143eafb3 100644 --- a/zcash_primitives/src/transaction/components/sprout.rs +++ b/zcash_primitives/src/transaction/components/sprout.rs @@ -13,14 +13,15 @@ const ZC_NUM_JS_OUTPUTS: usize = 2; #[derive(Clone)] pub(crate) enum SproutProof { Groth([u8; GROTH_PROOF_SIZE]), - Phgr([u8; PHGR_PROOF_SIZE]), + #[allow(clippy::upper_case_acronyms)] + PHGR([u8; PHGR_PROOF_SIZE]), } impl std::fmt::Debug for SproutProof { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match self { SproutProof::Groth(_) => write!(f, "SproutProof::Groth"), - SproutProof::Phgr(_) => write!(f, "SproutProof::PHGR"), + SproutProof::PHGR(_) => write!(f, "SproutProof::PHGR"), } } } @@ -121,7 +122,7 @@ impl JsDescription { // - Proof validity is enforced by JSDescription::Verify() in zcashd let mut proof = [0u8; PHGR_PROOF_SIZE]; reader.read_exact(&mut proof)?; - SproutProof::Phgr(proof) + SproutProof::PHGR(proof) }; let mut ciphertexts = [[0u8; 601]; ZC_NUM_JS_OUTPUTS]; @@ -158,7 +159,7 @@ impl JsDescription { match &self.proof { SproutProof::Groth(p) => writer.write_all(p)?, - SproutProof::Phgr(p) => writer.write_all(p)?, + SproutProof::PHGR(p) => writer.write_all(p)?, } writer.write_all(&self.ciphertexts[0])?;