From 337491073efdbf1b8875561081f69d0893f2a46e Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Mon, 20 Jun 2022 21:35:46 +0100 Subject: [PATCH] Handle custom repo path --- repository/repository.js | 9 +++++---- worker.js | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/repository/repository.js b/repository/repository.js index 9c887a5..a73ccde 100644 --- a/repository/repository.js +++ b/repository/repository.js @@ -11,6 +11,7 @@ function Repository(client, url, branch, opts) { opts = opts || {} const name = opts.name || url.split('/').slice(-1)[0] const repoDir = join(process.cwd(), '../' + name) + const repoPath = join(repoDir, opts.path || '') const exclude = opts.exclude || [] async function updateRepo() { @@ -40,9 +41,9 @@ function Repository(client, url, branch, opts) { } function buildData(dir) { - const jsonFiles = fs.readdirSync(join(repoDir, dir)).filter(file => path.extname(file) === '.json'); + const jsonFiles = fs.readdirSync(join(repoPath, dir)).filter(file => path.extname(file) === '.json'); const data = jsonFiles.reduce((sum, filename) => { - const path = join(repoDir, dir, filename); + const path = join(repoPath, dir, filename); const data = fs.existsSync(path) ? fs.readFileSync(path) : undefined const json = data && JSON.parse(data); sum[filename.replace(/\.[^.]*$/,'')] = json @@ -68,7 +69,7 @@ function Repository(client, url, branch, opts) { } async function loadData() { - const directories = fs.readdirSync(repoDir, { withFileTypes: true }) + const directories = fs.readdirSync(repoPath, { withFileTypes: true }) .filter((item) => item.isDirectory()) .map((item) => item.name); @@ -77,7 +78,7 @@ function Repository(client, url, branch, opts) { return; } - const path = join(repoDir, dir); + const path = join(repoPath, dir); if(opts.require && !fs.existsSync(join(path, opts.require))){ return } diff --git a/worker.js b/worker.js index e869a63..b6da06c 100644 --- a/worker.js +++ b/worker.js @@ -9,6 +9,7 @@ import BlockMonitor from "./chains/blockMonitor.js"; const chainUrl = process.env.CHAIN_URL || 'https://github.com/cosmos/chain-registry' const chainBranch = process.env.CHAIN_BRANCH || 'master' +const chainPath = process.env.CHAIN_PATH const repoRefreshSeconds = parseInt(process.env.REPO_REFRESH || 900) const validatorUrl = process.env.VALIDATOR_URL || 'https://github.com/eco-stake/validator-registry' const validatorBranch = process.env.VALIDATOR_BRANCH || 'master' @@ -77,7 +78,7 @@ async function queueBlockCheck(client, registry, monitor) { (async () => { const client = await redisClient(); - const chainRepo = Repository(client, chainUrl, chainBranch, { exclude: ['testnets'], require: 'chain.json' }) + const chainRepo = Repository(client, chainUrl, chainBranch, { path: chainPath, require: 'chain.json' }) const validatorRepo = Repository(client, validatorUrl, validatorBranch, { exclude: [], require: 'chains.json', storeMeta: async (name, allData) => { await client.json.set([name, 'addresses'].join(':'), '$', allData.reduce((sum, validator) => { for(const chain of validator.chains.chains){