From a9c2d773f632d4a968355213699ce1db6101107c 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 427a54a048..c008c48a77 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1198,26 +1198,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