Browse Source

support for multiple mining-pool configs of the same format

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
68bcb91ab4
  1. 39
      app.js
  2. 5
      app/coins/btc.js
  3. 4
      app/coins/ltc.js
  4. 36
      app/utils.js
  5. 6
      routes/baseActionsRouter.js
  6. 14
      views/address.pug
  7. 4
      views/includes/block-content.pug

39
app.js

@ -120,20 +120,33 @@ app.runOnStartup = function() {
});
}
if (global.coinConfig.miningPoolsConfigUrl) {
request(global.coinConfig.miningPoolsConfigUrl, function(error, response, body) {
if (!error && response && response.statusCode && response.statusCode == 200) {
var responseBody = JSON.parse(body);
global.miningPoolsConfig = responseBody;
} else {
console.log("Error:");
console.log(error);
console.log("Response:");
console.log(response);
}
if (global.coinConfig.miningPoolsConfigUrls) {
var promises = [];
for (var i = 0; i < global.coinConfig.miningPoolsConfigUrls.length; i++) {
promises.push(new Promise(function(resolve, reject) {
request(global.coinConfig.miningPoolsConfigUrls[i], function(error, response, body) {
if (!error && response && response.statusCode && response.statusCode == 200) {
var responseBody = JSON.parse(body);
resolve(responseBody);
} else {
console.log("Error:");
console.log(error);
console.log("Response:");
console.log(response);
resolve({"coinbase_tags" : {}, "payout_addresses":{}});
}
});
}));
}
Promise.all(promises).then(function(results) {
global.miningPoolsConfigs = results;
});
}
if (global.sourcecodeVersion == null) {

5
app/coins/btc.js

@ -9,7 +9,10 @@ module.exports = {
nodeTitle:"Bitcoin Full Node",
nodeUrl:"https://bitcoin.org/en/full-node",
demoSiteUrl: "https://btc.chaintools.io",
miningPoolsConfigUrl:"https://raw.githubusercontent.com/blockchain/Blockchain-Known-Pools/master/pools.json",
miningPoolsConfigUrls:[
"https://raw.githubusercontent.com/blockchain/Blockchain-Known-Pools/master/pools.json",
"https://raw.githubusercontent.com/btccom/Blockchain-Known-Pools/master/pools.json"
],
maxBlockWeight: 4000000,
currencyUnits:[
{

4
app/coins/ltc.js

@ -8,7 +8,9 @@ module.exports = {
nodeTitle:"Litecoin Full Node",
nodeUrl:"https://litecoin.org/",
demoSiteUrl: "https://ltc.chaintools.io",
miningPoolsConfigUrl:"https://raw.githubusercontent.com/hashstream/pools/master/pools.json",
miningPoolsConfigUrls:[
"https://raw.githubusercontent.com/hashstream/pools/master/pools.json",
],
maxBlockWeight: 4000000,
currencyUnits:[
{

36
app/utils.js

@ -169,27 +169,31 @@ function getMinerFromCoinbaseTx(tx) {
return null;
}
if (global.miningPoolsConfig) {
for (var payoutAddress in global.miningPoolsConfig.payout_addresses) {
if (global.miningPoolsConfig.payout_addresses.hasOwnProperty(payoutAddress)) {
if (tx.vout && tx.vout.length > 0 && tx.vout[0].scriptPubKey && tx.vout[0].scriptPubKey.addresses && tx.vout[0].scriptPubKey.addresses.length > 0) {
if (tx.vout[0].scriptPubKey.addresses[0] == payoutAddress) {
var minerInfo = global.miningPoolsConfig.payout_addresses[payoutAddress];
minerInfo.identifiedBy = "payout address " + payoutAddress;
return minerInfo;
if (global.miningPoolsConfigs) {
for (var i = 0; i < global.miningPoolsConfigs.length; i++) {
var miningPoolsConfig = global.miningPoolsConfigs[i];
for (var payoutAddress in miningPoolsConfig.payout_addresses) {
if (miningPoolsConfig.payout_addresses.hasOwnProperty(payoutAddress)) {
if (tx.vout && tx.vout.length > 0 && tx.vout[0].scriptPubKey && tx.vout[0].scriptPubKey.addresses && tx.vout[0].scriptPubKey.addresses.length > 0) {
if (tx.vout[0].scriptPubKey.addresses[0] == payoutAddress) {
var minerInfo = miningPoolsConfig.payout_addresses[payoutAddress];
minerInfo.identifiedBy = "payout address " + payoutAddress;
return minerInfo;
}
}
}
}
}
for (var coinbaseTag in global.miningPoolsConfig.coinbase_tags) {
if (global.miningPoolsConfig.coinbase_tags.hasOwnProperty(coinbaseTag)) {
if (hex2ascii(tx.vin[0].coinbase).indexOf(coinbaseTag) != -1) {
var minerInfo = global.miningPoolsConfig.coinbase_tags[coinbaseTag];
minerInfo.identifiedBy = "coinbase tag '" + coinbaseTag + "'";
for (var coinbaseTag in miningPoolsConfig.coinbase_tags) {
if (miningPoolsConfig.coinbase_tags.hasOwnProperty(coinbaseTag)) {
if (hex2ascii(tx.vin[0].coinbase).indexOf(coinbaseTag) != -1) {
var minerInfo = miningPoolsConfig.coinbase_tags[coinbaseTag];
minerInfo.identifiedBy = "coinbase tag '" + coinbaseTag + "'";
return minerInfo;
return minerInfo;
}
}
}
}

6
routes/baseActionsRouter.js

@ -500,8 +500,10 @@ router.get("/address/:address", function(req, res) {
}
}
if (global.miningPoolsConfig.payout_addresses[address]) {
res.locals.payoutAddressForMiner = global.miningPoolsConfig.payout_addresses[address];
for (var i = 0; i < global.miningPoolsConfigs.length; i++) {
if (global.miningPoolsConfigs[i].payout_addresses[address]) {
res.locals.payoutAddressForMiner = global.miningPoolsConfigs[i].payout_addresses[address];
}
}
coreApi.getAddress(address).then(function(result) {

14
views/address.pug

@ -23,9 +23,17 @@ block content
p
span This looks like a miner payout address for the pool
strong #{payoutAddressForMiner.name}
span (see the configuration
a(href=coinConfig.miningPoolsConfigUrl) here
span )
if (coinConfig.miningPoolsConfigUrls.length > 1)
span (see the configurations:
each item, index in coinConfig.miningPoolsConfigUrls
if (index > 0)
span ,
a(href=item) config ##{index + 1}
span )
else
span (see the configuration
a(href=coinConfig.miningPoolsConfigUrls[0]) here
span )
if (false)
pre

4
views/includes/block-content.pug

@ -163,11 +163,11 @@ div(class="tab-content")
if (result.getblock.miner)
span #{result.getblock.miner.name}
if (result.getblock.miner.identifiedBy)
a(href=coinConfig.miningPoolsConfigUrl, data-toggle="tooltip", title=("Identified by: " + result.getblock.miner.identifiedBy), target="_blank")
span(data-toggle="tooltip", title=("Identified by: " + result.getblock.miner.identifiedBy))
i(class="fas fa-info-circle")
else
span ?
a(href=coinConfig.miningPoolsConfigUrl, data-toggle="tooltip", title=("Unable to identify (click to see config)"), target="_blank")
span(data-toggle="tooltip", title="Unable to identify miner")
i(class="fas fa-info-circle")
div(class="card mb-3")

Loading…
Cancel
Save