Skip to content

Commit

Permalink
Fix ts to use correct interface and remove addTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Oct 28, 2024
1 parent d37469b commit 6e9cfee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
44 changes: 15 additions & 29 deletions js/pivx_shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ interface Block {
height: number;
}

/**
* Block that's deserialized in rust
*/
interface RustBlock {
txs: string[],
}

interface TransactionResult {
decrypted_notes: [Note, string][];
decrypted_new_notes: [Note, string][];
Expand Down Expand Up @@ -335,7 +342,11 @@ export class PIVXShield {
} = await this.callWorker<TransactionResult>(
"handle_blocks",
this.commitmentTree,
blocks,
blocks.map(block=>{
return {
txs: block.txs.map(({hex}) => hex)
}
}) satisfies RustBlock[],
this.extfvk,
this.isTestnet,
this.unspentNotes,
Expand Down Expand Up @@ -398,37 +409,12 @@ export class PIVXShield {
}
return simplifiedNotes;
}
async addTransaction(hex: string) {
const res = await this.callWorker<TransactionResult>(
"handle_transaction",
this.commitmentTree,
hex,
this.extfvk,
this.isTestnet,
this.unspentNotes,
);
this.commitmentTree = res.commitment_tree;
this.unspentNotes = res.decrypted_notes.concat(res.decrypted_new_notes);

if (res.nullifiers.length > 0) {
await this.removeSpentNotes(res.nullifiers);
}
// Check if the transaction belongs to the wallet:
let belongToWallet = res.decrypted_new_notes.length > 0;
for (const nullifier of res.nullifiers) {
if (belongToWallet) {
break;
}
belongToWallet = belongToWallet || this.mapNullifierNote.has(nullifier);
}
return { belongToWallet, decryptedNewNotes: res.decrypted_new_notes };
}

async decryptTransaction(hex: string) {
async decryptTransaction(hex: string) {
const res = await this.callWorker<TransactionResult>(
"handle_transaction",
"handle_blocks",
this.commitmentTree,
hex,
[{txs: [hex]}] satisfies RustBlock[],
this.extfvk,
this.isTestnet,
[],
Expand Down
1 change: 0 additions & 1 deletion src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub struct JSTxSaplingData {

#[derive(Serialize, Deserialize)]
pub struct Block {
height: u32,
txs: Vec<String>,
}

Expand Down

0 comments on commit 6e9cfee

Please sign in to comment.