Skip to content

Commit

Permalink
Use local instead of all addrs for mn
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 committed Mar 29, 2023
1 parent 7c90e4d commit a11ecff
Showing 1 changed file with 16 additions and 35 deletions.
51 changes: 16 additions & 35 deletions scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { masterKey, getDerivationPath, getNewAddress } from './wallet.js';
import { cChainParams, COIN } from './chain_params.js';
import { createAlert } from './misc.js';
import { Mempool } from './mempool.js';
import { Masternode, getFullData } from './masternode.js';
export let networkEnabled = true;
export let cachedBlockCount = 0;
export let arrRewards = [];
Expand Down Expand Up @@ -291,7 +292,11 @@ export async function getStakingRewards() {
}

export async function getMasternodeRewards() {
if (!networkEnabled || masterKey == undefined) return;
const cMasternode = new Masternode(
JSON.parse(localStorage.getItem('masternode'))
);
const cMasternodeData = await cMasternode.getFullData();
if (!networkEnabled || cMasternodeData == undefined) return;
doms.domGuiMasternodeLoadMoreIcon.style.opacity = 0.5;
const stopAnim = () => (doms.domGuiMasternodeLoadMoreIcon.style.opacity = 1);
const nHeight = masternodeRewards.length
Expand All @@ -309,40 +314,16 @@ export async function getMasternodeRewards() {
: 0),
0
);
let cData;
if (masterKey.isHD) {
const derivationPath = getDerivationPath(masterKey.isHardwareWallet)
.split('/')
.slice(0, 4)
.join('/');
const xpub = await masterKey.getxpub(derivationPath);
cData = await (
await fetch(
`${
cExplorer.url
}/api/v2/xpub/${xpub}?details=txs&pageSize=500&to=${
nHeight ? nHeight - 1 : 0
}`
)
).json();
// Map all address <--> derivation paths
if (cData.tokens)
cData.tokens.forEach((cAddrPath) =>
mapPaths.set(cAddrPath.name, cAddrPath.path)
);
} else {
const address = await masterKey.getAddress();
cData = await (
await fetch(
`${
cExplorer.url
}/api/v2/address/${address}?details=txs&pageSize=500&to=${
nHeight ? nHeight - 1 : 0
}`
)
).json();
mapPaths.set(address, ':)');
}
let cData = await (
await fetch(
`${
cExplorer.url
}/api/v2/address/${cMasternodeData.addr}?details=txs&pageSize=500&to=${
nHeight ? nHeight - 1 : 0
}`
)
).json();
mapPaths.set(cMasternodeData.addr, ':)');
if (cData && cData.transactions) {
// Update rewards
masternodeRewards = masternodeRewards.concat(
Expand Down

0 comments on commit a11ecff

Please sign in to comment.