Skip to content

Commit

Permalink
Merge f2377cb into a2ca63d
Browse files Browse the repository at this point in the history
  • Loading branch information
pbca26 authored Jul 4, 2022
2 parents a2ca63d + f2377cb commit 1960be3
Show file tree
Hide file tree
Showing 50 changed files with 4,331 additions and 3,227 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/electron/node_modules
/electron/ui/node_modules
/electron/ui/build
/src/coin-icons.scss
/public/coin-icons.png
/.pnp
.pnp.js

Expand Down
57 changes: 57 additions & 0 deletions check-coin-explorers-availability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fetch = require('node-fetch');
const coins = require('./src/lib/coins');

let coinsToRemove = [];

(async () => {
const getInfo = async explorerUrl => {
try {
const response = await fetch(`${explorerUrl}/status?q=getInfo`);
const isJson = response.headers.get('Content-Type').includes('application/json');

const body = isJson ? await response.json() : await response.text();

if (!response.ok) {
throw new Error(body);
}

return body;
} catch (e) {
return null;
}
};

const checkApiEndpoints = async coin => {
const getInfoRes = await Promise.all(coins[coin].api.map((value, index) => {
return getInfo(value);
}));
let longestBlockHeight = 0;
let apiEndPointIndex = null;

console.log('checkExplorerEndpoints', getInfoRes);

for (let i = 0; i < coins[coin].api.length; i++) {
if (getInfoRes[i] &&
'info' in getInfoRes[i] &&
'version' in getInfoRes[i].info) {
if (getInfoRes[i].info.blocks > longestBlockHeight) {
longestBlockHeight = getInfoRes[i].info.blocks;
apiEndPointIndex = i;
}
}
}

console.log('apiEndPointIndex', apiEndPointIndex);

return apiEndPointIndex !== null ? coins[coin].api[apiEndPointIndex] : null;
};

for (let coin in coins) {
const explorerUrl = await checkApiEndpoints(coin);
if (!explorerUrl) coinsToRemove.push(coin)
console.log(`${coin} explorer url`, explorerUrl);
}

console.log('all done!');
console.log('coins to remove', coinsToRemove);
})();
Loading

0 comments on commit 1960be3

Please sign in to comment.