diff --git a/scripts/composables/use_wallet.js b/scripts/composables/use_wallet.js index 166a2db75..5866df4a8 100644 --- a/scripts/composables/use_wallet.js +++ b/scripts/composables/use_wallet.js @@ -311,6 +311,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 f1bae6356..fbfd140a7 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -113,7 +113,7 @@ async function importWallet({ secret, password = '', label, - blockCount = 4_200_000, + blockCount = cChainParams.current.defaultStartingShieldBlock, }) { try { /** @@ -172,6 +172,7 @@ async function importWallet({ masterKey: parsedSecret.masterKey, shield: parsedSecret.shield, seed: parsedSecret.seed, + createdBlock: blockCount, label: label?.trim(), }), parsedSecret.masterKey.getKeyToExport(0).substring(0, 8) @@ -446,11 +447,23 @@ 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 || + cChainParams.current.defaultStartingShieldBlock, + }) + ); } const v = new Vault({ wallets: ws, label: vault.label, + createdBlock: + vault.createdBlock || + cChainParams.current.defaultStartingShieldBlock, }); await wallets.addVault(v); 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 4f468c597..a9cec3fa6 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -143,12 +143,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(() => { @@ -1140,8 +1145,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(); }