Skip to content

Commit

Permalink
zcash_client_sqlite: Skip gap address generation if no transparent ke…
Browse files Browse the repository at this point in the history
…y is available.
  • Loading branch information
nuttycom authored and str4d committed Mar 5, 2025
1 parent dcbdc47 commit 4efef40
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ impl<C: BorrowMut<rusqlite::Connection>, P: consensus::Parameters, CL: Clock> Wa
key_scope,
&wdb.gap_limits,
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
false,
)?;
}

Expand Down Expand Up @@ -1693,6 +1694,7 @@ impl<C: BorrowMut<rusqlite::Connection>, P: consensus::Parameters, CL: Clock> Wa
key_scope,
&wdb.gap_limits,
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
true,
)?;

Ok(utxo_id)
Expand Down
3 changes: 3 additions & 0 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ pub(crate) fn add_account<P: consensus::Parameters>(
key_scope,
gap_limits,
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
false,
)?;
}

Expand Down Expand Up @@ -670,6 +671,7 @@ pub(crate) fn get_next_available_address<P: consensus::Parameters, C: Clock>(
KeyScope::EXTERNAL,
gap_limits,
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
true,
)?;

// Select indices from the transparent gap limit that are available for use as
Expand Down Expand Up @@ -3414,6 +3416,7 @@ pub(crate) fn store_decrypted_tx<P: consensus::Parameters>(
key_scope,
gap_limits,
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
false,
)?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
key_scope,
&GapLimits::default(),
UnifiedAddressRequest::unsafe_custom(Allow, Allow, Require),
false,
)?;
}
}
Expand Down
17 changes: 14 additions & 3 deletions zcash_client_sqlite/src/wallet/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,21 @@ pub(crate) fn generate_gap_addresses<P: consensus::Parameters>(
key_scope: KeyScope,
gap_limits: &GapLimits,
request: UnifiedAddressRequest,
require_key: bool,
) -> Result<(), SqliteClientError> {
let account = get_account_internal(conn, params, account_id)?
.ok_or_else(|| SqliteClientError::AccountUnknown)?;

if !account.uivk().has_transparent() {
if require_key {
return Err(SqliteClientError::AddressGeneration(
AddressGenerationError::KeyNotAvailable(Typecode::P2pkh),
));
} else {
return Ok(());
}
}

let gen_addrs = |key_scope: KeyScope, index: NonHardenedChildIndex| {
Ok::<_, SqliteClientError>(match key_scope {
KeyScope::Zip32(zip32::Scope::External) => {
Expand All @@ -426,7 +437,7 @@ pub(crate) fn generate_gap_addresses<P: consensus::Parameters>(
.uivk()
.transparent()
.as_ref()
.ok_or(AddressGenerationError::KeyNotAvailable(Typecode::P2pkh))?
.expect("presence of transparent key was checked above.")
.derive_address(index)?;
(
ua.map_or_else(
Expand All @@ -448,7 +459,7 @@ pub(crate) fn generate_gap_addresses<P: consensus::Parameters>(
let internal_address = account
.ufvk()
.and_then(|k| k.transparent())
.ok_or(AddressGenerationError::KeyNotAvailable(Typecode::P2pkh))?
.expect("presence of transparent key was checked above.")
.derive_internal_ivk()?
.derive_address(index)?;
(
Expand All @@ -460,7 +471,7 @@ pub(crate) fn generate_gap_addresses<P: consensus::Parameters>(
let ephemeral_address = account
.ufvk()
.and_then(|k| k.transparent())
.ok_or(AddressGenerationError::KeyNotAvailable(Typecode::P2pkh))?
.expect("presence of transparent key was checked above.")
.derive_ephemeral_ivk()?
.derive_ephemeral_address(index)?;
(
Expand Down

0 comments on commit 4efef40

Please sign in to comment.