From c704bfedeb11e4e46605772696e047fd1e25dd68 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 8 Feb 2022 12:56:26 +0900 Subject: [PATCH] Download pool logos from github --- frontend/.gitignore | 1 + frontend/sync-assets.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/frontend/.gitignore b/frontend/.gitignore index 64b7777ea..789881ddd 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -53,6 +53,7 @@ src/resources/assets.minimal.json src/resources/assets-testnet.json src/resources/assets-testnet.minimal.json src/resources/pools.json +src/resources/mining-pools/* # environment config mempool-frontend-config.json diff --git a/frontend/sync-assets.js b/frontend/sync-assets.js index b1dc4090d..c37b987a2 100644 --- a/frontend/sync-assets.js +++ b/frontend/sync-assets.js @@ -33,6 +33,35 @@ function download(filename, url) { }); } +function downloadMiningPoolLogos() { + const options = { + host: 'api.github.com', + path: '/repos/mempool/mining-pools/contents/', + method: 'GET', + headers: {'user-agent': 'node.js'} + }; + + https.get(options, (response) => { + let chunks_of_data = []; + + response.on('data', (fragments) => { + chunks_of_data.push(fragments); + }); + + response.on('end', () => { + let response_body = Buffer.concat(chunks_of_data); + const poolLogos = JSON.parse(response_body.toString()); + for (const poolLogo of poolLogos) { + download(`${PATH}/mining-pools/${poolLogo.name}`, poolLogo.download_url); + } + }); + + response.on('error', (error) => { + throw new Error(error); + }); + }) +} + const poolsJsonUrl = 'https://raw.githubusercontent.com/btccom/Blockchain-Known-Pools/master/pools.json'; let assetsJsonUrl = 'https://raw.githubusercontent.com/mempool/asset_registry_db/master/index.json'; let assetsMinimalJsonUrl = 'https://raw.githubusercontent.com/mempool/asset_registry_db/master/index.minimal.json'; @@ -55,4 +84,5 @@ console.log('Downloading testnet assets'); download(PATH + 'assets-testnet.json', testnetAssetsJsonUrl); console.log('Downloading testnet assets minimal'); download(PATH + 'assets-testnet.minimal.json', testnetAssetsMinimalJsonUrl); - +console.log('Downloading mining pool logos'); +downloadMiningPoolLogos();