Skip to content

Commit

Permalink
Properly compute walletTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Oct 28, 2024
1 parent 78a46c9 commit b502cfd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
9 changes: 7 additions & 2 deletions js/pivx_shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ interface TransactionResult {
decrypted_new_notes: [Note, string][];
commitment_tree: string;
nullifiers: string[];
/**
* hex of the transactions belonging to the wallet
* i.e. either the spend or output belongs to us
*/
wallet_transactions: string[];
}

interface Transaction {
Expand Down Expand Up @@ -313,7 +318,6 @@ export class PIVXShield {

async handleBlocks(blocks: Block[]) {
if (blocks.length === 0) return [];
const walletTransactions: string[] = [];
if (
!blocks.every((block, i) => {
if (i === 0) {
Expand All @@ -339,6 +343,7 @@ export class PIVXShield {
decrypted_new_notes,
nullifiers,
commitment_tree,
wallet_transactions,
} = await this.callWorker<TransactionResult>(
"handle_blocks",
this.commitmentTree,
Expand All @@ -365,7 +370,7 @@ export class PIVXShield {
await this.removeSpentNotes(nullifiers);
this.lastProcessedBlock = blocks[blocks.length - 1].height;

return walletTransactions;
return wallet_transactions;
}

/**
Expand Down
28 changes: 17 additions & 11 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub struct JSTxSaplingData {
pub decrypted_new_notes: Vec<(Note, String)>,
pub nullifiers: Vec<String>,
pub commitment_tree: String,
pub wallet_transactions: Vec<String>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -164,19 +165,23 @@ pub fn handle_blocks(
.collect::<Vec<_>>();
let mut nullifiers = vec![];
let mut new_notes = vec![];
let mut wallet_transactions = vec![];
for block in blocks {
for tx in block.txs {
nullifiers.extend(
handle_transaction(
&mut tree,
&tx,
key.clone(),
is_testnet,
&mut comp_note,
&mut new_notes,
)
.map_err(|_| "Couldn't handle transaction")?,
);
let old_note_length = new_notes.len();
let tx_nullifiers = handle_transaction(
&mut tree,
&tx,
key.clone(),
is_testnet,
&mut comp_note,
&mut new_notes,
)
.map_err(|_| "Couldn't handle transaction")?;
if !tx_nullifiers.is_empty() || old_note_length != new_notes.len() {
wallet_transactions.push(tx);
}
nullifiers.extend(tx_nullifiers);
}
}

Expand All @@ -196,6 +201,7 @@ pub fn handle_blocks(
decrypted_notes: ser_comp_note,
nullifiers: ser_nullifiers,
commitment_tree: hex::encode(buff),
wallet_transactions,
decrypted_new_notes: ser_new_comp_note,
})?)
}
Expand Down

0 comments on commit b502cfd

Please sign in to comment.