diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 524e9e684..0ca7083e2 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -1405,6 +1405,16 @@ pub struct SentTransaction<'a, AccountId> { impl<'a, AccountId> SentTransaction<'a, AccountId> { /// Constructs a new [`SentTransaction`] from its constituent parts. + /// + /// ### Parameters + /// - `tx`: the raw transaction data + /// - `created`: the system time at which the transaction was created + /// - `target_height`: the target height that was used in the construction of the transaction + /// - `account`: the account that spent funds in creation of the transaction + /// - `outputs`: the outputs created by the transaction, including those sent to external + /// recipients which may not otherwise be recoverable + /// - `fee_amount`: the fee value paid by the transaction + /// - `utxos_spent`: the UTXOs controlled by the wallet that were spent in this transaction pub fn new( tx: &'a Transaction, created: time::OffsetDateTime, diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 139af897a..e4728625d 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -119,7 +119,7 @@ pub mod error; pub mod wallet; use wallet::{ commitment_tree::{self, put_shard_roots}, - notify_tx_retrieved, SubtreeScanProgress, TxQueryType, + notify_tx_retrieved, SubtreeScanProgress, }; #[cfg(feature = "transparent-inputs")] @@ -800,12 +800,7 @@ impl WalletWrite for WalletDb for tx in block.transactions() { let tx_row = wallet::put_tx_meta(wdb.conn.0, tx, block.height())?; - wallet::queue_tx_retrieval( - wdb.conn.0, - std::iter::once(tx.txid()), - TxQueryType::Enhancement, - None, - )?; + wallet::queue_tx_retrieval(wdb.conn.0, std::iter::once(tx.txid()), None)?; // Mark notes as spent and remove them from the scanning cache for spend in tx.sapling_spends() { @@ -1518,7 +1513,6 @@ impl WalletWrite for WalletDb wallet::queue_tx_retrieval( wdb.conn.0, b.vin.iter().map(|txin| *txin.prevout.txid()), - TxQueryType::Enhancement, Some(tx_ref) )?; } @@ -1531,7 +1525,6 @@ impl WalletWrite for WalletDb wallet::queue_tx_retrieval( wdb.conn.0, std::iter::once(d_tx.tx().txid()), - TxQueryType::Status, None )?; } diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index cbe1011ff..182576332 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1978,12 +1978,7 @@ pub(crate) fn store_transaction_to_be_sent( // at present for fully transparent transactions, because any transaction with a shielded // component will be detected via ordinary chain scanning and/or nullifier checking. if !detectable_via_scanning { - queue_tx_retrieval( - wdb.conn.0, - std::iter::once(sent_tx.tx().txid()), - TxQueryType::Status, - None, - )?; + queue_tx_retrieval(wdb.conn.0, std::iter::once(sent_tx.tx().txid()), None)?; } Ok(()) @@ -2409,31 +2404,35 @@ impl TxQueryType { pub(crate) fn queue_tx_retrieval( conn: &rusqlite::Transaction<'_>, txids: impl Iterator, - query_type: TxQueryType, dependent_tx_ref: Option, ) -> Result<(), SqliteClientError> { // Add an entry to the transaction retrieval queue if it would not be redundant. let mut stmt_insert_tx = conn.prepare_cached( "INSERT INTO tx_retrieval_queue (txid, query_type, dependent_transaction_id) - SELECT :txid, :query_type, :dependent_transaction_id - -- do not queue enhancement requests if we already have the raw transaction - WHERE :query_type <> :enhancement_type OR NOT EXISTS ( - SELECT 1 FROM transactions - WHERE txid = :txid - AND raw IS NOT NULL - ) - -- if there is already a status request, we can upgrade it to an enhancement request + SELECT + :txid, + IIF( + EXISTS (SELECT 1 FROM transactions WHERE txid = :txid AND raw IS NOT NULL), + :status_type, + :enhancement_type + ), + :dependent_transaction_id ON CONFLICT (txid) DO UPDATE - SET query_type = MAX(:query_type, query_type), + SET query_type = + IIF( + EXISTS (SELECT 1 FROM transactions WHERE txid = :txid AND raw IS NOT NULL), + :status_type, + :enhancement_type + ), dependent_transaction_id = IFNULL(:dependent_transaction_id, dependent_transaction_id)", )?; for txid in txids { stmt_insert_tx.execute(named_params! { ":txid": txid.as_ref(), - ":query_type": query_type.code(), - ":dependent_transaction_id": dependent_tx_ref.map(|r| r.0), + ":status_type": TxQueryType::Status.code(), ":enhancement_type": TxQueryType::Enhancement.code(), + ":dependent_transaction_id": dependent_tx_ref.map(|r| r.0), })?; }