reorg code, integration publish/subscribe working, still some TODOs

This commit is contained in:
Josip Milovac 2023-02-01 13:01:51 +11:00
parent 043a95d9ef
commit 1af6d56e2d
35 changed files with 3052 additions and 1401 deletions

View file

@ -1,6 +1,37 @@
const DIFFICULTY = 3;
const MINE_RATE = 3000;
const INITIAL_BALANCE = 500;
const MINING_REWARD = 50;
const fs = require('fs');
const process = require('process');
module.exports = { DIFFICULTY, MINE_RATE, INITIAL_BALANCE, MINING_REWARD };
class Config {
constructor(location, disallow_arg_overide) {
//possible race if deleted after check, but we live with it I guess
const looking = location;
if (typeof disallow_arg_overide === undefined || disallow_arg_overide === null || !disallow_arg_overide) {
const args = process.argv.slice(2);
if (args.length > 0) {
looking = args[0];
}
}
if (fs.existsSync(looking)) {
const rawSettings = fs.readFileSync(looking, 'utf8');
this.settings = JSON.parse(rawSettings);
}
}
get(config) {
if (this.settings.hasOwnProperty(config.key)) {
const value = this.settings[config.key];
if (config.hasOwnProperty('transform')) {
return config.transform(value);
} else {
return value;
}
} else {
return config.default;
}
}
}
module.exports = Config;