Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
vaults as rawVaults,
Wallet,
} from '../wallet.js';
import { ref, computed, watch, reactive } from 'vue';

Check warning on line 9 in scripts/composables/use_wallet.js

View workflow job for this annotation

GitHub Actions / Run linters

'watch' is defined but never used
import { fPublicMode, strCurrency } from '../settings.js';
import { cOracle } from '../prices.js';
import { LedgerController } from '../ledger.js';
Expand Down Expand Up @@ -311,6 +311,7 @@
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);
Expand Down
17 changes: 15 additions & 2 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function importWallet({
secret,
password = '',
label,
blockCount = 4_200_000,
blockCount = cChainParams.current.defaultStartingShieldBlock,
}) {
try {
/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions scripts/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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();
}

Expand Down