Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_sqlite: Use named column accessors for to_spendable_note #1339

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions zcash_client_sqlite/src/wallet/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
params: &P,
row: &Row,
) -> Result<Option<ReceivedNote<ReceivedNoteId, Note>>, 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")?;

Check warning on line 104 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L102-L104

Added lines #L102 - L104 were not covered by tests
let diversifier = {
let d: Vec<_> = row.get(3)?;
let d: Vec<_> = row.get("diversifier")?;

Check warning on line 106 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L106

Added line #L106 was not covered by tests
if d.len() != 11 {
return Err(SqliteClientError::CorruptedData(
"Invalid diversifier length".to_string(),
Expand All @@ -114,30 +114,31 @@
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| {

Check warning on line 117 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L117

Added line #L117 was not covered by tests
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")?;

Check warning on line 122 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L122

Added line #L122 was not covered by tests
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")?;

Check warning on line 128 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L128

Added line #L128 was not covered by tests
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(|_| {

Check warning on line 135 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L135

Added line #L135 was not covered by tests
SqliteClientError::CorruptedData("Note commitment tree position invalid.".to_string())
})?);
})?,
);

let ufvk_str: Option<String> = row.get(8)?;
let scope_code: Option<i64> = row.get(9)?;
let ufvk_str: Option<String> = row.get("ufvk")?;
let scope_code: Option<i64> = row.get("recipient_key_scope")?;

Check warning on line 141 in zcash_client_sqlite/src/wallet/orchard.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L140-L141

Added lines #L140 - L141 were not covered by tests

// 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
Expand Down
23 changes: 12 additions & 11 deletions zcash_client_sqlite/src/wallet/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ fn to_spendable_note<P: consensus::Parameters>(
params: &P,
row: &Row,
) -> Result<Option<ReceivedNote<ReceivedNoteId, sapling::Note>>, 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(),
Expand All @@ -113,12 +113,12 @@ fn to_spendable_note<P: consensus::Parameters>(
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
Expand All @@ -132,13 +132,14 @@ fn to_spendable_note<P: consensus::Parameters>(
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<String> = row.get(7)?;
let scope_code: Option<i64> = row.get(8)?;
let ufvk_str: Option<String> = row.get("ufvk")?;
let scope_code: Option<i64> = 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
Expand Down
Loading