Skip to content

Commit

Permalink
Merge pull request #205 from VerusCoin/dev
Browse files Browse the repository at this point in the history
v1.0.12-4
  • Loading branch information
Asherda authored Jul 11, 2023
2 parents 15157ae + d8175c4 commit 4e09acb
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 167 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ stages:
variables:
DOCKER_DRIVER: overlay2
DEFAULT_VERUSCOIN_BRANCH: release
VERUS_VERSION: 1.0.12-2
VERUSCOIN_VERSION: 1.0.12-2
VERUS_VERSION: 1.0.12-4
VERUSCOIN_VERSION: 1.0.12-4
KOMODO_VERSION: 0.8.0
KOMODO_DOWNLOAD_URL: https://github.com/KomodoPlatform/komodo/releases/download
PIRATE_VERSION: 5.7.4
Expand Down
2 changes: 1 addition & 1 deletion gui/Verus-Desktop-GUI
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "verus-desktop",
"productName": "Verus-Desktop",
"version": "1.0.12-2",
"version": "1.0.12-4",
"description": "Verus Desktop Wallet App",
"main": "main.js",
"scripts": {
Expand Down
31 changes: 2 additions & 29 deletions routes/api/electrum/balances.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { checkTimestamp } = require('agama-wallet-lib/src/time');
const { pubToElectrumScriptHashHex } = require('agama-wallet-lib/src/keys');
const btcnetworks = require('agama-wallet-lib/src/bitcoinjs-networks');
const { toSats } = require('agama-wallet-lib/src/utils');
const kmdCalcInterest = require('agama-wallet-lib/src/komodo-interest');
const UTXO_1MONTH_THRESHOLD_SECONDS = 2592000;

module.exports = (api) => {
Expand Down Expand Up @@ -64,8 +62,6 @@ module.exports = (api) => {
let ecl;
let _address = address;

api.log("electrum getbalance =>", "spv.getbalance");

ecl = await api.ecl(network);
_address =
ecl.protocolVersion && ecl.protocolVersion === "1.4"
Expand All @@ -89,23 +85,13 @@ module.exports = (api) => {
let utxoIssues = false;

for (let i = 0; i < utxoList.length; i++) {
api.log(
`utxo ${utxoList[i].tx_hash} sats ${utxoList[i].value} value ${
Number(utxoList[i].value) * 0.00000001
}`,
"spv.getbalance"
);

if (Number(utxoList[i].value) * 0.00000001 >= 10) {
_utxo.push(utxoList[i]);
} else {
utxoIssues = true;
}
}

api.log("filtered utxo list =>", "spv.getbalance");
api.log(_utxo, "spv.getbalance");

if (_utxo && _utxo.length) {
let interestTotal = 0;

Expand All @@ -132,12 +118,6 @@ module.exports = (api) => {
api
.getTransaction(_utxoItem.tx_hash, network, ecl)
.then((_rawtxJSON) => {
api.log("electrum gettransaction ==>", "spv.getbalance");
api.log(
`${index} | ${_rawtxJSON.length - 1}`,
"spv.getbalance"
);
api.log(_rawtxJSON, "spv.getbalance");

// decode tx
const _network = api.getNetworkData(network);
Expand Down Expand Up @@ -166,11 +146,10 @@ module.exports = (api) => {
decodedTx.format &&
decodedTx.format.locktime > 0
) {
interestTotal += kmdCalcInterest(
interestTotal += api.kmdCalcInterest(
decodedTx.format.locktime,
_utxoItem.value,
_utxoItem.height,
true
_utxoItem.height
);

const _locktimeSec = checkTimestamp(
Expand All @@ -192,9 +171,6 @@ module.exports = (api) => {
);
}

api.log("decoded tx =>", "spv.getbalance");
api.log(decodedTx, "spv.getbalance");

resolve(true);
});
});
Expand Down Expand Up @@ -228,9 +204,6 @@ module.exports = (api) => {
})
.catch((e) => reject(e));
} else {
api.log("electrum getbalance ==>", "spv.getbalance");
api.log(json, "spv.getbalance");

resolve({
confirmed: Number((0.00000001 * json.confirmed).toFixed(8)),
unconfirmed: Number((0.00000001 * json.unconfirmed).toFixed(8)),
Expand Down
3 changes: 0 additions & 3 deletions routes/api/electrum/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ module.exports = (api) => {
const ecl = await api.ecl(network);

ecl.blockchainHeadersSubscribe().then((json) => {
api.log("electrum currentblock (electrum >= v1.1) ==>", "spv.currentblock");
api.log(json, "spv.currentblock");

if (json && json.hasOwnProperty("block_height")) {
resolve(json.block_height);
} else if (json && json.hasOwnProperty("height")) {
Expand Down
39 changes: 3 additions & 36 deletions routes/api/electrum/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ module.exports = (api) => {
api.electrumCache.pendingTx &&
api.electrumCache.pendingTx[network] &&
api.electrumCache.pendingTx[network][txid]) {
api.log(`pending txs cache remove ${network} txid ${txid}`, 'spv.cache.pending');
delete api.electrumCache.pendingTx[network][txid];
delete api.electrumCache.pendingTx[network][txid];

if (!Object.keys(api.electrumCache.pendingTx[network]).length) {
delete api.electrumCache.pendingTx[network];
Expand All @@ -40,14 +39,8 @@ module.exports = (api) => {
pub: options.pub,
rawtx: options.rawtx,
};
api.log(`pending txs cache add ${network} txid ${txid} pub ${options.pub}`, 'spv.cache.pending');
} else {
api.log(`pending txs cache ${network} txid ${txid} already exists`, 'spv.cache.pending');
}
}
}

api.log('pending txs cache', 'spv.cache.pending');
api.log(api.electrumCache.pendingTx, 'spv.cache.pending');
};

api.findPendingTxByAddress = (network, pub) => {
Expand Down Expand Up @@ -89,17 +82,13 @@ module.exports = (api) => {
if (fs.existsSync(`${api.paths.agamaDir}/spv-cache.json`)) {
const localCache = fs.readFileSync(`${api.paths.agamaDir}/spv-cache.json`, 'utf8');

api.log('local spv cache loaded from local file', 'spv.cache');

try {
api.electrumCache = JSON.parse(localCache);
} catch (e) {
api.log('local spv cache file is damaged, create new', 'spv.cache');
api.saveLocalSPVCache();
api.electrumCache = {};
}
} else {
api.log('local spv cache file is not found, create new', 'spv.cache');
api.saveLocalSPVCache();
api.electrumCache = {};
}
Expand All @@ -117,7 +106,6 @@ module.exports = (api) => {
fsnode.chmodSync(spvCacheFileName, '0666');

setTimeout(() => {
api.log(result, 'spv.cache');
resolve(result);
}, 1000);
});
Expand All @@ -130,13 +118,9 @@ module.exports = (api) => {
const err = fs.writeFileSync(spvCacheFileName,
JSON.stringify(api.electrumCache), 'utf8');

if (err)
return api.log(err, 'spv.cache');

if (err) return null;
fsnode.chmodSync(spvCacheFileName, '0666');
setTimeout(() => {
api.log(result, 'spv.cache');
api.log(`spv-cache.json file is created successfully at: ${api.paths.agamaDir}`, 'spv.cache');
resolve(result);
}, 2000);
});
Expand All @@ -163,15 +147,11 @@ module.exports = (api) => {
const _pendingTxFromCache = api.findPendingTxRawById(network.toUpperCase(), txid);

if (_pendingTxFromCache) {
api.log(`${network} ${txid} get from pending txs cache`, 'spv.cache.transaction.pending');
resolve(_pendingTxFromCache);
} else {
api.log(`${network.toUpperCase()} dpow confs spv: ${api.dpowCoins.indexOf(network.toUpperCase()) > -1 ? true : false}`, 'spv.dpow.confs');

if (api.electrum.coinData[network.toLowerCase()].nspv) {
if (!api.electrumCache[network].tx[txid]) {
const nspvWrapper = api.nspvWrapper(network.toLowerCase());
api.log(`nspv raw input tx ${txid}`, 'spv.cache');

nspvWrapper.blockchainTransactionGet(txid, true)
.then((nspvGetTx) => {
Expand All @@ -180,24 +160,17 @@ module.exports = (api) => {
api.electrumCache[network].tx[txid] = nspvGetTx.hex;
resolve(api.electrumCache[network].tx[txid]);
} else {
api.log(`nspv unable to get raw input tx ${txid}`, 'spv.cache');
resolve();
}
});
} else {
api.log(`electrum cached raw input tx ${txid}`, 'spv.cache');
resolve(api.electrumCache[network].tx[txid]);
}
} else {
if (!api.electrumCache[network].tx[txid] ||
!api.electrumCache[network].verboseTx[txid] ||
(api.electrumCache[network].verboseTx[txid] && api.electrumCache[network].verboseTx[txid].hasOwnProperty('confirmations') && api.electrumCache[network].verboseTx[txid].hasOwnProperty('rawconfirmations') && api.electrumCache[network].verboseTx[txid].confirmations < 2) ||
(!api.electrumCache[network].verboseTx[txid].hasOwnProperty('confirmations') || !api.electrumCache[network].verboseTx[txid].hasOwnProperty('rawconfirmations'))) {
api.log(`electrum raw input tx ${txid}`, 'spv.cache');

if (api.dpowCoins.indexOf(network.toUpperCase()) > -1) {
api.log(`${network.toUpperCase()} request dpow data update`, 'spv.dpow.confs');
}

ecl.blockchainTransactionGet(txid, api.dpowCoins.indexOf(network.toUpperCase()) > -1 ? true : false)
.then((_rawtxJSON) => {
Expand All @@ -211,7 +184,6 @@ module.exports = (api) => {
resolve(api.electrumCache[network].tx[txid]);
});
} else {
api.log(`electrum cached raw input tx ${txid}`, 'spv.cache');
resolve(api.electrumCache[network].tx[txid]);
}
}
Expand All @@ -225,7 +197,6 @@ module.exports = (api) => {
}

if (api.electrumCache[network].txDecoded[txid]) {
api.log(`electrum raw input tx decoded ${txid}`, 'spv.cache');
return api.electrumCache[network].txDecoded[txid];
} else {
if (data) {
Expand All @@ -239,7 +210,6 @@ module.exports = (api) => {
api.getBlockHeader = (height, network, ecl) => {
return new Promise((resolve, reject) => {
if (height === 'pending') {
api.log(`electrum raw block ${height} use current time`, 'spv.cache.pending');
resolve({
timestamp: Math.floor(Date.now() / 1000),
});
Expand All @@ -255,8 +225,6 @@ module.exports = (api) => {
!api.electrumCache[network].blockHeader[height] ||
!Object.keys(api.electrumCache[network].blockHeader[height]).length
) {
api.log(`electrum raw block ${height}`, "spv.cache");

ecl.blockchainBlockGetHeader(height).then((_rawtxJSON) => {
if (typeof _rawtxJSON === "string") {
_rawtxJSON = parseBlock(_rawtxJSON, btcnetworks[network] || btcnetworks.kmd);
Expand All @@ -266,7 +234,6 @@ module.exports = (api) => {
}
}
api.electrumCache[network].blockHeader[height] = _rawtxJSON;
// api.log(api.electrumCache[network].blockHeader[height], 'spv.cache');
resolve(_rawtxJSON);
});
} else {
Expand Down
11 changes: 1 addition & 10 deletions routes/api/electrum/coins.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ module.exports = (api) => {
};

// wait for spv connection to be established
const ecl = await api.ecl(coin);

if (randomServer) {
api.log(`random ${coin} electrum server ${randomServer.ip}:${randomServer.port}`, 'spv.coin');
} else {
api.log(`${coin} doesnt have any backup electrum servers`, 'spv.coin');
}
await api.ecl(coin);

if (Object.keys(api.electrumKeys).length > 0) {
const _keys = api.wifToWif(
Expand Down Expand Up @@ -105,14 +99,11 @@ module.exports = (api) => {
for (let key in api.electrumJSNetworks) {
if (!api.electrumServers[key] ||
(api.electrumServers[key] && !api.electrumServers[key].serverList)) {
//api.log(`disable ${key}, coin config check not passed`, 'spv.coin');
delete api.electrumServers[key];
} else {
_totalCoins++;
}
}

api.log(`total supported spv coins ${_totalCoins}`, 'spv.coin');
};

return api;
Expand Down
78 changes: 76 additions & 2 deletions routes/api/electrum/interest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
const kmdCalcInterest = require('agama-wallet-lib/src/komodo-interest');
/*
MIT License
Copyright (c) 2018 - 2019 Atomic Labs, Luke Childs
Copyright (c) 2019 - 2022 Komodo Platform
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

const KOMODO_ENDOFERA = 7777777;
const LOCKTIME_THRESHOLD = 500000000;
const MIN_SATOSHIS = 1000000000;
const ONE_MONTH_CAP_HARDFORK = 1000000;
const ONE_HOUR = 60;
const ONE_MONTH = 31 * 24 * 60;
const ONE_YEAR = 365 * 24 * 60;
const DEVISOR = 10512000;
const N_S7_HARDFORK_HEIGHT = 3484958;

module.exports = (api) => {
api.kmdCalcInterest = kmdCalcInterest;
api.kmdCalcInterest = (locktime, value, height) => {
const tiptime = Math.floor(Date.now() / 1000) - 777;
const satoshis = value;

// Calculate coinage
const coinage = Math.floor((tiptime - locktime) / ONE_HOUR);

// Return early if UTXO is not eligible for rewards
if (
(height >= KOMODO_ENDOFERA) ||
(locktime < LOCKTIME_THRESHOLD) ||
(satoshis < MIN_SATOSHIS) ||
(coinage < ONE_HOUR) ||
(!height)
) {
return 0;
}

// Cap reward periods
const limit = (height >= ONE_MONTH_CAP_HARDFORK) ? ONE_MONTH : ONE_YEAR;
let rewardPeriod = Math.min(coinage, limit);

// The first hour of coinage should not accrue rewards
rewardPeriod -= 59;

// Calculate rewards
let rewards = Math.floor(satoshis / DEVISOR) * rewardPeriod;

// Vote-KIP0001 resulted in a reduction of the AUR from 5% to 0.01%
// https://github.com/KomodoPlatform/kips/blob/main/kip-0001.mediawiki
// https://github.com/KomodoPlatform/komodo/pull/584
if (height >= N_S7_HARDFORK_HEIGHT) {
rewards = Math.floor(rewards / 500);
}

// Ensure reward value is never negative
if (rewards < 0) {
throw new Error('Reward should never be negative');
}

return rewards;
};

return api;
};
Loading

0 comments on commit 4e09acb

Please sign in to comment.