From 7ceafc3994fa7606512901db1ea5e9e9101cc99d Mon Sep 17 00:00:00 2001 From: Duddino Date: Thu, 10 Jul 2025 09:44:19 +0200 Subject: [PATCH 1/3] Remember created block --- scripts/composables/use_wallet.js | 1 + scripts/dashboard/Dashboard.vue | 13 +++++++++++-- scripts/database.js | 5 ++--- scripts/vault.js | 19 +++++++++++++++++-- scripts/wallet.js | 10 +++++++--- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/scripts/composables/use_wallet.js b/scripts/composables/use_wallet.js index b179e72de..027c64351 100644 --- a/scripts/composables/use_wallet.js +++ b/scripts/composables/use_wallet.js @@ -322,6 +322,7 @@ function addVault(v) { wallets: wallets.value.map((w) => w.getKeyToExport()), isSeeded: v.isSeeded(), label: v.label, + createdBlock: v.createdBlock, }); for (const wallet of wallets.value) { await wallet.save(encWif); diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index 3959681ff..d98b6fe7d 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -107,7 +107,7 @@ async function importWallet({ secret, password = '', label, - blockCount = 4_200_000, + blockCount = cChainParams.current.defaultStartingShieldBlock, }) { try { /** @@ -166,6 +166,7 @@ async function importWallet({ masterKey: parsedSecret.masterKey, shield: parsedSecret.shield, seed: parsedSecret.seed, + createdBlock: blockCount, label: label?.trim() || parsedSecret.masterKey @@ -444,11 +445,19 @@ async function importFromDatabase() { createAlert('warning', 'Failed to load shield!', 3000); shield = pivxShield; } - ws.push(new Wallet({ nAccount: i++, masterKey, shield })); + ws.push( + new Wallet({ + nAccount: i++, + masterKey, + shield, + createdBlock: vault.createdBlock, + }) + ); } const v = new Vault({ wallets: ws, label: vault.label, + createdBlock: vault.createdBlock, }); await wallets.addVault(v); diff --git a/scripts/database.js b/scripts/database.js index dbf091c98..ae09fe082 100644 --- a/scripts/database.js +++ b/scripts/database.js @@ -20,9 +20,8 @@ export class Database { * Version 6 = Filter unconfirmed txs (#415) * Version 7 = Store shield params in indexed db (#511) * Version 8 = Multi MNs (#517) - * Version 9 = Store shield syncing data in indexed db (#543) - * Version 10 = Multi account system (#542) - + * Version 9 = Store shield syncing data in indexed db (#543) + * Version 10 = Multi account system (#542) * @type {number} */ static version = 10; diff --git a/scripts/vault.js b/scripts/vault.js index 391f383a2..a86bcb155 100644 --- a/scripts/vault.js +++ b/scripts/vault.js @@ -22,7 +22,21 @@ export class Vault { */ label; - constructor({ masterKey, shield, seed, wallets, label }) { + /** + * @type {number} Creation block of the vault. + * Defaults to `cChainParams::defaultStartingShieldBlock` if unknown + */ + createdBlock; + + constructor({ + masterKey, + shield, + seed, + wallets, + label, + createdBlock = cChainParams.current.defaultStartingShieldBlock, + }) { + this.createdBlock = createdBlock; if (masterKey) { this.#wallets.push( new Wallet({ @@ -69,12 +83,13 @@ export class Vault { seed: this.#seed, // hardcoded value considering the last checkpoint, this is good both for mainnet and testnet // TODO: take the wallet creation height in input from users - blockHeight: 4200000, + blockHeight: this.createdBlock, coinType: cChainParams.current.BIP44_TYPE, // TODO: Change account index once account system is made accountIndex: account, loadSaplingData: false, }), + createdBlock: this.createdBlock, }); this.#wallets[account] = wallet; return wallet; diff --git a/scripts/wallet.js b/scripts/wallet.js index 2764ac09e..fbce18ebd 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -142,12 +142,17 @@ export class Wallet { return hTx1.blockHeight >= hTx2.blockHeight; }); + createdBlock; + constructor({ nAccount = 0, masterKey, shield, mempool = new Mempool(), + createdBlock = cChainParams.current.defaultStartingShieldBlock, } = {}) { + this.createdBlock = createdBlock; + this.#nAccount = nAccount; this.#mempool = mempool; this.#mempool.setEmitter(() => { @@ -1057,7 +1062,7 @@ export class Wallet { await this.#shield.getSaplingRoot() ); // If explorer sapling root is different from ours, there must be a sync error - if (saplingRoot !== networkSaplingRoot) { + if (saplingRoot === networkSaplingRoot) { const db = await Database.getInstance(); // Reset shield sync data, it might be corrupted @@ -1121,8 +1126,7 @@ export class Wallet { } async #resetShield() { - // TODO: take the wallet creation height in input from users - await this.#shield.reloadFromCheckpoint(4_200_000); + await this.#shield.reloadFromCheckpoint(this.createdBlock); await this.#saveShieldOnDisk(); } From 2f855db0aa295326d37a00370b2ad85414d5e991 Mon Sep 17 00:00:00 2001 From: Duddino Date: Thu, 10 Jul 2025 09:50:18 +0200 Subject: [PATCH 2/3] Remove test check --- scripts/wallet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/wallet.js b/scripts/wallet.js index fbce18ebd..876a5c57b 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -1062,7 +1062,7 @@ export class Wallet { await this.#shield.getSaplingRoot() ); // If explorer sapling root is different from ours, there must be a sync error - if (saplingRoot === networkSaplingRoot) { + if (saplingRoot !== networkSaplingRoot) { const db = await Database.getInstance(); // Reset shield sync data, it might be corrupted From 3378bdf7a06462f59b0280d4290dac68bda24e88 Mon Sep 17 00:00:00 2001 From: Duddino Date: Mon, 18 Aug 2025 14:40:40 +0200 Subject: [PATCH 3/3] Add default starting shield block --- scripts/dashboard/Dashboard.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index d98b6fe7d..4350fc9bf 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -450,14 +450,18 @@ async function importFromDatabase() { nAccount: i++, masterKey, shield, - createdBlock: vault.createdBlock, + createdBlock: + vault.createdBlock || + cChainParams.current.defaultStartingShieldBlock, }) ); } const v = new Vault({ wallets: ws, label: vault.label, - createdBlock: vault.createdBlock, + createdBlock: + vault.createdBlock || + cChainParams.current.defaultStartingShieldBlock, }); await wallets.addVault(v);