Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_backend: Rename AccountKind to AccountSource #1272

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this library adheres to Rust's notion of
- `Account`
- `AccountBalance::with_orchard_balance_mut`
- `AccountBirthday::orchard_frontier`
- `AccountKind`
- `AccountSource`
- `BlockMetadata::orchard_tree_size`
- `DecryptedTransaction::{new, tx(), orchard_outputs()}`
- `NoteRetention`
Expand Down
12 changes: 6 additions & 6 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@

/// The kinds of accounts supported by `zcash_client_backend`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum AccountKind {
pub enum AccountSource {
/// An account derived from a known seed.
Derived {
seed_fingerprint: SeedFingerprint,
Expand All @@ -335,7 +335,7 @@

/// Returns whether this account is derived or imported, and the derivation parameters
/// if applicable.
fn kind(&self) -> AccountKind;
fn source(&self) -> AccountSource;

/// Returns the UFVK that the wallet backend has stored for the account, if any.
///
Expand All @@ -349,8 +349,8 @@
self.0
}

fn kind(&self) -> AccountKind {
AccountKind::Imported
fn source(&self) -> AccountSource {
AccountSource::Imported

Check warning on line 353 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L352-L353

Added lines #L352 - L353 were not covered by tests
}

fn ufvk(&self) -> Option<&UnifiedFullViewingKey> {
Expand All @@ -363,8 +363,8 @@
self.0
}

fn kind(&self) -> AccountKind {
AccountKind::Imported
fn source(&self) -> AccountSource {
AccountSource::Imported

Check warning on line 367 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L366-L367

Added lines #L366 - L367 were not covered by tests
}

fn ufvk(&self) -> Option<&UnifiedFullViewingKey> {
Expand Down
8 changes: 4 additions & 4 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
self,
chain::{BlockSource, ChainState, CommitmentTreeRoot},
scanning::{ScanPriority, ScanRange},
Account, AccountBirthday, AccountKind, BlockMetadata, DecryptedTransaction, InputSource,
Account, AccountBirthday, AccountSource, BlockMetadata, DecryptedTransaction, InputSource,
NullifierQuery, ScannedBlock, SentTransaction, SpendableNotes, WalletCommitmentTrees,
WalletRead, WalletSummary, WalletWrite, SAPLING_SHARD_HEIGHT,
},
Expand Down Expand Up @@ -316,10 +316,10 @@
seed: &SecretVec<u8>,
) -> Result<bool, Self::Error> {
if let Some(account) = self.get_account(account_id)? {
if let AccountKind::Derived {
if let AccountSource::Derived {

Check warning on line 319 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L319

Added line #L319 was not covered by tests
seed_fingerprint,
account_index,
} = account.kind()
} = account.source()
{
let seed_fingerprint_match =
SeedFingerprint::from_seed(seed.expose_secret()).ok_or_else(|| {
Expand Down Expand Up @@ -527,7 +527,7 @@
let account_id = wallet::add_account(
wdb.conn.0,
&wdb.params,
AccountKind::Derived {
AccountSource::Derived {
seed_fingerprint,
account_index,
},
Expand Down
38 changes: 19 additions & 19 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
address::{Address, UnifiedAddress},
data_api::{
scanning::{ScanPriority, ScanRange},
AccountBalance, AccountBirthday, AccountKind, BlockMetadata, Ratio, SentTransactionOutput,
WalletSummary, SAPLING_SHARD_HEIGHT,
AccountBalance, AccountBirthday, AccountSource, BlockMetadata, Ratio,
SentTransactionOutput, WalletSummary, SAPLING_SHARD_HEIGHT,
},
encoding::AddressCodec,
keys::UnifiedFullViewingKey,
Expand Down Expand Up @@ -139,21 +139,21 @@

pub(crate) const BLOCK_SAPLING_FRONTIER_ABSENT: &[u8] = &[0x0];

fn parse_account_kind(
fn parse_account_source(
account_kind: u32,
hd_seed_fingerprint: Option<[u8; 32]>,
hd_account_index: Option<u32>,
) -> Result<AccountKind, SqliteClientError> {
) -> Result<AccountSource, SqliteClientError> {
match (account_kind, hd_seed_fingerprint, hd_account_index) {
(0, Some(seed_fp), Some(account_index)) => Ok(AccountKind::Derived {
(0, Some(seed_fp), Some(account_index)) => Ok(AccountSource::Derived {
seed_fingerprint: SeedFingerprint::from_bytes(seed_fp),
account_index: zip32::AccountId::try_from(account_index).map_err(|_| {
SqliteClientError::CorruptedData(
"ZIP-32 account ID from wallet DB is out of range.".to_string(),
)
})?,
}),
(1, None, None) => Ok(AccountKind::Imported),
(1, None, None) => Ok(AccountSource::Imported),

Check warning on line 156 in zcash_client_sqlite/src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet.rs#L156

Added line #L156 was not covered by tests
(0, None, None) | (1, Some(_), Some(_)) => Err(SqliteClientError::CorruptedData(
"Wallet DB account_kind constraint violated".to_string(),
)),
Expand All @@ -163,10 +163,10 @@
}
}

fn account_kind_code(value: AccountKind) -> u32 {
fn account_kind_code(value: AccountSource) -> u32 {
match value {
AccountKind::Derived { .. } => 0,
AccountKind::Imported => 1,
AccountSource::Derived { .. } => 0,
AccountSource::Imported => 1,
}
}

Expand All @@ -190,7 +190,7 @@
#[derive(Debug, Clone)]
pub struct Account {
account_id: AccountId,
kind: AccountKind,
kind: AccountSource,
viewing_key: ViewingKey,
}

Expand All @@ -216,7 +216,7 @@
self.account_id
}

fn kind(&self) -> AccountKind {
fn source(&self) -> AccountSource {
self.kind
}

Expand Down Expand Up @@ -324,16 +324,16 @@
pub(crate) fn add_account<P: consensus::Parameters>(
conn: &rusqlite::Transaction,
params: &P,
kind: AccountKind,
kind: AccountSource,
viewing_key: ViewingKey,
birthday: AccountBirthday,
) -> Result<AccountId, SqliteClientError> {
let (hd_seed_fingerprint, hd_account_index) = match kind {
AccountKind::Derived {
AccountSource::Derived {

Check warning on line 332 in zcash_client_sqlite/src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet.rs#L332

Added line #L332 was not covered by tests
seed_fingerprint,
account_index,
} => (Some(seed_fingerprint), Some(account_index)),
AccountKind::Imported => (None, None),
AccountSource::Imported => (None, None),

Check warning on line 336 in zcash_client_sqlite/src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet.rs#L336

Added line #L336 was not covered by tests
};

let orchard_item = viewing_key
Expand Down Expand Up @@ -734,7 +734,7 @@
],
|row| {
let account_id = row.get::<_, u32>(0).map(AccountId)?;
let kind = parse_account_kind(row.get(1)?, row.get(2)?, row.get(3)?)?;
let kind = parse_account_source(row.get(1)?, row.get(2)?, row.get(3)?)?;

// We looked up the account by FVK components, so the UFVK column must be
// non-null.
Expand Down Expand Up @@ -802,7 +802,7 @@
}?;
Ok(Account {
account_id,
kind: AccountKind::Derived {
kind: AccountSource::Derived {

Check warning on line 805 in zcash_client_sqlite/src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet.rs#L805

Added line #L805 was not covered by tests
seed_fingerprint: *seed,
account_index,
},
Expand Down Expand Up @@ -1511,7 +1511,7 @@
let row = result.next()?;
match row {
Some(row) => {
let kind = parse_account_kind(
let kind = parse_account_source(
row.get("account_kind")?,
str4d marked this conversation as resolved.
Show resolved Hide resolved
row.get("hd_seed_fingerprint")?,
row.get("hd_account_index")?,
Expand Down Expand Up @@ -2700,7 +2700,7 @@
use std::num::NonZeroU32;

use sapling::zip32::ExtendedSpendingKey;
use zcash_client_backend::data_api::{AccountBirthday, AccountKind, WalletRead};
use zcash_client_backend::data_api::{AccountBirthday, AccountSource, WalletRead};
use zcash_primitives::{block::BlockHash, transaction::components::amount::NonNegativeAmount};

use crate::{
Expand Down Expand Up @@ -2857,7 +2857,7 @@
let expected_account_index = zip32::AccountId::try_from(0).unwrap();
assert_matches!(
account_parameters.kind,
AccountKind::Derived{account_index, ..} if account_index == expected_account_index
AccountSource::Derived{account_index, ..} if account_index == expected_account_index
);
}

Expand Down
4 changes: 2 additions & 2 deletions zcash_client_sqlite/src/wallet/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ mod tests {
#[test]
#[cfg(feature = "transparent-inputs")]
fn account_produces_expected_ua_sequence() {
use zcash_client_backend::data_api::{AccountBirthday, AccountKind, WalletRead};
use zcash_client_backend::data_api::{AccountBirthday, AccountSource, WalletRead};

let network = Network::MainNetwork;
let data_file = NamedTempFile::new().unwrap();
Expand All @@ -1301,7 +1301,7 @@ mod tests {
db_data.get_account(account_id),
Ok(Some(account)) if matches!(
account.kind,
AccountKind::Derived{account_index, ..} if account_index == zip32::AccountId::ZERO,
AccountSource::Derived{account_index, ..} if account_index == zip32::AccountId::ZERO,
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rusqlite::{named_params, Transaction};
use schemer_rusqlite::RusqliteMigration;
use secrecy::{ExposeSecret, SecretVec};
use uuid::Uuid;
use zcash_client_backend::{data_api::AccountKind, keys::UnifiedSpendingKey};
use zcash_client_backend::{data_api::AccountSource, keys::UnifiedSpendingKey};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::consensus;
use zip32::fingerprint::SeedFingerprint;
Expand Down Expand Up @@ -45,11 +45,11 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
type Error = WalletMigrationError;

fn up(&self, transaction: &Transaction) -> Result<(), WalletMigrationError> {
let account_kind_derived = account_kind_code(AccountKind::Derived {
let account_kind_derived = account_kind_code(AccountSource::Derived {
seed_fingerprint: SeedFingerprint::from_bytes([0; 32]),
account_index: zip32::AccountId::ZERO,
});
let account_kind_imported = account_kind_code(AccountKind::Imported);
let account_kind_imported = account_kind_code(AccountSource::Imported);
transaction.execute_batch(
&format!(r#"
PRAGMA foreign_keys = OFF;
Expand Down
Loading