Skip to content

Commit

Permalink
Update shield lib (#462)
Browse files Browse the repository at this point in the history
* feat: Update pivx-shield library

* feat: Update to the new PIVXShield.load return type
  • Loading branch information
panleone authored Nov 12, 2024
1 parent 968c266 commit 22fe25f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
"jquery": "^3.6.3",
"pinia": "^2.1.7",
"pivx-promos": "^0.2.0",
"pivx-shield": "^1.1.6",
"pivx-shield-rust": "^1.1.6",
"pivx-shield-rust-multicore": "^1.1.10",
"pivx-shield": "^1.2.0-7",
"pivx-shield-rust": "^1.2.0-7",
"pivx-shield-rust-multicore": "^1.2.0-7",
"qr-scanner": "^1.4.2",
"qrcode-generator": "^1.4.4",
"vue": "^3.3.4",
Expand Down
26 changes: 20 additions & 6 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { guiToggleReceiveType } from './contacts-book.js';
import { TransactionBuilder } from './transaction_builder.js';
import { createAlert } from './alerts/alert.js';
import { AsyncInterval } from './async_interval.js';
import { debugError, DebugTopics } from './debug.js';
import { debugError, debugLog, DebugTopics } from './debug.js';
import { OrderedArray } from './ordered_array.js';

/**
Expand Down Expand Up @@ -929,8 +929,7 @@ export class Wallet {
createAlert('warning', translation.badSaplingRoot, 5000);
this.#mempool = new Mempool();
this.#isSynced = false;
// TODO: take the wallet creation height in input from users
await this.#shield.reloadFromCheckpoint(4200000);
await this.#resetShield();
await this.#transparentSync();
await this.#syncShield();
return false;
Expand Down Expand Up @@ -964,9 +963,24 @@ export class Wallet {
if (!cAccount || cAccount.shieldData === '') {
return;
}
this.#shield = await PIVXShield.load(cAccount.shieldData);
getEventEmitter().emit('shield-loaded-from-disk');
return;
const loadRes = await PIVXShield.load(cAccount.shieldData);
this.#shield = loadRes.pivxShield;
// Load operation was not successful!
// Provided data are not compatible with the latest PIVX shield version.
// Resetting the shield object is required
if (!loadRes.success) {
debugLog(
DebugTopics.WALLET,
'Shield backup is not compatible with latest library version'
);
await this.#resetShield();
}
}

async #resetShield() {
// TODO: take the wallet creation height in input from users
await this.#shield.reloadFromCheckpoint(4200000);
await this.saveShieldOnDisk();
}

/**
Expand Down

0 comments on commit 22fe25f

Please sign in to comment.