From 6e9cfeed23bffed88e2f5db3403776487a11cb77 Mon Sep 17 00:00:00 2001 From: Duddino Date: Mon, 28 Oct 2024 09:44:52 +0100 Subject: [PATCH] Fix ts to use correct interface and remove addTransaction --- js/pivx_shield.ts | 44 +++++++++++++++----------------------------- src/transaction.rs | 1 - 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/js/pivx_shield.ts b/js/pivx_shield.ts index 80e9532..0a974b4 100644 --- a/js/pivx_shield.ts +++ b/js/pivx_shield.ts @@ -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][]; @@ -335,7 +342,11 @@ export class PIVXShield { } = await this.callWorker( "handle_blocks", this.commitmentTree, - blocks, + blocks.map(block=>{ + return { + txs: block.txs.map(({hex}) => hex) + } + }) satisfies RustBlock[], this.extfvk, this.isTestnet, this.unspentNotes, @@ -398,37 +409,12 @@ export class PIVXShield { } return simplifiedNotes; } - async addTransaction(hex: string) { - const res = await this.callWorker( - "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( - "handle_transaction", + "handle_blocks", this.commitmentTree, - hex, + [{txs: [hex]}] satisfies RustBlock[], this.extfvk, this.isTestnet, [], diff --git a/src/transaction.rs b/src/transaction.rs index 57a8306..3fa1893 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -132,7 +132,6 @@ pub struct JSTxSaplingData { #[derive(Serialize, Deserialize)] pub struct Block { - height: u32, txs: Vec, }