Renames to use lower-case abbreviations (matching Rust convention)
As of our MSRV bump to 1.51.0, we get lints for this.
This commit is contained in:
parent
6fa90197fe
commit
636845d0f9
|
@ -8,6 +8,10 @@ and this library adheres to Rust's notion of
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Changed
|
### Changed
|
||||||
- MSRV is now 1.51.0.
|
- 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
|
## [0.5.0] - 2021-03-26
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -309,9 +309,9 @@ pub mod testing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MockWalletDB {}
|
pub struct MockWalletDb {}
|
||||||
|
|
||||||
impl WalletRead for MockWalletDB {
|
impl WalletRead for MockWalletDb {
|
||||||
type Error = Error<u32>;
|
type Error = Error<u32>;
|
||||||
type NoteRef = u32;
|
type NoteRef = u32;
|
||||||
type TxRef = TxId;
|
type TxRef = TxId;
|
||||||
|
@ -398,7 +398,7 @@ pub mod testing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalletWrite for MockWalletDB {
|
impl WalletWrite for MockWalletDb {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn advance_by_block(
|
fn advance_by_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! use zcash_client_sqlite::{
|
//! use zcash_client_sqlite::{
|
||||||
//! BlockDB,
|
//! BlockDb,
|
||||||
//! WalletDB,
|
//! WalletDb,
|
||||||
//! error::SqliteClientError,
|
//! error::SqliteClientError,
|
||||||
//! wallet::{rewind_to_height},
|
//! wallet::{rewind_to_height},
|
||||||
//! wallet::init::{init_wallet_db},
|
//! wallet::init::{init_wallet_db},
|
||||||
|
@ -37,9 +37,9 @@
|
||||||
//! # fn test() -> Result<(), SqliteClientError> {
|
//! # fn test() -> Result<(), SqliteClientError> {
|
||||||
//! let network = Network::TestNetwork;
|
//! let network = Network::TestNetwork;
|
||||||
//! let cache_file = NamedTempFile::new()?;
|
//! 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_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)?;
|
//! init_wallet_db(&db_read)?;
|
||||||
//!
|
//!
|
||||||
//! let mut db_data = db_read.get_update_ops()?;
|
//! let mut db_data = db_read.get_update_ops()?;
|
||||||
|
@ -211,8 +211,8 @@ where
|
||||||
/// data_api::chain::scan_cached_blocks,
|
/// data_api::chain::scan_cached_blocks,
|
||||||
/// };
|
/// };
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// BlockDB,
|
/// BlockDb,
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// error::SqliteClientError,
|
/// error::SqliteClientError,
|
||||||
/// wallet::init::init_wallet_db,
|
/// wallet::init::init_wallet_db,
|
||||||
/// };
|
/// };
|
||||||
|
@ -225,10 +225,10 @@ where
|
||||||
/// #
|
/// #
|
||||||
/// # fn test() -> Result<(), SqliteClientError> {
|
/// # fn test() -> Result<(), SqliteClientError> {
|
||||||
/// let cache_file = NamedTempFile::new().unwrap();
|
/// 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 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)?;
|
/// init_wallet_db(&db_read)?;
|
||||||
///
|
///
|
||||||
/// let mut data = db_read.get_update_ops()?;
|
/// let mut data = db_read.get_update_ops()?;
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub enum Error<NoteId> {
|
||||||
InvalidChain(BlockHeight, ChainInvalid),
|
InvalidChain(BlockHeight, ChainInvalid),
|
||||||
|
|
||||||
/// A provided extsk is not associated with the specified account.
|
/// 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
|
/// 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.
|
/// not correspond to root of the stored commitment tree at the recorded height.
|
||||||
|
@ -80,7 +80,7 @@ impl<N: fmt::Display> fmt::Display for Error<N> {
|
||||||
Error::InvalidChain(upper_bound, cause) => {
|
Error::InvalidChain(upper_bound, cause) => {
|
||||||
write!(f, "Invalid chain (upper bound: {}): {:?}", u32::from(*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)
|
write!(f, "Incorrect ExtendedSpendingKey for account {}", account.0)
|
||||||
}
|
}
|
||||||
Error::InvalidNewWitnessAnchor(output, txid, last_height, anchor) => write!(
|
Error::InvalidNewWitnessAnchor(output, txid, last_height, anchor) => write!(
|
||||||
|
|
|
@ -103,7 +103,7 @@ where
|
||||||
/// wallet::{AccountId, OvkPolicy},
|
/// wallet::{AccountId, OvkPolicy},
|
||||||
/// };
|
/// };
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// error::SqliteClientError,
|
/// error::SqliteClientError,
|
||||||
/// wallet::init::init_wallet_db,
|
/// wallet::init::init_wallet_db,
|
||||||
/// };
|
/// };
|
||||||
|
@ -127,7 +127,7 @@ where
|
||||||
/// let to = extsk.default_address().unwrap().1.into();
|
/// let to = extsk.default_address().unwrap().1.into();
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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)?;
|
/// init_wallet_db(&db_read)?;
|
||||||
/// let mut db = db_read.get_update_ops()?;
|
/// let mut db = db_read.get_update_ops()?;
|
||||||
///
|
///
|
||||||
|
@ -168,7 +168,7 @@ where
|
||||||
// ExtendedFullViewingKey for the account we are spending from.
|
// ExtendedFullViewingKey for the account we are spending from.
|
||||||
let extfvk = ExtendedFullViewingKey::from(extsk);
|
let extfvk = ExtendedFullViewingKey::from(extsk);
|
||||||
if !wallet_db.is_valid_account_extfvk(account, &extfvk)? {
|
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.
|
// Apply the outgoing viewing key policy.
|
||||||
|
|
|
@ -8,6 +8,12 @@ and this library adheres to Rust's notion of
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Changed
|
### Changed
|
||||||
- MSRV is now 1.51.0.
|
- 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
|
## [0.3.0] - 2021-03-26
|
||||||
This release contains a major refactor of the APIs to leverage the new Data
|
This release contains a major refactor of the APIs to leverage the new Data
|
||||||
|
|
|
@ -7,7 +7,7 @@ use zcash_primitives::consensus::BlockHeight;
|
||||||
|
|
||||||
use zcash_client_backend::{data_api::error::Error, proto::compact_formats::CompactBlock};
|
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;
|
pub mod init;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ struct CompactBlockRow {
|
||||||
/// value provided is `None`, all blocks are traversed up to the
|
/// value provided is `None`, all blocks are traversed up to the
|
||||||
/// maximum height.
|
/// maximum height.
|
||||||
pub fn with_blocks<F>(
|
pub fn with_blocks<F>(
|
||||||
cache: &BlockDB,
|
cache: &BlockDb,
|
||||||
from_height: BlockHeight,
|
from_height: BlockHeight,
|
||||||
limit: Option<u32>,
|
limit: Option<u32>,
|
||||||
mut with_row: F,
|
mut with_row: F,
|
||||||
|
@ -92,17 +92,17 @@ mod tests {
|
||||||
init::{init_accounts_table, init_wallet_db},
|
init::{init_accounts_table, init_wallet_db},
|
||||||
rewind_to_height,
|
rewind_to_height,
|
||||||
},
|
},
|
||||||
AccountId, BlockDB, NoteId, WalletDB,
|
AccountId, BlockDb, NoteId, WalletDb,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valid_chain_states() {
|
fn valid_chain_states() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -179,11 +179,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_chain_cache_disconnected() {
|
fn invalid_chain_cache_disconnected() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -251,11 +251,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_chain_cache_reorg() {
|
fn invalid_chain_cache_reorg() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -323,11 +323,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn data_db_rewinding() {
|
fn data_db_rewinding() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -382,11 +382,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn scan_cached_blocks_requires_sequential_blocks() {
|
fn scan_cached_blocks_requires_sequential_blocks() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -443,11 +443,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn scan_cached_blocks_finds_received_notes() {
|
fn scan_cached_blocks_finds_received_notes() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -491,11 +491,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn scan_cached_blocks_finds_change_notes() {
|
fn scan_cached_blocks_finds_change_notes() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use rusqlite::NO_PARAMS;
|
use rusqlite::NO_PARAMS;
|
||||||
|
|
||||||
use crate::BlockDB;
|
use crate::BlockDb;
|
||||||
|
|
||||||
/// Sets up the internal structure of the cache database.
|
/// Sets up the internal structure of the cache database.
|
||||||
///
|
///
|
||||||
|
@ -11,15 +11,15 @@ use crate::BlockDB;
|
||||||
/// ```
|
/// ```
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// BlockDB,
|
/// BlockDb,
|
||||||
/// chain::init::init_cache_database,
|
/// chain::init::init_cache_database,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let cache_file = NamedTempFile::new().unwrap();
|
/// 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();
|
/// 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(
|
db_cache.0.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS compactblocks (
|
"CREATE TABLE IF NOT EXISTS compactblocks (
|
||||||
height INTEGER PRIMARY KEY,
|
height INTEGER PRIMARY KEY,
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub enum SqliteClientError {
|
||||||
CorruptedData(String),
|
CorruptedData(String),
|
||||||
|
|
||||||
/// Decoding of the extended full viewing key has failed (for the specified network)
|
/// 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.
|
/// The rcm value for a note cannot be decoded to a valid JubJub point.
|
||||||
InvalidNote,
|
InvalidNote,
|
||||||
|
@ -63,7 +63,7 @@ impl fmt::Display for SqliteClientError {
|
||||||
SqliteClientError::CorruptedData(reason) => {
|
SqliteClientError::CorruptedData(reason) => {
|
||||||
write!(f, "Data DB is corrupted: {}", 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::InvalidNote => write!(f, "Invalid note"),
|
||||||
SqliteClientError::InvalidNoteId => write!(f, "The note ID associated with an inserted witness must correspond to a received 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),
|
SqliteClientError::Bech32(e) => write!(f, "{}", e),
|
||||||
|
|
|
@ -81,15 +81,15 @@ impl fmt::Display for NoteId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper for the SQLite connection to the wallet database.
|
/// A wrapper for the SQLite connection to the wallet database.
|
||||||
pub struct WalletDB<P> {
|
pub struct WalletDb<P> {
|
||||||
conn: Connection,
|
conn: Connection,
|
||||||
params: P,
|
params: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: consensus::Parameters> WalletDB<P> {
|
impl<P: consensus::Parameters> WalletDb<P> {
|
||||||
/// Construct a connection to the wallet database stored at the specified path.
|
/// Construct a connection to the wallet database stored at the specified path.
|
||||||
pub fn for_path<F: AsRef<Path>>(path: F, params: P) -> Result<Self, rusqlite::Error> {
|
pub fn for_path<F: AsRef<Path>>(path: F, params: P) -> Result<Self, rusqlite::Error> {
|
||||||
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
|
/// Given a wallet database connection, obtain a handle for the write operations
|
||||||
|
@ -170,7 +170,7 @@ impl<P: consensus::Parameters> WalletDB<P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: consensus::Parameters> WalletRead for WalletDB<P> {
|
impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
|
||||||
type Error = SqliteClientError;
|
type Error = SqliteClientError;
|
||||||
type NoteRef = NoteId;
|
type NoteRef = NoteId;
|
||||||
type TxRef = i64;
|
type TxRef = i64;
|
||||||
|
@ -265,7 +265,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDB<P> {
|
||||||
///
|
///
|
||||||
/// [`WalletWrite`]: zcash_client_backend::data_api::WalletWrite
|
/// [`WalletWrite`]: zcash_client_backend::data_api::WalletWrite
|
||||||
pub struct DataConnStmtCache<'a, P> {
|
pub struct DataConnStmtCache<'a, P> {
|
||||||
wallet_db: &'a WalletDB<P>,
|
wallet_db: &'a WalletDb<P>,
|
||||||
stmt_insert_block: Statement<'a>,
|
stmt_insert_block: Statement<'a>,
|
||||||
|
|
||||||
stmt_insert_tx_meta: 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.
|
/// 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.
|
/// Opens a connection to the wallet database stored at the specified path.
|
||||||
pub fn for_path<P: AsRef<Path>>(path: P) -> Result<Self, rusqlite::Error> {
|
pub fn for_path<P: AsRef<Path>>(path: P) -> Result<Self, rusqlite::Error> {
|
||||||
Connection::open(path).map(BlockDB)
|
Connection::open(path).map(BlockDb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockSource for BlockDB {
|
impl BlockSource for BlockDb {
|
||||||
type Error = SqliteClientError;
|
type Error = SqliteClientError;
|
||||||
|
|
||||||
fn with_blocks<F>(
|
fn with_blocks<F>(
|
||||||
|
@ -569,7 +569,7 @@ mod tests {
|
||||||
zip32::ExtendedFullViewingKey,
|
zip32::ExtendedFullViewingKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::BlockDB;
|
use super::BlockDb;
|
||||||
|
|
||||||
#[cfg(feature = "mainnet")]
|
#[cfg(feature = "mainnet")]
|
||||||
pub(crate) fn network() -> Network {
|
pub(crate) fn network() -> Network {
|
||||||
|
@ -730,7 +730,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a fake CompactBlock into the cache DB.
|
/// 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();
|
let cb_bytes = cb.write_to_bytes().unwrap();
|
||||||
db_cache
|
db_cache
|
||||||
.0
|
.0
|
||||||
|
|
|
@ -33,7 +33,7 @@ use zcash_client_backend::{
|
||||||
DecryptedOutput,
|
DecryptedOutput,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, WalletDB};
|
use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, WalletDb};
|
||||||
|
|
||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod transact;
|
pub mod transact;
|
||||||
|
@ -109,16 +109,16 @@ impl ShieldedOutput for DecryptedOutput {
|
||||||
/// };
|
/// };
|
||||||
/// use zcash_client_backend::wallet::AccountId;
|
/// use zcash_client_backend::wallet::AccountId;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_address,
|
/// wallet::get_address,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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));
|
/// let addr = get_address(&db, AccountId(0));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_address<P: consensus::Parameters>(
|
pub fn get_address<P: consensus::Parameters>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
) -> Result<Option<PaymentAddress>, SqliteClientError> {
|
) -> Result<Option<PaymentAddress>, SqliteClientError> {
|
||||||
let addr: String = wdb.conn.query_row(
|
let addr: String = wdb.conn.query_row(
|
||||||
|
@ -136,7 +136,7 @@ pub fn get_address<P: consensus::Parameters>(
|
||||||
///
|
///
|
||||||
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
|
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
|
||||||
pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
|
pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, SqliteClientError> {
|
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, SqliteClientError> {
|
||||||
// Fetch the ExtendedFullViewingKeys we are tracking
|
// Fetch the ExtendedFullViewingKeys we are tracking
|
||||||
let mut stmt_fetch_accounts = wdb
|
let mut stmt_fetch_accounts = wdb
|
||||||
|
@ -152,7 +152,7 @@ pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
|
||||||
&extfvk,
|
&extfvk,
|
||||||
)
|
)
|
||||||
.map_err(SqliteClientError::Bech32)
|
.map_err(SqliteClientError::Bech32)
|
||||||
.and_then(|k| k.ok_or(SqliteClientError::IncorrectHRPExtFVK))
|
.and_then(|k| k.ok_or(SqliteClientError::IncorrectHrpExtFvk))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok((acct, extfvk))
|
Ok((acct, extfvk))
|
||||||
|
@ -173,7 +173,7 @@ pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
|
||||||
///
|
///
|
||||||
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
|
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
|
||||||
pub fn is_valid_account_extfvk<P: consensus::Parameters>(
|
pub fn is_valid_account_extfvk<P: consensus::Parameters>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
extfvk: &ExtendedFullViewingKey,
|
extfvk: &ExtendedFullViewingKey,
|
||||||
) -> Result<bool, SqliteClientError> {
|
) -> Result<bool, SqliteClientError> {
|
||||||
|
@ -205,15 +205,15 @@ pub fn is_valid_account_extfvk<P: consensus::Parameters>(
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_client_backend::wallet::AccountId;
|
/// use zcash_client_backend::wallet::AccountId;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_balance,
|
/// wallet::get_balance,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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));
|
/// let addr = get_balance(&db, AccountId(0));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_balance<P>(wdb: &WalletDB<P>, account: AccountId) -> Result<Amount, SqliteClientError> {
|
pub fn get_balance<P>(wdb: &WalletDb<P>, account: AccountId) -> Result<Amount, SqliteClientError> {
|
||||||
let balance = wdb.conn.query_row(
|
let balance = wdb.conn.query_row(
|
||||||
"SELECT SUM(value) FROM received_notes
|
"SELECT SUM(value) FROM received_notes
|
||||||
INNER JOIN transactions ON transactions.id_tx = received_notes.tx
|
INNER JOIN transactions ON transactions.id_tx = received_notes.tx
|
||||||
|
@ -241,16 +241,16 @@ pub fn get_balance<P>(wdb: &WalletDB<P>, account: AccountId) -> Result<Amount, S
|
||||||
/// use zcash_primitives::consensus::{BlockHeight, Network};
|
/// use zcash_primitives::consensus::{BlockHeight, Network};
|
||||||
/// use zcash_client_backend::wallet::AccountId;
|
/// use zcash_client_backend::wallet::AccountId;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_balance_at,
|
/// wallet::get_balance_at,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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_at(&db, AccountId(0), BlockHeight::from_u32(0));
|
/// let addr = get_balance_at(&db, AccountId(0), BlockHeight::from_u32(0));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_balance_at<P>(
|
pub fn get_balance_at<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
anchor_height: BlockHeight,
|
anchor_height: BlockHeight,
|
||||||
) -> Result<Amount, SqliteClientError> {
|
) -> Result<Amount, SqliteClientError> {
|
||||||
|
@ -282,15 +282,15 @@ pub fn get_balance_at<P>(
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// NoteId,
|
/// NoteId,
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_received_memo,
|
/// wallet::get_received_memo,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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);
|
/// let memo = get_received_memo(&db, 27);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_received_memo<P>(wdb: &WalletDB<P>, id_note: i64) -> Result<Memo, SqliteClientError> {
|
pub fn get_received_memo<P>(wdb: &WalletDb<P>, id_note: i64) -> Result<Memo, SqliteClientError> {
|
||||||
let memo_bytes: Vec<_> = wdb.conn.query_row(
|
let memo_bytes: Vec<_> = wdb.conn.query_row(
|
||||||
"SELECT memo FROM received_notes
|
"SELECT memo FROM received_notes
|
||||||
WHERE id_note = ?",
|
WHERE id_note = ?",
|
||||||
|
@ -315,15 +315,15 @@ pub fn get_received_memo<P>(wdb: &WalletDB<P>, id_note: i64) -> Result<Memo, Sql
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// NoteId,
|
/// NoteId,
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_sent_memo,
|
/// wallet::get_sent_memo,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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_sent_memo(&db, 12);
|
/// let memo = get_sent_memo(&db, 12);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_sent_memo<P>(wdb: &WalletDB<P>, id_note: i64) -> Result<Memo, SqliteClientError> {
|
pub fn get_sent_memo<P>(wdb: &WalletDb<P>, id_note: i64) -> Result<Memo, SqliteClientError> {
|
||||||
let memo_bytes: Vec<_> = wdb.conn.query_row(
|
let memo_bytes: Vec<_> = wdb.conn.query_row(
|
||||||
"SELECT memo FROM sent_notes
|
"SELECT memo FROM sent_notes
|
||||||
WHERE id_note = ?",
|
WHERE id_note = ?",
|
||||||
|
@ -344,16 +344,16 @@ pub fn get_sent_memo<P>(wdb: &WalletDB<P>, id_note: i64) -> Result<Memo, SqliteC
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::block_height_extrema,
|
/// wallet::block_height_extrema,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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 bounds = block_height_extrema(&db);
|
/// let bounds = block_height_extrema(&db);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn block_height_extrema<P>(
|
pub fn block_height_extrema<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
) -> Result<Option<(BlockHeight, BlockHeight)>, rusqlite::Error> {
|
) -> Result<Option<(BlockHeight, BlockHeight)>, rusqlite::Error> {
|
||||||
wdb.conn
|
wdb.conn
|
||||||
.query_row(
|
.query_row(
|
||||||
|
@ -383,16 +383,16 @@ pub fn block_height_extrema<P>(
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_primitives::transaction::TxId;
|
/// use zcash_primitives::transaction::TxId;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_tx_height,
|
/// wallet::get_tx_height,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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]));
|
/// let height = get_tx_height(&db, TxId([0u8; 32]));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_tx_height<P>(
|
pub fn get_tx_height<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
txid: TxId,
|
txid: TxId,
|
||||||
) -> Result<Option<BlockHeight>, rusqlite::Error> {
|
) -> Result<Option<BlockHeight>, rusqlite::Error> {
|
||||||
wdb.conn
|
wdb.conn
|
||||||
|
@ -413,16 +413,16 @@ pub fn get_tx_height<P>(
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::consensus::{H0, Network};
|
/// use zcash_primitives::consensus::{H0, Network};
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_block_hash,
|
/// wallet::get_block_hash,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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);
|
/// let hash = get_block_hash(&db, H0);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_block_hash<P>(
|
pub fn get_block_hash<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
block_height: BlockHeight,
|
block_height: BlockHeight,
|
||||||
) -> Result<Option<BlockHash>, rusqlite::Error> {
|
) -> Result<Option<BlockHash>, rusqlite::Error> {
|
||||||
wdb.conn
|
wdb.conn
|
||||||
|
@ -444,7 +444,7 @@ pub fn get_block_hash<P>(
|
||||||
///
|
///
|
||||||
/// This should only be executed inside a transactional context.
|
/// This should only be executed inside a transactional context.
|
||||||
pub fn rewind_to_height<P: consensus::Parameters>(
|
pub fn rewind_to_height<P: consensus::Parameters>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
block_height: BlockHeight,
|
block_height: BlockHeight,
|
||||||
) -> Result<(), SqliteClientError> {
|
) -> Result<(), SqliteClientError> {
|
||||||
let sapling_activation_height = wdb
|
let sapling_activation_height = wdb
|
||||||
|
@ -496,16 +496,16 @@ pub fn rewind_to_height<P: consensus::Parameters>(
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::consensus::{Network, H0};
|
/// use zcash_primitives::consensus::{Network, H0};
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_commitment_tree,
|
/// wallet::get_commitment_tree,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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);
|
/// let tree = get_commitment_tree(&db, H0);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_commitment_tree<P>(
|
pub fn get_commitment_tree<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
block_height: BlockHeight,
|
block_height: BlockHeight,
|
||||||
) -> Result<Option<CommitmentTree<Node>>, SqliteClientError> {
|
) -> Result<Option<CommitmentTree<Node>>, SqliteClientError> {
|
||||||
wdb.conn
|
wdb.conn
|
||||||
|
@ -536,16 +536,16 @@ pub fn get_commitment_tree<P>(
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::consensus::{Network, H0};
|
/// use zcash_primitives::consensus::{Network, H0};
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::get_witnesses,
|
/// wallet::get_witnesses,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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);
|
/// let witnesses = get_witnesses(&db, H0);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_witnesses<P>(
|
pub fn get_witnesses<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
block_height: BlockHeight,
|
block_height: BlockHeight,
|
||||||
) -> Result<Vec<(NoteId, IncrementalWitness<Node>)>, SqliteClientError> {
|
) -> Result<Vec<(NoteId, IncrementalWitness<Node>)>, SqliteClientError> {
|
||||||
let mut stmt_fetch_witnesses = wdb
|
let mut stmt_fetch_witnesses = wdb
|
||||||
|
@ -568,7 +568,7 @@ pub fn get_witnesses<P>(
|
||||||
/// that have not yet been confirmed as a consequence of the spending
|
/// that have not yet been confirmed as a consequence of the spending
|
||||||
/// transaction being included in a block.
|
/// transaction being included in a block.
|
||||||
pub fn get_nullifiers<P>(
|
pub fn get_nullifiers<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
) -> Result<Vec<(AccountId, Nullifier)>, SqliteClientError> {
|
) -> Result<Vec<(AccountId, Nullifier)>, SqliteClientError> {
|
||||||
// Get the nullifiers for the notes we are tracking
|
// Get the nullifiers for the notes we are tracking
|
||||||
let mut stmt_fetch_nullifiers = wdb.conn.prepare(
|
let mut stmt_fetch_nullifiers = wdb.conn.prepare(
|
||||||
|
@ -862,7 +862,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
tests,
|
tests,
|
||||||
wallet::init::{init_accounts_table, init_wallet_db},
|
wallet::init::{init_accounts_table, init_wallet_db},
|
||||||
AccountId, WalletDB,
|
AccountId, WalletDb,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{get_address, get_balance};
|
use super::{get_address, get_balance};
|
||||||
|
@ -870,7 +870,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_database_has_no_balance() {
|
fn empty_database_has_no_balance() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
|
|
@ -10,7 +10,7 @@ use zcash_primitives::{
|
||||||
|
|
||||||
use zcash_client_backend::encoding::encode_extended_full_viewing_key;
|
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.
|
/// 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 tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::consensus::Network;
|
/// use zcash_primitives::consensus::Network;
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::init::init_wallet_db,
|
/// wallet::init::init_wallet_db,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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();
|
/// init_wallet_db(&db).unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn init_wallet_db<P>(wdb: &WalletDB<P>) -> Result<(), rusqlite::Error> {
|
pub fn init_wallet_db<P>(wdb: &WalletDb<P>) -> Result<(), rusqlite::Error> {
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS accounts (
|
"CREATE TABLE IF NOT EXISTS accounts (
|
||||||
account INTEGER PRIMARY KEY,
|
account INTEGER PRIMARY KEY,
|
||||||
|
@ -127,12 +127,12 @@ pub fn init_wallet_db<P>(wdb: &WalletDB<P>) -> Result<(), rusqlite::Error> {
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::init::{init_accounts_table, init_wallet_db}
|
/// wallet::init::{init_accounts_table, init_wallet_db}
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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();
|
/// init_wallet_db(&db_data).unwrap();
|
||||||
///
|
///
|
||||||
/// let extsk = ExtendedSpendingKey::master(&[]);
|
/// let extsk = ExtendedSpendingKey::master(&[]);
|
||||||
|
@ -144,7 +144,7 @@ pub fn init_wallet_db<P>(wdb: &WalletDB<P>) -> Result<(), rusqlite::Error> {
|
||||||
/// [`scan_cached_blocks`]: zcash_client_backend::data_api::chain::scan_cached_blocks
|
/// [`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
|
/// [`create_spend_to_address`]: zcash_client_backend::data_api::wallet::create_spend_to_address
|
||||||
pub fn init_accounts_table<P: consensus::Parameters>(
|
pub fn init_accounts_table<P: consensus::Parameters>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
extfvks: &[ExtendedFullViewingKey],
|
extfvks: &[ExtendedFullViewingKey],
|
||||||
) -> Result<(), SqliteClientError> {
|
) -> Result<(), SqliteClientError> {
|
||||||
let mut empty_check = wdb.conn.prepare("SELECT * FROM accounts LIMIT 1")?;
|
let mut empty_check = wdb.conn.prepare("SELECT * FROM accounts LIMIT 1")?;
|
||||||
|
@ -191,7 +191,7 @@ pub fn init_accounts_table<P: consensus::Parameters>(
|
||||||
/// consensus::{BlockHeight, Network},
|
/// consensus::{BlockHeight, Network},
|
||||||
/// };
|
/// };
|
||||||
/// use zcash_client_sqlite::{
|
/// use zcash_client_sqlite::{
|
||||||
/// WalletDB,
|
/// WalletDb,
|
||||||
/// wallet::init::init_blocks_table,
|
/// wallet::init::init_blocks_table,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
|
@ -206,11 +206,11 @@ pub fn init_accounts_table<P: consensus::Parameters>(
|
||||||
/// let sapling_tree = &[];
|
/// let sapling_tree = &[];
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// 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);
|
/// init_blocks_table(&db, height, hash, time, sapling_tree);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn init_blocks_table<P>(
|
pub fn init_blocks_table<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
height: BlockHeight,
|
height: BlockHeight,
|
||||||
hash: BlockHash,
|
hash: BlockHash,
|
||||||
time: u32,
|
time: u32,
|
||||||
|
@ -245,14 +245,14 @@ mod tests {
|
||||||
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey},
|
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};
|
use super::{init_accounts_table, init_blocks_table, init_wallet_db};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_accounts_table_only_works_once() {
|
fn init_accounts_table_only_works_once() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// We can call the function as many times as we want with no data
|
// We can call the function as many times as we want with no data
|
||||||
|
@ -273,7 +273,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn init_blocks_table_only_works_once() {
|
fn init_blocks_table_only_works_once() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// First call with data should initialise the blocks table
|
// First call with data should initialise the blocks table
|
||||||
|
@ -300,7 +300,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn init_accounts_table_stores_correct_address() {
|
fn init_accounts_table_stores_correct_address() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
|
|
@ -14,7 +14,7 @@ use zcash_primitives::{
|
||||||
|
|
||||||
use zcash_client_backend::wallet::{AccountId, SpendableNote};
|
use zcash_client_backend::wallet::{AccountId, SpendableNote};
|
||||||
|
|
||||||
use crate::{error::SqliteClientError, WalletDB};
|
use crate::{error::SqliteClientError, WalletDb};
|
||||||
|
|
||||||
fn to_spendable_note(row: &Row) -> Result<SpendableNote, SqliteClientError> {
|
fn to_spendable_note(row: &Row) -> Result<SpendableNote, SqliteClientError> {
|
||||||
let diversifier = {
|
let diversifier = {
|
||||||
|
@ -60,7 +60,7 @@ fn to_spendable_note(row: &Row) -> Result<SpendableNote, SqliteClientError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_spendable_notes<P>(
|
pub fn get_spendable_notes<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
anchor_height: BlockHeight,
|
anchor_height: BlockHeight,
|
||||||
) -> Result<Vec<SpendableNote>, SqliteClientError> {
|
) -> Result<Vec<SpendableNote>, SqliteClientError> {
|
||||||
|
@ -88,7 +88,7 @@ pub fn get_spendable_notes<P>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_spendable_notes<P>(
|
pub fn select_spendable_notes<P>(
|
||||||
wdb: &WalletDB<P>,
|
wdb: &WalletDb<P>,
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
target_value: Amount,
|
target_value: Amount,
|
||||||
anchor_height: BlockHeight,
|
anchor_height: BlockHeight,
|
||||||
|
@ -175,7 +175,7 @@ mod tests {
|
||||||
get_balance, get_balance_at,
|
get_balance, get_balance_at,
|
||||||
init::{init_accounts_table, init_blocks_table, init_wallet_db},
|
init::{init_accounts_table, init_blocks_table, init_wallet_db},
|
||||||
},
|
},
|
||||||
AccountId, BlockDB, DataConnStmtCache, WalletDB,
|
AccountId, BlockDb, DataConnStmtCache, WalletDb,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn test_prover() -> impl TxProver {
|
fn test_prover() -> impl TxProver {
|
||||||
|
@ -190,7 +190,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_fails_on_incorrect_extsk() {
|
fn create_to_address_fails_on_incorrect_extsk() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add two accounts to the wallet
|
// Add two accounts to the wallet
|
||||||
|
@ -239,7 +239,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_fails_with_no_blocks() {
|
fn create_to_address_fails_with_no_blocks() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -269,7 +269,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_fails_on_insufficient_balance() {
|
fn create_to_address_fails_on_insufficient_balance() {
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
init_blocks_table(
|
init_blocks_table(
|
||||||
&db_data,
|
&db_data,
|
||||||
|
@ -313,11 +313,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_fails_on_unverified_notes() {
|
fn create_to_address_fails_on_unverified_notes() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -440,11 +440,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_fails_on_locked_notes() {
|
fn create_to_address_fails_on_locked_notes() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -561,11 +561,11 @@ mod tests {
|
||||||
fn ovk_policy_prevents_recovery_from_chain() {
|
fn ovk_policy_prevents_recovery_from_chain() {
|
||||||
let network = tests::network();
|
let network = tests::network();
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
@ -670,11 +670,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_to_address_succeeds_to_t_addr_zero_change() {
|
fn create_to_address_succeeds_to_t_addr_zero_change() {
|
||||||
let cache_file = NamedTempFile::new().unwrap();
|
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();
|
init_cache_database(&db_cache).unwrap();
|
||||||
|
|
||||||
let data_file = NamedTempFile::new().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();
|
init_wallet_db(&db_data).unwrap();
|
||||||
|
|
||||||
// Add an account to the wallet
|
// Add an account to the wallet
|
||||||
|
|
|
@ -17,6 +17,10 @@ and this library adheres to Rust's notion of
|
||||||
- `zcash_primitives::prover`
|
- `zcash_primitives::prover`
|
||||||
- `zcash_primitives::redjubjub`
|
- `zcash_primitives::redjubjub`
|
||||||
- `zcash_primitives::util::{hash_to_scalar, generate_random_rseed}`
|
- `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
|
## [0.5.0] - 2021-03-26
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub mod tze;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
amount::Amount,
|
amount::Amount,
|
||||||
sapling::{OutputDescription, SpendDescription},
|
sapling::{OutputDescription, SpendDescription},
|
||||||
sprout::JSDescription,
|
sprout::JsDescription,
|
||||||
transparent::{OutPoint, TxIn, TxOut},
|
transparent::{OutPoint, TxIn, TxOut},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,20 +13,20 @@ const ZC_NUM_JS_OUTPUTS: usize = 2;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) enum SproutProof {
|
pub(crate) enum SproutProof {
|
||||||
Groth([u8; GROTH_PROOF_SIZE]),
|
Groth([u8; GROTH_PROOF_SIZE]),
|
||||||
PHGR([u8; PHGR_PROOF_SIZE]),
|
Phgr([u8; PHGR_PROOF_SIZE]),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for SproutProof {
|
impl std::fmt::Debug for SproutProof {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
match self {
|
match self {
|
||||||
SproutProof::Groth(_) => write!(f, "SproutProof::Groth"),
|
SproutProof::Groth(_) => write!(f, "SproutProof::Groth"),
|
||||||
SproutProof::PHGR(_) => write!(f, "SproutProof::PHGR"),
|
SproutProof::Phgr(_) => write!(f, "SproutProof::PHGR"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct JSDescription {
|
pub struct JsDescription {
|
||||||
pub(crate) vpub_old: Amount,
|
pub(crate) vpub_old: Amount,
|
||||||
pub(crate) vpub_new: Amount,
|
pub(crate) vpub_new: Amount,
|
||||||
pub(crate) anchor: [u8; 32],
|
pub(crate) anchor: [u8; 32],
|
||||||
|
@ -39,7 +39,7 @@ pub struct JSDescription {
|
||||||
pub(crate) ciphertexts: [[u8; 601]; ZC_NUM_JS_OUTPUTS],
|
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> {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -63,7 +63,7 @@ impl std::fmt::Debug for JSDescription {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JSDescription {
|
impl JsDescription {
|
||||||
pub fn read<R: Read>(mut reader: R, use_groth: bool) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R, use_groth: bool) -> io::Result<Self> {
|
||||||
// Consensus rule (§4.3): Canonical encoding is enforced here
|
// Consensus rule (§4.3): Canonical encoding is enforced here
|
||||||
let vpub_old = {
|
let vpub_old = {
|
||||||
|
@ -125,7 +125,7 @@ impl JSDescription {
|
||||||
// - Proof validity is enforced by JSDescription::Verify() in zcashd
|
// - Proof validity is enforced by JSDescription::Verify() in zcashd
|
||||||
let mut proof = [0u8; PHGR_PROOF_SIZE];
|
let mut proof = [0u8; PHGR_PROOF_SIZE];
|
||||||
reader.read_exact(&mut proof)?;
|
reader.read_exact(&mut proof)?;
|
||||||
SproutProof::PHGR(proof)
|
SproutProof::Phgr(proof)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ciphertexts = [[0u8; 601]; ZC_NUM_JS_OUTPUTS];
|
let mut ciphertexts = [[0u8; 601]; ZC_NUM_JS_OUTPUTS];
|
||||||
|
@ -134,7 +134,7 @@ impl JSDescription {
|
||||||
.map(|ct| reader.read_exact(ct))
|
.map(|ct| reader.read_exact(ct))
|
||||||
.collect::<io::Result<()>>()?;
|
.collect::<io::Result<()>>()?;
|
||||||
|
|
||||||
Ok(JSDescription {
|
Ok(JsDescription {
|
||||||
vpub_old,
|
vpub_old,
|
||||||
vpub_new,
|
vpub_new,
|
||||||
anchor,
|
anchor,
|
||||||
|
@ -163,7 +163,7 @@ impl JSDescription {
|
||||||
|
|
||||||
match &self.proof {
|
match &self.proof {
|
||||||
SproutProof::Groth(p) => writer.write_all(p)?,
|
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])?;
|
writer.write_all(&self.ciphertexts[0])?;
|
||||||
|
|
|
@ -19,7 +19,7 @@ mod tests;
|
||||||
|
|
||||||
pub use self::sighash::{signature_hash, signature_hash_data, SignableInput, SIGHASH_ALL};
|
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")]
|
#[cfg(feature = "zfuture")]
|
||||||
use self::components::{TzeIn, TzeOut};
|
use self::components::{TzeIn, TzeOut};
|
||||||
|
@ -183,7 +183,7 @@ pub struct TransactionData {
|
||||||
pub value_balance: Amount,
|
pub value_balance: Amount,
|
||||||
pub shielded_spends: Vec<SpendDescription>,
|
pub shielded_spends: Vec<SpendDescription>,
|
||||||
pub shielded_outputs: Vec<OutputDescription>,
|
pub shielded_outputs: Vec<OutputDescription>,
|
||||||
pub joinsplits: Vec<JSDescription>,
|
pub joinsplits: Vec<JsDescription>,
|
||||||
pub joinsplit_pubkey: Option<[u8; 32]>,
|
pub joinsplit_pubkey: Option<[u8; 32]>,
|
||||||
pub joinsplit_sig: Option<[u8; 64]>,
|
pub joinsplit_sig: Option<[u8; 64]>,
|
||||||
pub binding_sig: Option<Signature>,
|
pub binding_sig: Option<Signature>,
|
||||||
|
@ -349,7 +349,7 @@ impl Transaction {
|
||||||
|
|
||||||
let (joinsplits, joinsplit_pubkey, joinsplit_sig) = if version.has_sprout() {
|
let (joinsplits, joinsplit_pubkey, joinsplit_sig) = if version.has_sprout() {
|
||||||
let jss = Vector::read(&mut reader, |r| {
|
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 (pubkey, sig) = if !jss.is_empty() {
|
||||||
let mut joinsplit_pubkey = [0; 32];
|
let mut joinsplit_pubkey = [0; 32];
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
components::{Amount, JSDescription, OutputDescription, SpendDescription, TxIn, TxOut},
|
components::{Amount, JsDescription, OutputDescription, SpendDescription, TxIn, TxOut},
|
||||||
Transaction, TransactionData, TxVersion,
|
Transaction, TransactionData, TxVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ fn single_output_hash(tx_out: &TxOut) -> Blake2bHash {
|
||||||
|
|
||||||
fn joinsplits_hash(
|
fn joinsplits_hash(
|
||||||
txversion: TxVersion,
|
txversion: TxVersion,
|
||||||
joinsplits: &[JSDescription],
|
joinsplits: &[JsDescription],
|
||||||
joinsplit_pubkey: &[u8; 32],
|
joinsplit_pubkey: &[u8; 32],
|
||||||
) -> Blake2bHash {
|
) -> Blake2bHash {
|
||||||
let mut data = Vec::with_capacity(
|
let mut data = Vec::with_capacity(
|
||||||
|
|
|
@ -32,9 +32,9 @@ fn derive_child_ovk(parent: &OutgoingViewingKey, i_l: &[u8]) -> OutgoingViewingK
|
||||||
// ZIP 32 structures
|
// ZIP 32 structures
|
||||||
|
|
||||||
/// A Sapling full viewing key fingerprint
|
/// 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 {
|
fn from(fvk: &FullViewingKey) -> Self {
|
||||||
let mut h = Blake2bParams::new()
|
let mut h = Blake2bParams::new()
|
||||||
.hash_length(32)
|
.hash_length(32)
|
||||||
|
@ -43,25 +43,25 @@ impl From<&FullViewingKey> for FVKFingerprint {
|
||||||
h.update(&fvk.to_bytes());
|
h.update(&fvk.to_bytes());
|
||||||
let mut fvfp = [0u8; 32];
|
let mut fvfp = [0u8; 32];
|
||||||
fvfp.copy_from_slice(h.finalize().as_bytes());
|
fvfp.copy_from_slice(h.finalize().as_bytes());
|
||||||
FVKFingerprint(fvfp)
|
FvkFingerprint(fvfp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Sapling full viewing key tag
|
/// A Sapling full viewing key tag
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
struct FVKTag([u8; 4]);
|
struct FvkTag([u8; 4]);
|
||||||
|
|
||||||
impl FVKFingerprint {
|
impl FvkFingerprint {
|
||||||
fn tag(&self) -> FVKTag {
|
fn tag(&self) -> FvkTag {
|
||||||
let mut tag = [0u8; 4];
|
let mut tag = [0u8; 4];
|
||||||
tag.copy_from_slice(&self.0[..4]);
|
tag.copy_from_slice(&self.0[..4]);
|
||||||
FVKTag(tag)
|
FvkTag(tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FVKTag {
|
impl FvkTag {
|
||||||
fn master() -> Self {
|
fn master() -> Self {
|
||||||
FVKTag([0u8; 4])
|
FvkTag([0u8; 4])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ impl DiversifierKey {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ExtendedSpendingKey {
|
pub struct ExtendedSpendingKey {
|
||||||
depth: u8,
|
depth: u8,
|
||||||
parent_fvk_tag: FVKTag,
|
parent_fvk_tag: FvkTag,
|
||||||
child_index: ChildIndex,
|
child_index: ChildIndex,
|
||||||
chain_code: ChainCode,
|
chain_code: ChainCode,
|
||||||
pub expsk: ExpandedSpendingKey,
|
pub expsk: ExpandedSpendingKey,
|
||||||
|
@ -185,7 +185,7 @@ pub struct ExtendedSpendingKey {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ExtendedFullViewingKey {
|
pub struct ExtendedFullViewingKey {
|
||||||
depth: u8,
|
depth: u8,
|
||||||
parent_fvk_tag: FVKTag,
|
parent_fvk_tag: FvkTag,
|
||||||
child_index: ChildIndex,
|
child_index: ChildIndex,
|
||||||
chain_code: ChainCode,
|
chain_code: ChainCode,
|
||||||
pub fvk: FullViewingKey,
|
pub fvk: FullViewingKey,
|
||||||
|
@ -251,7 +251,7 @@ impl ExtendedSpendingKey {
|
||||||
|
|
||||||
ExtendedSpendingKey {
|
ExtendedSpendingKey {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
parent_fvk_tag: FVKTag::master(),
|
parent_fvk_tag: FvkTag::master(),
|
||||||
child_index: ChildIndex::master(),
|
child_index: ChildIndex::master(),
|
||||||
chain_code: ChainCode(c_m),
|
chain_code: ChainCode(c_m),
|
||||||
expsk: ExpandedSpendingKey::from_spending_key(sk_m),
|
expsk: ExpandedSpendingKey::from_spending_key(sk_m),
|
||||||
|
@ -272,7 +272,7 @@ impl ExtendedSpendingKey {
|
||||||
|
|
||||||
Ok(ExtendedSpendingKey {
|
Ok(ExtendedSpendingKey {
|
||||||
depth,
|
depth,
|
||||||
parent_fvk_tag: FVKTag(tag),
|
parent_fvk_tag: FvkTag(tag),
|
||||||
child_index: ChildIndex::from_index(i),
|
child_index: ChildIndex::from_index(i),
|
||||||
chain_code: ChainCode(c),
|
chain_code: ChainCode(c),
|
||||||
expsk,
|
expsk,
|
||||||
|
@ -326,7 +326,7 @@ impl ExtendedSpendingKey {
|
||||||
|
|
||||||
ExtendedSpendingKey {
|
ExtendedSpendingKey {
|
||||||
depth: self.depth + 1,
|
depth: self.depth + 1,
|
||||||
parent_fvk_tag: FVKFingerprint::from(&fvk).tag(),
|
parent_fvk_tag: FvkFingerprint::from(&fvk).tag(),
|
||||||
child_index: i,
|
child_index: i,
|
||||||
chain_code: ChainCode(c_i),
|
chain_code: ChainCode(c_i),
|
||||||
expsk: {
|
expsk: {
|
||||||
|
@ -373,7 +373,7 @@ impl ExtendedFullViewingKey {
|
||||||
|
|
||||||
Ok(ExtendedFullViewingKey {
|
Ok(ExtendedFullViewingKey {
|
||||||
depth,
|
depth,
|
||||||
parent_fvk_tag: FVKTag(tag),
|
parent_fvk_tag: FvkTag(tag),
|
||||||
child_index: ChildIndex::from_index(i),
|
child_index: ChildIndex::from_index(i),
|
||||||
chain_code: ChainCode(c),
|
chain_code: ChainCode(c),
|
||||||
fvk,
|
fvk,
|
||||||
|
@ -410,7 +410,7 @@ impl ExtendedFullViewingKey {
|
||||||
|
|
||||||
Ok(ExtendedFullViewingKey {
|
Ok(ExtendedFullViewingKey {
|
||||||
depth: self.depth + 1,
|
depth: self.depth + 1,
|
||||||
parent_fvk_tag: FVKFingerprint::from(&self.fvk).tag(),
|
parent_fvk_tag: FvkFingerprint::from(&self.fvk).tag(),
|
||||||
child_index: i,
|
child_index: i,
|
||||||
chain_code: ChainCode(c_i),
|
chain_code: ChainCode(c_i),
|
||||||
fvk: {
|
fvk: {
|
||||||
|
@ -1035,7 +1035,7 @@ mod tests {
|
||||||
let mut ser = vec![];
|
let mut ser = vec![];
|
||||||
xfvk.write(&mut ser).unwrap();
|
xfvk.write(&mut ser).unwrap();
|
||||||
assert_eq!(&ser[..], &tv.xfvk[..]);
|
assert_eq!(&ser[..], &tv.xfvk[..]);
|
||||||
assert_eq!(FVKFingerprint::from(&xfvk.fvk).0, tv.fp);
|
assert_eq!(FvkFingerprint::from(&xfvk.fvk).0, tv.fp);
|
||||||
|
|
||||||
// d0
|
// d0
|
||||||
let mut di = DiversifierIndex::new();
|
let mut di = DiversifierIndex::new();
|
||||||
|
|
|
@ -8,6 +8,10 @@ and this library adheres to Rust's notion of
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Changed
|
### Changed
|
||||||
- MSRV is now 1.51.0.
|
- 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
|
## [0.5.0] - 2021-03-26
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -35,12 +35,12 @@ pub struct JoinSplit {
|
||||||
pub vpub_new: Option<u64>,
|
pub vpub_new: Option<u64>,
|
||||||
pub h_sig: Option<[u8; 32]>,
|
pub h_sig: Option<[u8; 32]>,
|
||||||
pub phi: Option<[u8; 32]>,
|
pub phi: Option<[u8; 32]>,
|
||||||
pub inputs: Vec<JSInput>,
|
pub inputs: Vec<JsInput>,
|
||||||
pub outputs: Vec<JSOutput>,
|
pub outputs: Vec<JsOutput>,
|
||||||
pub rt: Option<[u8; 32]>,
|
pub rt: Option<[u8; 32]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct JSInput {
|
pub struct JsInput {
|
||||||
pub value: Option<u64>,
|
pub value: Option<u64>,
|
||||||
pub a_sk: Option<SpendingKey>,
|
pub a_sk: Option<SpendingKey>,
|
||||||
pub rho: Option<UniqueRandomness>,
|
pub rho: Option<UniqueRandomness>,
|
||||||
|
@ -48,7 +48,7 @@ pub struct JSInput {
|
||||||
pub auth_path: [Option<([u8; 32], bool)>; TREE_DEPTH],
|
pub auth_path: [Option<([u8; 32], bool)>; TREE_DEPTH],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct JSOutput {
|
pub struct JsOutput {
|
||||||
pub value: Option<u64>,
|
pub value: Option<u64>,
|
||||||
pub a_pk: Option<PayingKey>,
|
pub a_pk: Option<PayingKey>,
|
||||||
pub r: Option<CommitmentRandomness>,
|
pub r: Option<CommitmentRandomness>,
|
||||||
|
@ -389,7 +389,7 @@ fn test_sprout_constraints() {
|
||||||
let r = Some(CommitmentRandomness(get_u256(&mut test_vector)));
|
let r = Some(CommitmentRandomness(get_u256(&mut test_vector)));
|
||||||
let a_sk = Some(SpendingKey(get_u256(&mut test_vector)));
|
let a_sk = Some(SpendingKey(get_u256(&mut test_vector)));
|
||||||
|
|
||||||
inputs.push(JSInput {
|
inputs.push(JsInput {
|
||||||
value,
|
value,
|
||||||
a_sk,
|
a_sk,
|
||||||
rho,
|
rho,
|
||||||
|
@ -406,7 +406,7 @@ fn test_sprout_constraints() {
|
||||||
get_u256(&mut test_vector);
|
get_u256(&mut test_vector);
|
||||||
let r = Some(CommitmentRandomness(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::<LittleEndian>().unwrap());
|
let vpub_old = Some(test_vector.read_u64::<LittleEndian>().unwrap());
|
||||||
|
|
|
@ -90,7 +90,7 @@ pub fn create_proof(
|
||||||
position >>= 1;
|
position >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs.push(JSInput {
|
inputs.push(JsInput {
|
||||||
value,
|
value,
|
||||||
a_sk,
|
a_sk,
|
||||||
rho,
|
rho,
|
||||||
|
@ -106,7 +106,7 @@ pub fn create_proof(
|
||||||
let mut outputs = Vec::with_capacity(2);
|
let mut outputs = Vec::with_capacity(2);
|
||||||
{
|
{
|
||||||
let mut handle_output = |a_pk, value, r| {
|
let mut handle_output = |a_pk, value, r| {
|
||||||
outputs.push(JSOutput {
|
outputs.push(JsOutput {
|
||||||
value: Some(value),
|
value: Some(value),
|
||||||
a_pk: Some(PayingKey(a_pk)),
|
a_pk: Some(PayingKey(a_pk)),
|
||||||
r: Some(CommitmentRandomness(r)),
|
r: Some(CommitmentRandomness(r)),
|
||||||
|
|
Loading…
Reference in New Issue