Skip to content

Commit

Permalink
Changed btc provider default to sochain
Browse files Browse the repository at this point in the history
  • Loading branch information
crove-iov committed Nov 12, 2020
1 parent 5a4c7b2 commit 6c1dabb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const usePrimaryBtcHashrateProvider = require('./lib/utils/config').usePrimaryBt
const btcHashrateUpdater = setInterval(() =>
{
if(usePrimaryBtcHashrateProvider) {
Nodes.updateBtcHashrate('http://35.202.2.222:5000/blockchain/hashrate/');
Nodes.updateBtcHashrate('https://sochain.com/api/v2/get_info/BTC');
} else {
Nodes.updateBtcHashrateFromBackUp('https://api.blockchain.info/stats');
}
Expand Down
5 changes: 5 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,9 @@ Collection.prototype.updateBtcHashrateFromBackUp = function(source)
this._blockchain.updateBtcHashrateFromBackUpExternalSource(source);
}

Collection.prototype.updateBtcHashrateFromAlternativeBackUp = function(source)
{
this._blockchain.updateBtcHashrateFromAlternativeBackUpExternalSource(source);
}

module.exports = Collection;
40 changes: 34 additions & 6 deletions lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ function tryParseJSON (jsonString, customErrorMessage){

History.prototype.updateBtcHashrateFromExternalSource = function(source)
{
http.get(source, (resp) => {
https.get(source, (resp) => {
let data = '';

resp.on('data', (chunk) => {
Expand All @@ -701,14 +701,12 @@ History.prototype.updateBtcHashrateFromExternalSource = function(source)

resp.on('end', () => {
const parsedData = tryParseJSON(data, "Failed to update BTC hashrate. Unable to parse JSON response");

if (!parsedData || !parsedData.hasOwnProperty("data") || !parsedData.data.hasOwnProperty("hashrate")){
return;
}

const oldBtcHashrate = this._btcHashrate;
const btcHashrateExa = parsedData.data.hashrate;
this._btcHashrate = btcHashrateExa * 1000000000000000000;

this._btcHashrate = parsedData.data.hashrate
// trigger client update
if(oldBtcHashrate !== this._btcHashrate) {
this.getCharts();
Expand All @@ -734,7 +732,7 @@ History.prototype.updateBtcHashrateFromBackUpExternalSource = function(source)
if (!parsedData || !parsedData.hasOwnProperty("hash_rate")){
return;
}

const oldBtcHashrate = this._btcHashrate;
const btcHashrateGiga = parsedData.hash_rate;
this._btcHashrate = btcHashrateGiga * 1000000000;
Expand All @@ -750,4 +748,34 @@ History.prototype.updateBtcHashrateFromBackUpExternalSource = function(source)
});
}

History.prototype.updateBtcHashrateFromAlternativeExternalSource = function(source)
{
http.get(source, (resp) => {
let data = '';

resp.on('data', (chunk) => {
data += chunk;
});

resp.on('end', () => {
const parsedData = tryParseJSON(data, "Failed to update BTC hashrate. Unable to parse JSON response");
if (!parsedData || !parsedData.hasOwnProperty("data") || !parsedData.data.hasOwnProperty("hashrate")){
return;
}

const oldBtcHashrate = this._btcHashrate;
const btcHashrateExa = parsedData.data.hashrate;
this._btcHashrate = btcHashrateExa * 1000000000000000000;

// trigger client update
if(oldBtcHashrate !== this._btcHashrate) {
this.getCharts();
}
});

}).on("error", (err) => {
console.error("Error while retrieving BTC hash rate: " + err.message);
});
}

module.exports = History;

0 comments on commit 6c1dabb

Please sign in to comment.