Skip to content

Commit

Permalink
zcash_client_sqlite: Add Orchard support to get_received_memo
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d authored and nuttycom committed Mar 10, 2024
1 parent 9ccedf2 commit 4ef9452
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,26 +1196,26 @@ pub(crate) fn get_received_memo(
conn: &rusqlite::Connection,
note_id: NoteId,
) -> Result<Option<Memo>, SqliteClientError> {
let memo_bytes: Option<Vec<_>> = 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<Vec<_>> = 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
Expand Down

0 comments on commit 4ef9452

Please sign in to comment.