From 4ef9452a8482e9ca319cd728e0cf5c9ad1bf723c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 10 Mar 2024 20:07:56 +0000 Subject: [PATCH] zcash_client_sqlite: Add Orchard support to `get_received_memo` --- zcash_client_sqlite/src/wallet.rs | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 9e0362f9a..d356ec303 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1196,26 +1196,26 @@ pub(crate) fn get_received_memo( conn: &rusqlite::Connection, note_id: NoteId, ) -> Result, SqliteClientError> { - let memo_bytes: Option> = match note_id.protocol() { - ShieldedProtocol::Sapling => conn - .query_row( - "SELECT memo FROM sapling_received_notes - JOIN transactions ON sapling_received_notes.tx = transactions.id_tx + let fetch_memo = |table_prefix: &'static str, output_col: &'static str| { + conn.query_row( + &format!( + "SELECT memo FROM {table_prefix}_received_notes + JOIN transactions ON {table_prefix}_received_notes.tx = transactions.id_tx WHERE transactions.txid = :txid - AND sapling_received_notes.output_index = :output_index", - named_params![ - ":txid": note_id.txid().as_ref(), - ":output_index": note_id.output_index() - ], - |row| row.get(0), - ) - .optional()? - .flatten(), - _ => { - return Err(SqliteClientError::UnsupportedPoolType(PoolType::Shielded( - note_id.protocol(), - ))) - } + AND {table_prefix}_received_notes.{output_col} = :output_index" + ), + named_params![ + ":txid": note_id.txid().as_ref(), + ":output_index": note_id.output_index() + ], + |row| row.get(0), + ) + .optional() + }; + + let memo_bytes: Option> = match note_id.protocol() { + ShieldedProtocol::Sapling => fetch_memo(SAPLING_TABLES_PREFIX, "output_index")?.flatten(), + ShieldedProtocol::Orchard => fetch_memo(ORCHARD_TABLES_PREFIX, "action_index")?.flatten(), }; memo_bytes