2020-05-02 09:04:33 +02:00
|
|
|
var https = require('https');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2021-08-05 00:31:22 +02:00
|
|
|
const CONFIG_FILE_NAME = 'mempool-frontend-config.json';
|
|
|
|
let configContent = {};
|
|
|
|
|
2021-01-11 14:11:29 +01:00
|
|
|
var PATH = 'dist/mempool/browser/en-US/resources/';
|
2020-05-02 09:04:33 +02:00
|
|
|
if (process.argv[2] && process.argv[2] === 'dev') {
|
2020-05-02 11:59:14 +02:00
|
|
|
PATH = 'src/resources/';
|
2020-05-02 09:04:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-05 00:31:22 +02:00
|
|
|
try {
|
|
|
|
const rawConfig = fs.readFileSync(CONFIG_FILE_NAME);
|
|
|
|
configContent = JSON.parse(rawConfig);
|
|
|
|
console.log(`${CONFIG_FILE_NAME} file found, using provided config`);
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code !== 'ENOENT') {
|
|
|
|
throw new Error(e);
|
|
|
|
} else {
|
|
|
|
console.log(`${CONFIG_FILE_NAME} file not found, using default config`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 09:04:33 +02:00
|
|
|
function download(filename, url) {
|
2020-05-27 20:56:32 +02:00
|
|
|
https.get(url, (response) => {
|
|
|
|
if (response.statusCode < 200 || response.statusCode > 299) {
|
|
|
|
throw new Error('HTTP Error ' + response.statusCode + ' while fetching \'' + filename + '\'');
|
|
|
|
}
|
|
|
|
response.pipe(fs.createWriteStream(filename));
|
|
|
|
})
|
|
|
|
.on('error', function(e) {
|
|
|
|
throw new Error(e);
|
2020-05-02 09:04:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-08 04:56:26 +01:00
|
|
|
function downloadMiningPoolLogos() {
|
|
|
|
const options = {
|
|
|
|
host: 'api.github.com',
|
2022-03-17 14:16:57 +01:00
|
|
|
path: '/repos/mempool/mining-pool-logos/contents/',
|
2022-02-08 04:56:26 +01:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-17 14:16:57 +01:00
|
|
|
const poolsJsonUrl = 'https://raw.githubusercontent.com/mempool/mining-pools/master/pools.json';
|
2021-08-05 00:31:22 +02:00
|
|
|
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';
|
|
|
|
|
|
|
|
if (configContent.BASE_MODULE && configContent.BASE_MODULE === 'liquid') {
|
|
|
|
assetsJsonUrl = 'https://raw.githubusercontent.com/Blockstream/asset_registry_db/master/index.json';
|
|
|
|
assetsMinimalJsonUrl = 'https://raw.githubusercontent.com/Blockstream/asset_registry_db/master/index.minimal.json';
|
|
|
|
}
|
|
|
|
|
2021-12-28 21:42:34 +01:00
|
|
|
const testnetAssetsJsonUrl = 'https://raw.githubusercontent.com/Blockstream/asset_registry_testnet_db/master/index.json';
|
|
|
|
const testnetAssetsMinimalJsonUrl = 'https://raw.githubusercontent.com/Blockstream/asset_registry_testnet_db/master/index.minimal.json';
|
|
|
|
|
2020-05-02 09:04:33 +02:00
|
|
|
console.log('Downloading assets');
|
2021-08-05 00:31:22 +02:00
|
|
|
download(PATH + 'assets.json', assetsJsonUrl);
|
2020-05-02 09:04:33 +02:00
|
|
|
console.log('Downloading assets minimal');
|
2021-08-05 00:31:22 +02:00
|
|
|
download(PATH + 'assets.minimal.json', assetsMinimalJsonUrl);
|
2020-05-09 19:35:21 +02:00
|
|
|
console.log('Downloading mining pools info');
|
2021-08-05 00:31:22 +02:00
|
|
|
download(PATH + 'pools.json', poolsJsonUrl);
|
2021-12-28 21:42:34 +01:00
|
|
|
console.log('Downloading testnet assets');
|
|
|
|
download(PATH + 'assets-testnet.json', testnetAssetsJsonUrl);
|
|
|
|
console.log('Downloading testnet assets minimal');
|
|
|
|
download(PATH + 'assets-testnet.minimal.json', testnetAssetsMinimalJsonUrl);
|
2022-02-08 04:56:26 +01:00
|
|
|
console.log('Downloading mining pool logos');
|
|
|
|
downloadMiningPoolLogos();
|