Skip to content

Commit

Permalink
Merge branch 'master' into cypress-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino authored Nov 5, 2024
2 parents 2ea915e + 4750196 commit d8e1f79
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-constant-condition": "off",
"@typescript-eslint/no-empty-function": "off",
"no-console": "error"
"no-console": "error",
"eqeqeq": ["error", "smart"]
}
}
2 changes: 1 addition & 1 deletion scripts/contacts-book.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function renderContacts(account, fPrompt = false) {

// Render an editable Contacts Table
strHTML += `<div class="shadowInnerCard${
account.contacts.length == 0 ? ' d-none' : ''
account.contacts.length === 0 ? ' d-none' : ''
}" style="font-family: 'Montserrat'; text-align: start; margin: 0px 15px; border-radius: 10px; border: 1px solid #42117e; background-color: #25183d; padding: 13px 9px;">
<div style="max-height: 270px; overflow: auto;">`;

Expand Down
2 changes: 1 addition & 1 deletion scripts/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class Database {
' to ' +
Database.version
);
if (oldVersion == 0) {
if (oldVersion === 0) {
db.createObjectStore('masternodes');
db.createObjectStore('accounts');
db.createObjectStore('settings');
Expand Down
10 changes: 5 additions & 5 deletions scripts/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { bech32 } from 'bech32';
* @returns {Array<Number>} The compressed public key bytes
*/
export function compressPublicKey(pubKeyBytes) {
if (pubKeyBytes.length != 65)
if (pubKeyBytes.length !== 65)
throw new Error('Attempting to compress an invalid uncompressed key');
const x = pubKeyBytes.slice(1, 33);
const y = pubKeyBytes.slice(33);
Expand Down Expand Up @@ -94,7 +94,7 @@ export function deriveAddress({ pkBytes, publicKey, output = 'ENCODED' }) {
pubKeyBytes = compressPublicKey(pubKeyBytes);
}

if (pubKeyBytes.length != 33) {
if (pubKeyBytes.length !== 33) {
throw new Error('Invalid public key');
}

Expand Down Expand Up @@ -244,9 +244,9 @@ export function parseWIF(strWIF, skipVerification = false) {
* @returns {number[]} - Encoded numbers
*/
export function numToBytes(num, bytes = 8) {
if (bytes == 0) {
if (bytes === 0) {
return [];
} else if (num == -1n) {
} else if (num === -1n) {
return hexToBytes('ffffffffffffffff');
} else {
return [Number(num % 256n)].concat(numToBytes(num / 256n, bytes - 1));
Expand All @@ -270,7 +270,7 @@ export function numToByteArray(num) {
* @returns {BigInt} converted number from bytes
*/
export function bytesToNum(bytes) {
if (bytes.length == 0) return 0n;
if (bytes.length === 0) return 0n;
else return BigInt(bytes[0]) + 256n * bytesToNum(bytes.slice(1));
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/flipdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ export class FlipDown {

function rotorTopFlip() {
this.rotorTop.forEach((el, i) => {
if (el.textContent != this.clockValuesAsString[i]) {
if (el.textContent !== this.clockValuesAsString[i]) {
el.textContent = this.clockValuesAsString[i];
}
});
}

function rotorLeafRearFlip() {
this.rotorLeafRear.forEach((el, i) => {
if (el.textContent != this.clockValuesAsString[i]) {
if (el.textContent !== this.clockValuesAsString[i]) {
el.textContent = this.clockValuesAsString[i];
el.parentElement.classList.add('flipped');
var flip = setInterval(
Expand Down
10 changes: 5 additions & 5 deletions scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export async function govVote(hash, voteCode) {
(await confirmPopup({
title: ALERTS.CONFIRM_POPUP_VOTE,
html: ALERTS.CONFIRM_POPUP_VOTE_HTML,
})) == true
})) === true
) {
const database = await Database.getInstance();
const cMasternode = await database.getMasternode();
Expand Down Expand Up @@ -769,7 +769,7 @@ export async function updateGovernanceTab() {
fRenderingGovernance = true;

// Setup the Superblock countdown (if not already done), no need to block thread with await, either.
if (!isTestnetLastState == cChainParams.current.isTestnet) {
if (isTestnetLastState !== cChainParams.current.isTestnet) {
// Reset flipdown
governanceFlipdown = null;
doms.domFlipdown.innerHTML = '';
Expand Down Expand Up @@ -1004,7 +1004,7 @@ async function renderProposals(arrProposals, fContested) {
}

// Add border radius to last row
if (arrProposals.length - 1 == i) {
if (arrProposals.length - 1 === i) {
domStatus.classList.add('bblr-7p');
}

Expand Down Expand Up @@ -1254,7 +1254,7 @@ async function renderProposals(arrProposals, fContested) {
domYesBtn.onclick = () => govVote(cProposal.Hash, 1);

// Add border radius to last row
if (arrProposals.length - 1 == i) {
if (arrProposals.length - 1 === i) {
domVoteBtns.classList.add('bbrr-7p');
}

Expand Down Expand Up @@ -1753,7 +1753,7 @@ export function switchSettings(page) {

Object.values(SETTINGS).forEach(({ section, btn }) => {
// Set the slider to the proper location
if (page == 'display') {
if (page === 'display') {
doms.domDisplayDecimalsSlider.oninput = function () {
doms.domDisplayDecimalsSliderDisplay.innerHTML = this.value;
//let val = ((((doms.domDisplayDecimalsSlider.offsetWidth - 24) / 9) ) * parseInt(this.value));
Expand Down
2 changes: 1 addition & 1 deletion scripts/masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export default class Masternode {
true
);

if (/^"[a-f0-9]"$/ && res.length == 64 + 2) {
if (/^"[a-f0-9]"$/ && res.length === 64 + 2) {
return { ok: true, hash: res };
} else if (
res.includes('is unconfirmed') ||
Expand Down
2 changes: 1 addition & 1 deletion scripts/mempool.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class CachableBalance {
value = -1;

isValid() {
return this.value != -1;
return this.value !== -1;
}
invalidate() {
this.value = -1;
Expand Down
2 changes: 1 addition & 1 deletion scripts/network/__mocks__/network_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TestBlock {
*/
addTransaction(txHex, blockHeight) {
// Sanity check
if (blockHeight != this.blockHeight) {
if (blockHeight !== this.blockHeight) {
throw new Error('Transaction and block have a different height!');
}
this.txs.push(new TestTransaction(txHex, blockHeight));
Expand Down
4 changes: 2 additions & 2 deletions scripts/network/network_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class NetworkManager {
let attemptNet = isRPC ? this.#currentNode : this.#currentExplorer;

let i = this.#networks.findIndex((net) => attemptNet === net);
if (i == -1) {
if (i === -1) {
debugWarn(DebugTopics.NET, 'Cannot find index in networks array');
i = 0;
}
Expand All @@ -90,7 +90,7 @@ class NetworkManager {
attemptNet.strUrl + ' failed on ' + funcName
);
// If allowed, switch instances
if (!fAutoSwitch || attempts == nMaxTries) {
if (!fAutoSwitch || attempts === nMaxTries) {
throw error;
}
attemptNet = this.#networks[(i + attempts) % nMaxTries];
Expand Down
52 changes: 26 additions & 26 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ export function getScriptForBurn(data) {
export function isP2PKH(dataBytes) {
return (
dataBytes.length >= 25 &&
dataBytes[0] == OP['DUP'] &&
dataBytes[1] == OP['HASH160'] &&
dataBytes[2] == 0x14 &&
dataBytes[23] == OP['EQUALVERIFY'] &&
dataBytes[24] == OP['CHECKSIG']
dataBytes[0] === OP['DUP'] &&
dataBytes[1] === OP['HASH160'] &&
dataBytes[2] === 0x14 &&
dataBytes[23] === OP['EQUALVERIFY'] &&
dataBytes[24] === OP['CHECKSIG']
);
}

Expand All @@ -197,18 +197,18 @@ export function isP2PKH(dataBytes) {
export function isP2CS(dataBytes) {
return (
dataBytes.length >= 51 &&
dataBytes[0] == OP['DUP'] &&
dataBytes[1] == OP['HASH160'] &&
dataBytes[2] == OP['ROT'] &&
dataBytes[3] == OP['IF'] &&
(dataBytes[4] == OP['CHECKCOLDSTAKEVERIFY'] ||
dataBytes[4] == OP['CHECKCOLDSTAKEVERIFY_LOF']) &&
dataBytes[5] == 0x14 &&
dataBytes[26] == OP['ELSE'] &&
dataBytes[27] == 0x14 &&
dataBytes[48] == OP['ENDIF'] &&
dataBytes[49] == OP['EQUALVERIFY'] &&
dataBytes[50] == OP['CHECKSIG']
dataBytes[0] === OP['DUP'] &&
dataBytes[1] === OP['HASH160'] &&
dataBytes[2] === OP['ROT'] &&
dataBytes[3] === OP['IF'] &&
(dataBytes[4] === OP['CHECKCOLDSTAKEVERIFY'] ||
dataBytes[4] === OP['CHECKCOLDSTAKEVERIFY_LOF']) &&
dataBytes[5] === 0x14 &&
dataBytes[26] === OP['ELSE'] &&
dataBytes[27] === 0x14 &&
dataBytes[48] === OP['ENDIF'] &&
dataBytes[49] === OP['EQUALVERIFY'] &&
dataBytes[50] === OP['CHECKSIG']
);
}

Expand All @@ -219,12 +219,12 @@ export function isP2CS(dataBytes) {
export function isP2EXC(dataBytes) {
return (
dataBytes.length >= 26 &&
dataBytes[0] == OP['EXCHANGEADDR'] &&
dataBytes[1] == OP['DUP'] &&
dataBytes[2] == OP['HASH160'] &&
dataBytes[3] == 0x14 &&
dataBytes[24] == OP['EQUALVERIFY'] &&
dataBytes[25] == OP['CHECKSIG']
dataBytes[0] === OP['EXCHANGEADDR'] &&
dataBytes[1] === OP['DUP'] &&
dataBytes[2] === OP['HASH160'] &&
dataBytes[3] === 0x14 &&
dataBytes[24] === OP['EQUALVERIFY'] &&
dataBytes[25] === OP['CHECKSIG']
);
}

Expand All @@ -234,9 +234,9 @@ export function isP2EXC(dataBytes) {
*/
export function isProposalFee(dataBytes) {
return (
dataBytes.length == 34 &&
dataBytes[0] == OP['RETURN'] &&
dataBytes[1] == 32
dataBytes.length === 34 &&
dataBytes[0] === OP['RETURN'] &&
dataBytes[1] === 32
);
}
/**
Expand Down
8 changes: 4 additions & 4 deletions scripts/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class CTxOut {
}

isEmpty() {
return this.value == 0 && (this.script === 'f8' || this.script === '');
return this.value === 0 && (this.script === 'f8' || this.script === '');
}

serialize() {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class Transaction {
}

isConfirmed() {
return this.blockHeight != -1;
return this.blockHeight !== -1;
}

isCoinStake() {
Expand All @@ -166,7 +166,7 @@ export class Transaction {
isCoinBase() {
// txid is full of 0s for coinbase inputs
return (
this.vin.length == 1 && !!this.vin[0].outpoint.txid.match(/^0*$/)
this.vin.length === 1 && !!this.vin[0].outpoint.txid.match(/^0*$/)
);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ export class Transaction {
const copy = structuredClone(this.__original);
// Black out all inputs
for (let i = 0; i < copy.vin.length; i++) {
if (i != index) copy.vin[i].scriptSig = '';
if (i !== index) copy.vin[i].scriptSig = '';
}
return bytesToHex(
dSHA256([
Expand Down
4 changes: 2 additions & 2 deletions scripts/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class TransactionBuilder {
const front = bytes.slice(0, bytes.length - 4);
const back = bytes.slice(bytes.length - 4);
const checksum = dSHA256(front).slice(0, 4);
if (checksum + '' == back + '') {
if (checksum + '' === back + '') {
return Array.from(front.slice(isExchangeAddress(address) ? 3 : 1));
}
throw new Error('Invalid address');
Expand Down Expand Up @@ -271,7 +271,7 @@ export class TransactionBuilder {
const tx = this.#transaction;
let first = true;
const outputs = tx.vout.length;
if (!outputs || outputs == 0) {
if (!outputs || outputs === 0) {
throw new Error('tx has no outputs!');
}
for (let vout of tx.vout) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function startBatch(
batchSize,
retryTime = 10000
) {
if (length == 0) {
if (length === 0) {
return;
}
return new Promise((res) => {
Expand Down
15 changes: 8 additions & 7 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class Wallet {
} else if (isP2CS(dataBytes)) {
const addresses = [];
for (let i = 0; i < 2; i++) {
const iStart = i == 0 ? OWNER_START_INDEX : COLD_START_INDEX;
const iStart = i === 0 ? OWNER_START_INDEX : COLD_START_INDEX;
addresses.push(
this.getAddressFromHashCache(
bytesToHex(dataBytes.slice(iStart, iStart + 20)),
Expand Down Expand Up @@ -710,6 +710,9 @@ export class Wallet {
await this.#syncShield();
}
this.#isSynced = true;
// At this point download the last missing blocks in the range (blockCount -5, blockCount]
await this.getLatestBlocks(blockCount);

// Update both activities post sync
getEventEmitter().enableEvent('balance-update');
getEventEmitter().emit('balance-update');
Expand Down Expand Up @@ -774,7 +777,7 @@ export class Wallet {
handled++;
await this.#shield.handleBlock(blocks[j]);
// Backup every 500 handled blocks
if (handled % 500 == 0) await this.saveShieldOnDisk();
if (handled % 500 === 0) await this.saveShieldOnDisk();
// Delete so we don't have to hold all blocks in memory
// until we finish syncing
delete blocks[j];
Expand Down Expand Up @@ -836,9 +839,9 @@ export class Wallet {
subscribeToNetworkEvents() {
getEventEmitter().on('new-block', async (block) => {
if (this.#isSynced) {
await this.getLatestBlocks(block);
// Invalidate the balance cache to keep immature balance updated
this.#mempool.invalidateBalanceCache();
await this.getLatestBlocks(block);
getEventEmitter().emit('new-tx');
}
});
Expand All @@ -851,11 +854,9 @@ export class Wallet {
async (blockCount) => {
const cNet = getNetwork();
let block;
// Don't ask for the exact last block that arrived,
// since it takes around 1 minute for blockbook to make it API available
for (
let blockHeight = this.#lastProcessedBlock + 1;
blockHeight < blockCount;
blockHeight <= blockCount;
blockHeight++
) {
try {
Expand Down Expand Up @@ -940,7 +941,7 @@ export class Wallet {
const cDB = await Database.getInstance();
const cAccount = await cDB.getAccount();
// If the account has not been created yet or there is no shield data return
if (!cAccount || cAccount.shieldData == '') {
if (!cAccount || cAccount.shieldData === '') {
return;
}
this.#shield = await PIVXShield.load(cAccount.shieldData);
Expand Down
Loading

0 comments on commit d8e1f79

Please sign in to comment.