diff --git a/js/pivx_shield.ts b/js/pivx_shield.ts index a44e443..9ef7c99 100644 --- a/js/pivx_shield.ts +++ b/js/pivx_shield.ts @@ -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 { @@ -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) { @@ -339,6 +343,7 @@ export class PIVXShield { decrypted_new_notes, nullifiers, commitment_tree, + wallet_transactions, } = await this.callWorker( "handle_blocks", this.commitmentTree, @@ -365,7 +370,7 @@ export class PIVXShield { await this.removeSpentNotes(nullifiers); this.lastProcessedBlock = blocks[blocks.length - 1].height; - return walletTransactions; + return wallet_transactions; } /** diff --git a/src/transaction.rs b/src/transaction.rs index 1c0741c..05e6bc5 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -87,6 +87,7 @@ pub struct JSTxSaplingData { pub decrypted_new_notes: Vec<(Note, String)>, pub nullifiers: Vec, pub commitment_tree: String, + pub wallet_transactions: Vec, } #[derive(Serialize, Deserialize)] @@ -123,19 +124,23 @@ pub fn handle_blocks( .collect::>(); 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); } } @@ -155,6 +160,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, })?) }