Skip to content

Commit

Permalink
zcash_client_sqlite: Rename account_type column to account_kind
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Mar 13, 2024
1 parent bbb7f36 commit b161472
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ pub(crate) mod scanning;
pub(crate) const BLOCK_SAPLING_FRONTIER_ABSENT: &[u8] = &[0x0];

fn parse_account_kind(
account_type: u32,
account_kind: u32,
hd_seed_fingerprint: Option<[u8; 32]>,
hd_account_index: Option<u32>,
) -> Result<AccountKind, SqliteClientError> {
match (account_type, hd_seed_fingerprint, hd_account_index) {
match (account_kind, hd_seed_fingerprint, hd_account_index) {
(0, Some(seed_fp), Some(account_index)) => Ok(AccountKind::Derived {
seed_fingerprint: HdSeedFingerprint::from_bytes(seed_fp),
account_index: zip32::AccountId::try_from(account_index).map_err(|_| {
Expand All @@ -154,10 +154,10 @@ fn parse_account_kind(
}),
(1, None, None) => Ok(AccountKind::Imported),
(0, None, None) | (1, Some(_), Some(_)) => Err(SqliteClientError::CorruptedData(
"Wallet DB account_type constraint violated".to_string(),
"Wallet DB account_kind constraint violated".to_string(),
)),
(_, _, _) => Err(SqliteClientError::CorruptedData(
"Unrecognized account_type".to_string(),
"Unrecognized account_kind".to_string(),
)),
}
}
Expand Down Expand Up @@ -351,21 +351,21 @@ pub(crate) fn add_account<P: consensus::Parameters>(
let account_id: AccountId = conn.query_row(
r#"
INSERT INTO accounts (
account_type, hd_seed_fingerprint, hd_account_index,
account_kind, hd_seed_fingerprint, hd_account_index,
ufvk, uivk,
orchard_fvk_item_cache, sapling_fvk_item_cache, p2pkh_fvk_item_cache,
birthday_height, recover_until_height
)
VALUES (
:account_type, :hd_seed_fingerprint, :hd_account_index,
:account_kind, :hd_seed_fingerprint, :hd_account_index,
:ufvk, :uivk,
:orchard_fvk_item_cache, :sapling_fvk_item_cache, :p2pkh_fvk_item_cache,
:birthday_height, :recover_until_height
)
RETURNING id;
"#,
named_params![
":account_type": account_kind_code(kind),
":account_kind": account_kind_code(kind),
":hd_seed_fingerprint": hd_seed_fingerprint.as_ref().map(|fp| fp.as_bytes()),
":hd_account_index": hd_account_index.map(u32::from),
":ufvk": viewing_key.ufvk().map(|ufvk| ufvk.encode(params)),
Expand Down Expand Up @@ -717,7 +717,7 @@ pub(crate) fn get_account_for_ufvk<P: consensus::Parameters>(
let transparent_item: Option<Vec<u8>> = None;

let mut stmt = conn.prepare(
"SELECT id, account_type, hd_seed_fingerprint, hd_account_index, ufvk
"SELECT id, account_kind, hd_seed_fingerprint, hd_account_index, ufvk
FROM accounts
WHERE orchard_fvk_item_cache = :orchard_fvk_item_cache
OR sapling_fvk_item_cache = :sapling_fvk_item_cache
Expand Down Expand Up @@ -1501,7 +1501,7 @@ pub(crate) fn get_account<P: Parameters>(
) -> Result<Option<Account>, SqliteClientError> {
let mut sql = conn.prepare_cached(
r#"
SELECT account_type, hd_seed_fingerprint, hd_account_index, ufvk, uivk
SELECT account_kind, hd_seed_fingerprint, hd_account_index, ufvk, uivk
FROM accounts
WHERE id = :account_id
"#,
Expand All @@ -1512,7 +1512,7 @@ pub(crate) fn get_account<P: Parameters>(
match row {
Some(row) => {
let kind = parse_account_kind(
row.get("account_type")?,
row.get("account_kind")?,
row.get("hd_seed_fingerprint")?,
row.get("hd_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 @@ -224,7 +224,7 @@ mod tests {
let expected_tables = vec![
r#"CREATE TABLE "accounts" (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
account_type INTEGER NOT NULL DEFAULT 0,
account_kind INTEGER NOT NULL DEFAULT 0,
hd_seed_fingerprint BLOB,
hd_account_index INTEGER,
ufvk TEXT,
Expand All @@ -234,7 +234,7 @@ mod tests {
p2pkh_fvk_item_cache BLOB,
birthday_height INTEGER NOT NULL,
recover_until_height INTEGER,
CHECK ( (account_type = 0 AND hd_seed_fingerprint IS NOT NULL AND hd_account_index IS NOT NULL AND ufvk IS NOT NULL) OR (account_type = 1 AND hd_seed_fingerprint IS NULL AND hd_account_index IS NULL) )
CHECK ( (account_kind = 0 AND hd_seed_fingerprint IS NOT NULL AND hd_account_index IS NOT NULL AND ufvk IS NOT NULL) OR (account_kind = 1 AND hd_seed_fingerprint IS NULL AND hd_account_index IS NULL) )
)"#,
r#"CREATE TABLE "addresses" (
account_id INTEGER NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
type Error = WalletMigrationError;

fn up(&self, transaction: &Transaction) -> Result<(), WalletMigrationError> {
let account_type_derived = account_kind_code(AccountKind::Derived {
let account_kind_derived = account_kind_code(AccountKind::Derived {
seed_fingerprint: HdSeedFingerprint::from_bytes([0; 32]),
account_index: zip32::AccountId::ZERO,
});
let account_type_imported = account_kind_code(AccountKind::Imported);
let account_kind_imported = account_kind_code(AccountKind::Imported);
transaction.execute_batch(
&format!(r#"
PRAGMA foreign_keys = OFF;
PRAGMA legacy_alter_table = ON;
CREATE TABLE accounts_new (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
account_type INTEGER NOT NULL DEFAULT {account_type_derived},
account_kind INTEGER NOT NULL DEFAULT {account_kind_derived},
hd_seed_fingerprint BLOB,
hd_account_index INTEGER,
ufvk TEXT,
Expand All @@ -67,9 +67,9 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
birthday_height INTEGER NOT NULL,
recover_until_height INTEGER,
CHECK (
(account_type = {account_type_derived} AND hd_seed_fingerprint IS NOT NULL AND hd_account_index IS NOT NULL AND ufvk IS NOT NULL)
(account_kind = {account_kind_derived} AND hd_seed_fingerprint IS NOT NULL AND hd_account_index IS NOT NULL AND ufvk IS NOT NULL)
OR
(account_type = {account_type_imported} AND hd_seed_fingerprint IS NULL AND hd_account_index IS NULL)
(account_kind = {account_kind_imported} AND hd_seed_fingerprint IS NULL AND hd_account_index IS NULL)
)
);
CREATE UNIQUE INDEX hd_account ON accounts_new (hd_seed_fingerprint, hd_account_index);
Expand Down Expand Up @@ -130,21 +130,21 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
transaction.execute(
r#"
INSERT INTO accounts_new (
id, account_type, hd_seed_fingerprint, hd_account_index,
id, account_kind, hd_seed_fingerprint, hd_account_index,
ufvk, uivk,
orchard_fvk_item_cache, sapling_fvk_item_cache, p2pkh_fvk_item_cache,
birthday_height, recover_until_height
)
VALUES (
:account_id, :account_type, :seed_id, :account_index,
:account_id, :account_kind, :seed_id, :account_index,
:ufvk, :uivk,
:orchard_fvk_item_cache, :sapling_fvk_item_cache, :p2pkh_fvk_item_cache,
:birthday_height, :recover_until_height
);
"#,
named_params![
":account_id": account_id,
":account_type": account_type_derived,
":account_kind": account_kind_derived,
":seed_id": seed_id.as_bytes(),
":account_index": account_index,
":ufvk": ufvk,
Expand Down

0 comments on commit b161472

Please sign in to comment.