zcash_client_sqlite: Rename `account_type` column to `account_kind`
This commit is contained in:
parent
bbb7f36e55
commit
b161472cc0
|
@ -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(|_| {
|
||||
|
@ -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(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -351,13 +351,13 @@ 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
|
||||
|
@ -365,7 +365,7 @@ pub(crate) fn add_account<P: consensus::Parameters>(
|
|||
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)),
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
"#,
|
||||
|
@ -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")?,
|
||||
)?;
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -44,11 +44,11 @@ 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;
|
||||
|
@ -56,7 +56,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
|
|||
|
||||
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,
|
||||
|
@ -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);
|
||||
|
@ -130,13 +130,13 @@ 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
|
||||
|
@ -144,7 +144,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
|
|||
"#,
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue