zcash_client_sqlite: Generalize `ReceivedNoteId`
This commit is contained in:
parent
d55edd8dd8
commit
e2ac746e9d
|
@ -132,14 +132,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)]
|
#[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 {
|
impl fmt::Display for ReceivedNoteId {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ReceivedNoteId(id) => write!(f, "Received Note {}", id),
|
ReceivedNoteId(protocol, id) => write!(f, "Received {:?} Note: {}", protocol, id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use zcash_client_backend::{
|
||||||
data_api::NullifierQuery,
|
data_api::NullifierQuery,
|
||||||
keys::UnifiedFullViewingKey,
|
keys::UnifiedFullViewingKey,
|
||||||
wallet::{Note, ReceivedNote, WalletSaplingOutput},
|
wallet::{Note, ReceivedNote, WalletSaplingOutput},
|
||||||
DecryptedOutput, TransferType,
|
DecryptedOutput, ShieldedProtocol, TransferType,
|
||||||
};
|
};
|
||||||
use zcash_primitives::transaction::{components::amount::NonNegativeAmount, TxId};
|
use zcash_primitives::transaction::{components::amount::NonNegativeAmount, TxId};
|
||||||
use zcash_protocol::{
|
use zcash_protocol::{
|
||||||
|
@ -97,7 +97,7 @@ fn to_spendable_note<P: consensus::Parameters>(
|
||||||
params: &P,
|
params: &P,
|
||||||
row: &Row,
|
row: &Row,
|
||||||
) -> Result<ReceivedNote<ReceivedNoteId, Note>, SqliteClientError> {
|
) -> Result<ReceivedNote<ReceivedNoteId, Note>, SqliteClientError> {
|
||||||
let note_id = ReceivedNoteId(row.get(0)?);
|
let note_id = ReceivedNoteId(ShieldedProtocol::Sapling, row.get(0)?);
|
||||||
let txid = row.get::<_, [u8; 32]>(1).map(TxId::from_bytes)?;
|
let txid = row.get::<_, [u8; 32]>(1).map(TxId::from_bytes)?;
|
||||||
let output_index = row.get(2)?;
|
let output_index = row.get(2)?;
|
||||||
let diversifier = {
|
let diversifier = {
|
||||||
|
@ -299,7 +299,7 @@ pub(crate) fn select_spendable_sapling_notes<P: consensus::Parameters>(
|
||||||
FROM (SELECT * from eligible WHERE so_far >= :target_value LIMIT 1)",
|
FROM (SELECT * from eligible WHERE so_far >= :target_value LIMIT 1)",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let excluded: Vec<Value> = exclude.iter().map(|n| Value::from(n.0)).collect();
|
let excluded: Vec<Value> = exclude.iter().map(|n| Value::from(n.1)).collect();
|
||||||
let excluded_ptr = Rc::new(excluded);
|
let excluded_ptr = Rc::new(excluded);
|
||||||
|
|
||||||
let notes = stmt_select_notes.query_and_then(
|
let notes = stmt_select_notes.query_and_then(
|
||||||
|
@ -329,7 +329,7 @@ pub(crate) fn get_sapling_nullifiers(
|
||||||
// Get the nullifiers for the notes we are tracking
|
// Get the nullifiers for the notes we are tracking
|
||||||
let mut stmt_fetch_nullifiers = match query {
|
let mut stmt_fetch_nullifiers = match query {
|
||||||
NullifierQuery::Unspent => conn.prepare(
|
NullifierQuery::Unspent => conn.prepare(
|
||||||
"SELECT rn.id, rn.account_id, rn.nf
|
"SELECT rn.account_id, rn.nf
|
||||||
FROM sapling_received_notes rn
|
FROM sapling_received_notes rn
|
||||||
LEFT OUTER JOIN transactions tx
|
LEFT OUTER JOIN transactions tx
|
||||||
ON tx.id_tx = rn.spent
|
ON tx.id_tx = rn.spent
|
||||||
|
@ -337,15 +337,15 @@ pub(crate) fn get_sapling_nullifiers(
|
||||||
AND nf IS NOT NULL",
|
AND nf IS NOT NULL",
|
||||||
),
|
),
|
||||||
NullifierQuery::All => conn.prepare(
|
NullifierQuery::All => conn.prepare(
|
||||||
"SELECT rn.id, rn.account_id, rn.nf
|
"SELECT rn.account_id, rn.nf
|
||||||
FROM sapling_received_notes rn
|
FROM sapling_received_notes rn
|
||||||
WHERE nf IS NOT NULL",
|
WHERE nf IS NOT NULL",
|
||||||
),
|
),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
let nullifiers = stmt_fetch_nullifiers.query_and_then([], |row| {
|
let nullifiers = stmt_fetch_nullifiers.query_and_then([], |row| {
|
||||||
let account = AccountId(row.get(1)?);
|
let account = AccountId(row.get(0)?);
|
||||||
let nf_bytes: Vec<u8> = row.get(2)?;
|
let nf_bytes: Vec<u8> = row.get(1)?;
|
||||||
Ok::<_, rusqlite::Error>((account, sapling::Nullifier::from_slice(&nf_bytes).unwrap()))
|
Ok::<_, rusqlite::Error>((account, sapling::Nullifier::from_slice(&nf_bytes).unwrap()))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue