From bdd0990db2f566bcc0a072650dcb404a800739d2 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 1 Apr 2024 13:49:40 -0600 Subject: [PATCH] zcash_client_sqlite: Use named column accessors for `to_spendable_note` --- zcash_client_sqlite/src/wallet/orchard.rs | 25 ++++++++++++----------- zcash_client_sqlite/src/wallet/sapling.rs | 23 +++++++++++---------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/orchard.rs b/zcash_client_sqlite/src/wallet/orchard.rs index 9545460ff1..373d76c014 100644 --- a/zcash_client_sqlite/src/wallet/orchard.rs +++ b/zcash_client_sqlite/src/wallet/orchard.rs @@ -99,11 +99,11 @@ fn to_spendable_note( params: &P, row: &Row, ) -> Result>, SqliteClientError> { - let note_id = ReceivedNoteId(ShieldedProtocol::Orchard, row.get(0)?); - let txid = row.get::<_, [u8; 32]>(1).map(TxId::from_bytes)?; - let action_index = row.get(2)?; + let note_id = ReceivedNoteId(ShieldedProtocol::Orchard, row.get("id")?); + let txid = row.get::<_, [u8; 32]>("txid").map(TxId::from_bytes)?; + let action_index = row.get("action_index")?; let diversifier = { - let d: Vec<_> = row.get(3)?; + let d: Vec<_> = row.get("diversifier")?; if d.len() != 11 { return Err(SqliteClientError::CorruptedData( "Invalid diversifier length".to_string(), @@ -114,30 +114,31 @@ fn to_spendable_note( Diversifier::from_bytes(tmp) }; - let note_value: u64 = row.get::<_, i64>(4)?.try_into().map_err(|_e| { + let note_value: u64 = row.get::<_, i64>("value")?.try_into().map_err(|_e| { SqliteClientError::CorruptedData("Note values must be nonnegative".to_string()) })?; let rho = { - let rho_bytes: [u8; 32] = row.get(5)?; + let rho_bytes: [u8; 32] = row.get("rho")?; Option::from(Rho::from_bytes(&rho_bytes)) .ok_or_else(|| SqliteClientError::CorruptedData("Invalid rho.".to_string())) }?; let rseed = { - let rseed_bytes: [u8; 32] = row.get(6)?; + let rseed_bytes: [u8; 32] = row.get("rseed")?; Option::from(RandomSeed::from_bytes(rseed_bytes, &rho)).ok_or_else(|| { SqliteClientError::CorruptedData("Invalid Orchard random seed.".to_string()) }) }?; - let note_commitment_tree_position = - Position::from(u64::try_from(row.get::<_, i64>(7)?).map_err(|_| { + let note_commitment_tree_position = Position::from( + u64::try_from(row.get::<_, i64>("commitment_tree_position")?).map_err(|_| { SqliteClientError::CorruptedData("Note commitment tree position invalid.".to_string()) - })?); + })?, + ); - let ufvk_str: Option = row.get(8)?; - let scope_code: Option = row.get(9)?; + let ufvk_str: Option = row.get("ufvk")?; + let scope_code: Option = row.get("recipient_key_scope")?; // If we don't have information about the recipient key scope or the ufvk we can't determine // which spending key to use. This may be because the received note was associated with an diff --git a/zcash_client_sqlite/src/wallet/sapling.rs b/zcash_client_sqlite/src/wallet/sapling.rs index 63550dca7f..63dc4188bc 100644 --- a/zcash_client_sqlite/src/wallet/sapling.rs +++ b/zcash_client_sqlite/src/wallet/sapling.rs @@ -98,11 +98,11 @@ fn to_spendable_note( params: &P, row: &Row, ) -> Result>, SqliteClientError> { - let note_id = ReceivedNoteId(ShieldedProtocol::Sapling, row.get(0)?); - let txid = row.get::<_, [u8; 32]>(1).map(TxId::from_bytes)?; - let output_index = row.get(2)?; + let note_id = ReceivedNoteId(ShieldedProtocol::Sapling, row.get("id")?); + let txid = row.get::<_, [u8; 32]>("txid").map(TxId::from_bytes)?; + let output_index = row.get("output_index")?; let diversifier = { - let d: Vec<_> = row.get(3)?; + let d: Vec<_> = row.get("diversifier")?; if d.len() != 11 { return Err(SqliteClientError::CorruptedData( "Invalid diversifier length".to_string(), @@ -113,12 +113,12 @@ fn to_spendable_note( Diversifier(tmp) }; - let note_value: u64 = row.get::<_, i64>(4)?.try_into().map_err(|_e| { + let note_value: u64 = row.get::<_, i64>("value")?.try_into().map_err(|_e| { SqliteClientError::CorruptedData("Note values must be nonnegative".to_string()) })?; let rseed = { - let rcm_bytes: Vec<_> = row.get(5)?; + let rcm_bytes: Vec<_> = row.get("rcm")?; // We store rcm directly in the data DB, regardless of whether the note // used a v1 or v2 note plaintext, so for the purposes of spending let's @@ -132,13 +132,14 @@ fn to_spendable_note( Rseed::BeforeZip212(rcm) }; - let note_commitment_tree_position = - Position::from(u64::try_from(row.get::<_, i64>(6)?).map_err(|_| { + let note_commitment_tree_position = Position::from( + u64::try_from(row.get::<_, i64>("commitment_tree_position")?).map_err(|_| { SqliteClientError::CorruptedData("Note commitment tree position invalid.".to_string()) - })?); + })?, + ); - let ufvk_str: Option = row.get(7)?; - let scope_code: Option = row.get(8)?; + let ufvk_str: Option = row.get("ufvk")?; + let scope_code: Option = row.get("recipient_key_scope")?; // If we don't have information about the recipient key scope or the ufvk we can't determine // which spending key to use. This may be because the received note was associated with an