Skip to content

Commit

Permalink
Merge pull request #91 from panleone/versioning
Browse files Browse the repository at this point in the history
Add  a versioning system
  • Loading branch information
Duddino authored Oct 25, 2024
2 parents ddfbceb + c610fc9 commit 5080fc9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions js/pivx_shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ interface CreateTransactionReturnValue {
}

export class PIVXShield {
/**
* integer to keep track of the current Shield version.
* v1: added mapNullifierNote
*/
static version = 1;

/**
* Webassembly object that holds Shield related functions
*/
Expand Down Expand Up @@ -250,6 +256,7 @@ export class PIVXShield {
*/
save() {
return JSON.stringify({
version: PIVXShield.version,
extfvk: this.extfvk,
lastProcessedBlock: this.lastProcessedBlock,
commitmentTree: this.commitmentTree,
Expand All @@ -269,6 +276,8 @@ export class PIVXShield {
new URL("worker_start.js", import.meta.url),
);

const currVersion = shieldData.version ?? 0;

await new Promise<void>((res) => {
shieldWorker.onmessage = (msg) => {
if (msg.data === "done") res();
Expand All @@ -282,18 +291,16 @@ export class PIVXShield {
shieldData.lastProcessedBlock,
shieldData.commitmentTree,
);
pivxShield.mapNullifierNote = new Map(
Object.entries(shieldData.mapNullifierNote ?? {}),
);

if (currVersion >= 1) {
pivxShield.mapNullifierNote = new Map(
Object.entries(shieldData.mapNullifierNote),
);
}
pivxShield.diversifierIndex = shieldData.diversifierIndex;
pivxShield.unspentNotes = shieldData.unspentNotes;

// Shield activity update: mapNullifierNote must be present in the shieldData
let success = true;
if (!shieldData.mapNullifierNote) {
success = false;
}
return { pivxShield, success };
return { pivxShield, success: currVersion == PIVXShield.version };
}

/**
Expand Down

0 comments on commit 5080fc9

Please sign in to comment.