Merge pull request #1272 from nuttycom/account_source

zcash_client_backend: Rename `AccountKind` to `AccountSource`
This commit is contained in:
str4d 2024-03-18 17:59:17 +00:00 committed by GitHub
commit da64e8aa5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 35 deletions

View File

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

View File

@ -317,7 +317,7 @@ impl AccountBalance {
/// 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,
@ -335,7 +335,7 @@ pub trait Account<AccountId: Copy> {
/// 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.
///
@ -349,8 +349,8 @@ impl<A: Copy> Account<A> for (A, UnifiedFullViewingKey) {
self.0
}
fn kind(&self) -> AccountKind {
AccountKind::Imported
fn source(&self) -> AccountSource {
AccountSource::Imported
}
fn ufvk(&self) -> Option<&UnifiedFullViewingKey> {
@ -363,8 +363,8 @@ impl<A: Copy> Account<A> for (A, Option<UnifiedFullViewingKey>) {
self.0
}
fn kind(&self) -> AccountKind {
AccountKind::Imported
fn source(&self) -> AccountSource {
AccountSource::Imported
}
fn ufvk(&self) -> Option<&UnifiedFullViewingKey> {

View File

@ -60,7 +60,7 @@ use zcash_client_backend::{
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,
},
@ -316,10 +316,10 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> WalletRead for W
seed: &SecretVec<u8>,
) -> Result<bool, Self::Error> {
if let Some(account) = self.get_account(account_id)? {
if let AccountKind::Derived {
if let AccountSource::Derived {
seed_fingerprint,
account_index,
} = account.kind()
} = account.source()
{
let seed_fingerprint_match =
SeedFingerprint::from_seed(seed.expose_secret()).ok_or_else(|| {
@ -527,7 +527,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
let account_id = wallet::add_account(
wdb.conn.0,
&wdb.params,
AccountKind::Derived {
AccountSource::Derived {
seed_fingerprint,
account_index,
},

View File

@ -81,8 +81,8 @@ use zcash_client_backend::{
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,
@ -139,13 +139,13 @@ pub(crate) mod scanning;
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(
@ -153,7 +153,7 @@ fn parse_account_kind(
)
})?,
}),
(1, None, None) => Ok(AccountKind::Imported),
(1, None, None) => Ok(AccountSource::Imported),
(0, None, None) | (1, Some(_), Some(_)) => Err(SqliteClientError::CorruptedData(
"Wallet DB account_kind constraint violated".to_string(),
)),
@ -163,10 +163,10 @@ fn parse_account_kind(
}
}
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,
}
}
@ -190,7 +190,7 @@ pub(crate) enum ViewingKey {
#[derive(Debug, Clone)]
pub struct Account {
account_id: AccountId,
kind: AccountKind,
kind: AccountSource,
viewing_key: ViewingKey,
}
@ -216,7 +216,7 @@ impl zcash_client_backend::data_api::Account<AccountId> for Account {
self.account_id
}
fn kind(&self) -> AccountKind {
fn source(&self) -> AccountSource {
self.kind
}
@ -299,16 +299,16 @@ pub(crate) fn max_zip32_account_index(
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 {
seed_fingerprint,
account_index,
} => (Some(seed_fingerprint), Some(account_index)),
AccountKind::Imported => (None, None),
AccountSource::Imported => (None, None),
};
let orchard_item = viewing_key
@ -709,7 +709,7 @@ pub(crate) fn get_account_for_ufvk<P: consensus::Parameters>(
],
|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.
@ -777,7 +777,7 @@ pub(crate) fn get_derived_account<P: consensus::Parameters>(
}?;
Ok(Account {
account_id,
kind: AccountKind::Derived {
kind: AccountSource::Derived {
seed_fingerprint: *seed,
account_index,
},
@ -1486,7 +1486,7 @@ pub(crate) fn get_account<P: Parameters>(
let row = result.next()?;
match row {
Some(row) => {
let kind = parse_account_kind(
let kind = parse_account_source(
row.get("account_kind")?,
row.get("hd_seed_fingerprint")?,
row.get("hd_account_index")?,
@ -2670,7 +2670,7 @@ mod tests {
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::{
@ -2827,7 +2827,7 @@ mod tests {
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
);
}

View File

@ -1288,7 +1288,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();
@ -1307,7 +1307,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,
)
);

View File

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