Skip to content

Commit

Permalink
Merge pull request #22 from eco-stake/handle-custom-repo-path
Browse files Browse the repository at this point in the history
Handle custom repo path
  • Loading branch information
tombeynon authored Jun 20, 2022
2 parents fd1bd3d + 3374910 commit e1969a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions repository/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit e1969a5

Please sign in to comment.