Skip to content

Commit

Permalink
Wallet speed up + remove some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Oct 12, 2023
1 parent 2b1fe20 commit 017dcf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
7 changes: 4 additions & 3 deletions scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export class ExplorerNetwork extends Network {
this.blocks
);
this.blocks = backend.blocks;
console.log('sync:', this.lastBlockSynced, this.fullSynced);
if (this.fullSynced) {
await this.getLatestTxs(this.lastBlockSynced);
this.lastBlockSynced = this.blocks;
Expand Down Expand Up @@ -206,6 +205,7 @@ export class ExplorerNetwork extends Network {
this.lastWallet
)
: this.lastWallet;
await this.wallet.loadAddresses();
for (const tx of iPage.transactions.reverse()) {
await mempool.updateMempool(mempool.parseTransaction(tx));
}
Expand All @@ -216,6 +216,7 @@ export class ExplorerNetwork extends Network {
this.lastWallet
)
: this.lastWallet;
await this.wallet.loadAddresses();
if (firstPage.transactions) {
for (const tx of firstPage.transactions.reverse()) {
await mempool.updateMempool(mempool.parseTransaction(tx));
Expand All @@ -233,8 +234,8 @@ export class ExplorerNetwork extends Network {
this.lastBlockSynced =
nBlockHeights.length == 0 ? 0 : nBlockHeights.sort().at(-1);
this.fullSynced = true;
activityDashboard.update(10);
stakingDashboard.update(10);
await activityDashboard.update(50);
await stakingDashboard.update(50);
}

/**
Expand Down
30 changes: 12 additions & 18 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,33 +246,27 @@ export class Wallet {
return this.#masterKey?.isHardwareWallet === true;
}

/**
* @param {string} address - address to check
* @return {string?} BIP32 path or null if it's not your address
*/
isOwnAddress(address) {
if (this.#ownAddresses.has(address)) {
return this.#ownAddresses.get(address);
}
async loadAddresses() {
const last = getNetwork().lastWallet;
this.#addressIndex =
this.#addressIndex > last ? this.#addressIndex : last;
if (this.isHD()) {
for (let i = 0; i <= this.#addressIndex + MAX_ACCOUNT_GAP; i++) {
const path = this.getDerivationPath(0, i);
const testAddress = this.#masterKey.getAddress(path);
if (address === testAddress) {
this.#ownAddresses.set(address, path);
return path;
}
const address = await this.#masterKey.getAddress(path);
this.#ownAddresses.set(address, path);
}
} else {
const value = address === this.getKeyToExport() ? ':)' : null;
this.#ownAddresses.set(address, value);
return value;
this.#ownAddresses.set(await this.getKeyToExport(), ':)');
}
this.#ownAddresses.set(address, null);
return null;
}

/**
* @param {string} address - address to check
* @return {Promise<String?>} BIP32 path or null if it's not your address
*/
async isOwnAddress(address) {
return this.#ownAddresses.get(address) ?? null;
}

/**
Expand Down

0 comments on commit 017dcf9

Please sign in to comment.