Skip to content

Commit

Permalink
zcash_client_sqlite: Add Orchard note selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Mar 8, 2024
1 parent 89d99f5 commit 3a0629b
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 32 deletions.
41 changes: 33 additions & 8 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use zcash_client_backend::{
},
proto::compact_formats::CompactBlock,
wallet::{Note, NoteId, ReceivedNote, Recipient, WalletTransparentOutput},
DecryptedOutput, ShieldedProtocol, TransferType,
DecryptedOutput, PoolType, ShieldedProtocol, TransferType,
};
use zcash_keys::keys::HdSeedFingerprint;
use zcash_primitives::{
Expand All @@ -76,7 +76,7 @@ use zip32::{DiversifierIndex, Scope};
use crate::{error::SqliteClientError, wallet::commitment_tree::SqliteShardStore};

#[cfg(feature = "orchard")]
use zcash_client_backend::{data_api::ORCHARD_SHARD_HEIGHT, PoolType};
use zcash_client_backend::data_api::ORCHARD_SHARD_HEIGHT;

#[cfg(feature = "transparent-inputs")]
use {
Expand Down Expand Up @@ -112,6 +112,7 @@ pub(crate) const PRUNING_DEPTH: u32 = 100;
pub(crate) const VERIFY_LOOKAHEAD: u32 = 10;

pub(crate) const SAPLING_TABLES_PREFIX: &str = "sapling";

#[cfg(feature = "orchard")]
pub(crate) const ORCHARD_TABLES_PREFIX: &str = "orchard";

Expand All @@ -135,14 +136,14 @@ impl ConditionallySelectable for AccountId {
}
}

/// A newtype wrapper for received note identifiers.
/// An opaque type for received note identifiers.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ReceivedNoteId(pub(crate) i64);
pub struct ReceivedNoteId(pub(crate) ShieldedProtocol, pub(crate) i64);

impl fmt::Display for ReceivedNoteId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ReceivedNoteId(id) => write!(f, "Received Note {}", id),
ReceivedNoteId(protocol, id) => write!(f, "Received {:?} Note: {}", protocol, id),

Check warning on line 146 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L146

Added line #L146 was not covered by tests
}
}
}
Expand Down Expand Up @@ -209,7 +210,20 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> InputSource for
txid,
index,
),
ShieldedProtocol::Orchard => Ok(None),
ShieldedProtocol::Orchard => {

Check warning on line 213 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L213

Added line #L213 was not covered by tests
#[cfg(feature = "orchard")]
return wallet::orchard::get_spendable_orchard_note(
self.conn.borrow(),
&self.params,
txid,
index,

Check warning on line 219 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L215-L219

Added lines #L215 - L219 were not covered by tests
);

#[cfg(not(feature = "orchard"))]
return Err(SqliteClientError::UnsupportedPoolType(PoolType::Shielded(
ShieldedProtocol::Orchard,

Check warning on line 224 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L223-L224

Added lines #L223 - L224 were not covered by tests
)));
}
}
}

Expand All @@ -221,14 +235,25 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> InputSource for
anchor_height: BlockHeight,
exclude: &[Self::NoteRef],
) -> Result<Vec<ReceivedNote<Self::NoteRef, Note>>, Self::Error> {
wallet::sapling::select_spendable_sapling_notes(
let received_iter = std::iter::empty();
let received_iter = received_iter.chain(wallet::sapling::select_spendable_sapling_notes(
self.conn.borrow(),
&self.params,
account,
target_value,
anchor_height,
exclude,
)
)?);
#[cfg(feature = "orchard")]
let received_iter = received_iter.chain(wallet::orchard::select_spendable_orchard_notes(
self.conn.borrow(),
&self.params,
account,
target_value,
anchor_height,
exclude,

Check warning on line 254 in zcash_client_sqlite/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/lib.rs#L248-L254

Added lines #L248 - L254 were not covered by tests
)?);
Ok(received_iter.collect())
}

#[cfg(feature = "transparent-inputs")]
Expand Down
6 changes: 4 additions & 2 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ use std::io::{self, Cursor};
use std::num::NonZeroU32;
use std::ops::RangeInclusive;
use tracing::debug;
use zcash_client_backend::data_api::ORCHARD_SHARD_HEIGHT;
use zcash_keys::keys::HdSeedFingerprint;

use zcash_client_backend::{
Expand Down Expand Up @@ -101,7 +100,6 @@ use zcash_primitives::{
zip32::{self, DiversifierIndex, Scope},
};

use crate::ORCHARD_TABLES_PREFIX;
use crate::{
error::SqliteClientError,
wallet::commitment_tree::{get_max_checkpointed_height, SqliteShardStore},
Expand All @@ -126,6 +124,9 @@ use {
},
};

#[cfg(feature = "orchard")]
use {crate::ORCHARD_TABLES_PREFIX, zcash_client_backend::data_api::ORCHARD_SHARD_HEIGHT};

pub mod commitment_tree;
pub mod init;
#[cfg(feature = "orchard")]
Expand Down Expand Up @@ -287,6 +288,7 @@ pub(crate) fn add_account<P: consensus::Parameters>(
)?;
}

#[cfg(feature = "orchard")]
if let Some(frontier) = birthday.orchard_frontier().value() {
debug!("Inserting Orchard frontier into ShardTree: {:?}", frontier);

Check warning on line 293 in zcash_client_sqlite/src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet.rs#L291-L293

Added lines #L291 - L293 were not covered by tests
let shard_store = SqliteShardStore::<
Expand Down
Loading

0 comments on commit 3a0629b

Please sign in to comment.