Add `WalletRead::is_seed_relevant_to_any_derived_accounts`
This commit is contained in:
parent
8c7f8d07ba
commit
e6bc21b461
|
@ -59,6 +59,8 @@ and this library adheres to Rust's notion of
|
||||||
- Arguments to `ScannedBlock::from_parts` have changed.
|
- Arguments to `ScannedBlock::from_parts` have changed.
|
||||||
- Changes to the `WalletRead` trait:
|
- Changes to the `WalletRead` trait:
|
||||||
- Added `Account` associated type.
|
- Added `Account` associated type.
|
||||||
|
- Added `validate_seed` method.
|
||||||
|
- Added `is_seed_relevant_to_any_derived_accounts` method.
|
||||||
- Added `get_account` method.
|
- Added `get_account` method.
|
||||||
- Added `get_derived_account` method.
|
- Added `get_derived_account` method.
|
||||||
- `get_account_for_ufvk` now returns `Self::Account` instead of a bare
|
- `get_account_for_ufvk` now returns `Self::Account` instead of a bare
|
||||||
|
@ -80,7 +82,6 @@ and this library adheres to Rust's notion of
|
||||||
- `type OrchardShardStore`
|
- `type OrchardShardStore`
|
||||||
- `fn with_orchard_tree_mut`
|
- `fn with_orchard_tree_mut`
|
||||||
- `fn put_orchard_subtree_roots`
|
- `fn put_orchard_subtree_roots`
|
||||||
- Added method `WalletRead::validate_seed`
|
|
||||||
- Removed `Error::AccountNotFound` variant.
|
- Removed `Error::AccountNotFound` variant.
|
||||||
- `WalletSummary::new` now takes an additional `next_orchard_subtree_index`
|
- `WalletSummary::new` now takes an additional `next_orchard_subtree_index`
|
||||||
argument when the `orchard` feature flag is enabled.
|
argument when the `orchard` feature flag is enabled.
|
||||||
|
|
|
@ -740,6 +740,13 @@ pub trait WalletRead {
|
||||||
seed: &SecretVec<u8>,
|
seed: &SecretVec<u8>,
|
||||||
) -> Result<bool, Self::Error>;
|
) -> Result<bool, Self::Error>;
|
||||||
|
|
||||||
|
/// Checks whether the given seed is relevant to any of the derived accounts (where
|
||||||
|
/// [`Account::source`] is [`AccountSource::Derived`]) in the wallet.
|
||||||
|
fn is_seed_relevant_to_any_derived_accounts(
|
||||||
|
&self,
|
||||||
|
seed: &SecretVec<u8>,
|
||||||
|
) -> Result<bool, Self::Error>;
|
||||||
|
|
||||||
/// Returns the account corresponding to a given [`UnifiedFullViewingKey`], if any.
|
/// Returns the account corresponding to a given [`UnifiedFullViewingKey`], if any.
|
||||||
fn get_account_for_ufvk(
|
fn get_account_for_ufvk(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1719,6 +1726,13 @@ pub mod testing {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_seed_relevant_to_any_derived_accounts(
|
||||||
|
&self,
|
||||||
|
_seed: &SecretVec<u8>,
|
||||||
|
) -> Result<bool, Self::Error> {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_account_for_ufvk(
|
fn get_account_for_ufvk(
|
||||||
&self,
|
&self,
|
||||||
_ufvk: &UnifiedFullViewingKey,
|
_ufvk: &UnifiedFullViewingKey,
|
||||||
|
|
|
@ -337,6 +337,39 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> WalletRead for W
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_seed_relevant_to_any_derived_accounts(
|
||||||
|
&self,
|
||||||
|
seed: &SecretVec<u8>,
|
||||||
|
) -> Result<bool, Self::Error> {
|
||||||
|
for account_id in self.get_account_ids()? {
|
||||||
|
let account = self.get_account(account_id)?.expect("account ID exists");
|
||||||
|
|
||||||
|
// If the account is imported, the seed _might_ be relevant, but the only
|
||||||
|
// way we could determine that is by brute-forcing the ZIP 32 account
|
||||||
|
// index space, which we're not going to do. The method name indicates to
|
||||||
|
// the caller that we only check derived accounts.
|
||||||
|
if let AccountSource::Derived {
|
||||||
|
seed_fingerprint,
|
||||||
|
account_index,
|
||||||
|
} = account.source()
|
||||||
|
{
|
||||||
|
if wallet::seed_matches_derived_account(
|
||||||
|
&self.params,
|
||||||
|
seed,
|
||||||
|
&seed_fingerprint,
|
||||||
|
account_index,
|
||||||
|
&account.uivk(),
|
||||||
|
)? {
|
||||||
|
// The seed is relevant to this account. No need to check any others.
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The seed was not relevant to any of the accounts in the wallet.
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_account_for_ufvk(
|
fn get_account_for_ufvk(
|
||||||
&self,
|
&self,
|
||||||
ufvk: &UnifiedFullViewingKey,
|
ufvk: &UnifiedFullViewingKey,
|
||||||
|
|
Loading…
Reference in New Issue