// default=false env vars [ "BTCEXP_DEMO", "BTCEXP_PRIVACY_MODE", "BTCEXP_NO_INMEMORY_RPC_CACHE", "BTCEXP_RPC_ALLOWALL" ].forEach(function(item) { if (process.env[item] === undefined) { process.env[item] = "false"; debugLog(`Config(default): ${item}=false`) } });
router.get("/disconnect", function(req, res, next) { res.cookie('rpc-host', ""); res.cookie('rpc-port', ""); res.cookie('rpc-username', ""); req.session.host = ""; req.session.port = ""; req.session.username = ""; debugLog("destroyed rpc client."); global.rpcClient = null; req.session.userMessage = "Disconnected from node."; req.session.userMessageType = "success"; res.redirect("/"); });
simpleGit(".").log(["-n 1"], function(err, log) { if (err) { utils.logError("3fehge9ee", err, {desc:"Error accessing git repo"}); debugLog(`Starting ${global.coinConfig.ticker} RPC Explorer, v${global.appVersion} (code: unknown commit)`); } else { global.sourcecodeVersion = log.all[0].hash.substring(0, 10); global.sourcecodeDate = log.all[0].date.substring(0, "0000-00-00".length); debugLog(`Starting ${global.coinConfig.ticker} RPC Explorer, v${global.appVersion} (commit: '${global.sourcecodeVersion}', date: ${global.sourcecodeDate})`); } app.continueStartup(); });
Object.keys(args).filter(k => k.length > 1).forEach(k => { if (args[k] === false) { debugLog(`Config(arg): BTCEXP_NO_${envify(k)}=true`); process.env[`BTCEXP_NO_${envify(k)}`] = true; } else { debugLog(`Config(arg): BTCEXP_${envify(k)}=${args[k]}`); process.env[`BTCEXP_${envify(k)}`] = args[k]; } });
process.on("unhandledRejection", (reason, p) => { debugLog("Unhandled Rejection at: Promise", p, "reason:", reason, "stack:", (reason != null ? reason.stack : "null")); });
function getUtxo(txid, outputIndex) { debugLog("getUtxo: %s (%d)", txid, outputIndex); return new Promise(function(resolve, reject) { getRpcDataWithParams({method:"gettxout", parameters:[txid, outputIndex]}).then(function(result) { if (result == null) { resolve("0"); return; } if (result.code && result.code < 0) { reject(result); return; } resolve(result); }).catch(function(err) { reject(err); }); }); }
function refreshExchangeRates() { if (!config.queryExchangeRates || config.privacyMode) { return; } if (coins[config.coin].exchangeRateData) { request(coins[config.coin].exchangeRateData.jsonUrl, function(error, response, body) { if (error == null && response && response.statusCode && response.statusCode == 200) { var responseBody = JSON.parse(body); var exchangeRates = coins[config.coin].exchangeRateData.responseBodySelectorFunction(responseBody); if (exchangeRates != null) { global.exchangeRates = exchangeRates; global.exchangeRatesUpdateTime = new Date(); debugLog("Using exchange rates: " + JSON.stringify(global.exchangeRates) + " starting at " + global.exchangeRatesUpdateTime); } else { debugLog("Unable to get exchange rate data"); } } else { logError("39r7h2390fgewfgds", {error:error, response:response, body:body}); } }); } }
function loadHistoricalDataForChain(chain) { debugLog(`Loading historical data for chain=${chain}`); if (global.coinConfig.historicalData) { global.coinConfig.historicalData.forEach(function(item) { if (item.chain == chain) { if (item.type == "blockheight") { global.specialBlocks[item.blockHash] = item; } else if (item.type == "tx") { global.specialTransactions[item.txid] = item; } else if (item.type == "address") { global.specialAddresses[item.address] = {type:"fun", addressInfo:item}; } } }); } }
function refreshUtxoSetSummary() { if (config.slowDeviceMode) { global.utxoSetSummary = null; global.utxoSetSummaryPending = false; debugLog("Skipping performance-intensive task: fetch UTXO set summary. This is skipped due to the flag 'slowDeviceMode' which defaults to 'true' to protect slow nodes. Set this flag to 'false' to enjoy UTXO set summary details."); return; } // flag that we're working on calculating UTXO details (to differentiate cases where we don't have the details and we're not going to try computing them) global.utxoSetSummaryPending = true; coreApi.getUtxoSetSummary().then(function(result) { global.utxoSetSummary = result; result.lastUpdated = Date.now(); debugLog("Refreshed utxo summary: " + JSON.stringify(result)); }); }
function loadMiningPoolConfigs() { debugLog("Loading mining pools config");
}); debugLog("created new rpc client: " + newClient);
function verifyRpcConnection() { if (!global.activeBlockchain) { debugLog(`Verifying RPC connection...`); coreApi.getNetworkInfo().then(function(getnetworkinfo) { coreApi.getBlockchainInfo().then(function(getblockchaininfo) { global.activeBlockchain = getblockchaininfo.chain; // we've verified rpc connection, no need to keep trying clearInterval(global.verifyRpcConnectionIntervalId); onRpcConnectionVerified(getnetworkinfo, getblockchaininfo); }).catch(function(err) { utils.logError("329u0wsdgewg6ed", err); }); }).catch(function(err) { utils.logError("32ugegdfsde", err); }); } }
function getRawTransaction(txid) { debugLog("getRawTransaction: %s", txid);
function getBlockByHash(blockHash) { debugLog("getBlockByHash: %s", blockHash); return new Promise(function(resolve, reject) { getRpcDataWithParams({method:"getblock", parameters:[blockHash]}).then(function(block) { getRawTransaction(block.tx[0]).then(function(tx) { block.coinbaseTx = tx; block.totalFees = utils.getBlockTotalFeesFromCoinbaseTxAndBlockHeight(tx, block.height); block.subsidy = coinConfig.blockRewardFunction(block.height, global.activeBlockchain); block.miner = utils.getMinerFromCoinbaseTx(tx); resolve(block); }).catch(function(err) { reject(err); }); }).catch(function(err) { reject(err); }); }); }
// default=true env vars [ "BTCEXP_NO_RATES", "BTCEXP_UI_SHOW_TOOLS_SUBHEADER", "BTCEXP_SLOW_DEVICE_MODE" ].forEach(function(item) { if (process.env[item] === undefined) { process.env[item] = "true"; debugLog(`Config(default): ${item}=true`) } });