Skip to content

Commit

Permalink
view: ugly workaround for source issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Jan 4, 2024
1 parent 717b8a0 commit bee6268
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 7 additions & 2 deletions crates/view/src/note_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ impl TryFrom<&Row<'_>> for SpendableNoteRecord {
.ok()
.flatten();
let return_address = return_address_bytes
.map(|b| AddressView::decode(b.as_slice()))
.transpose()?;
.map(|b| {
println!("return_address_bytes: {:?}", hex::encode(&b));
// Address is not proto-encoded
Address::try_from(b)
})
.transpose()?
.map(|a| AddressView::Opaque { address: a });
Ok(SpendableNoteRecord {
address_index: row.get::<_, Vec<u8>>("address_index")?[..].try_into()?,
nullifier: row.get::<_, Vec<u8>>("nullifier")?[..].try_into()?,
Expand Down
16 changes: 12 additions & 4 deletions crates/view/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ impl Storage {
spendable_notes.source,
spendable_notes.height_spent,
spendable_notes.nullifier,
spendable_notes.position
spendable_notes.position,
tx.return_address
FROM notes
JOIN spendable_notes ON notes.note_commitment = spendable_notes.note_commitment
LEFT JOIN tx ON SUBSTR(spendable_notes.source, 5) = tx.tx_hash
WHERE notes.note_commitment = x'{}'",
hex::encode(note_commitment.0.to_bytes())
))?
Expand Down Expand Up @@ -790,9 +792,11 @@ impl Storage {
spendable_notes.source,
spendable_notes.height_spent,
spendable_notes.nullifier,
spendable_notes.position
spendable_notes.position,
tx.return_address
FROM notes
JOIN spendable_notes ON notes.note_commitment = spendable_notes.note_commitment
LEFT JOIN tx ON SUBSTR(spendable_notes.source, 5) = tx.tx_hash
WHERE hex(spendable_notes.nullifier) = \"{}\"",
hex::encode_upper(nullifier_bytes)
))?
Expand Down Expand Up @@ -963,9 +967,11 @@ impl Storage {
spendable_notes.source,
spendable_notes.height_spent,
spendable_notes.nullifier,
spendable_notes.position
spendable_notes.position,
tx.return_address
FROM notes
JOIN spendable_notes ON notes.note_commitment = spendable_notes.note_commitment
LEFT JOIN tx ON SUBSTR(spendable_notes.source, 5) = tx.tx_hash
WHERE spendable_notes.height_spent IS {spent_clause}
AND notes.asset_id IS {asset_clause}
AND spendable_notes.address_index IS {address_clause}"
Expand Down Expand Up @@ -1670,6 +1676,8 @@ impl Storage {
) -> anyhow::Result<Vec<SpendableNoteRecord>> {
let pool = self.pool.clone();

// NOTE on SUBSTR:
// The `source` field is proto-encoded, if it's a tx hash, that will involve a 4-byte prefix 0x0a220a20
let query = "SELECT notes.note_commitment,
spendable_notes.height_created,
notes.address,
Expand All @@ -1683,7 +1691,7 @@ impl Storage {
spendable_notes.position
FROM notes
JOIN spendable_notes ON notes.note_commitment = spendable_notes.note_commitment
JOIN tx ON spendable_notes.source = tx.tx_hash
JOIN tx ON SUBSTR(spendable_notes.source, 5) = tx.tx_hash
WHERE tx.return_address = ?1";

let return_address = return_address.to_vec();
Expand Down

0 comments on commit bee6268

Please sign in to comment.