burst-whale-watch
Version:
An account watcher for Burstcoin
69 lines • 3.02 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path = require("path");
const configDialog_1 = require("./configDialog");
const fs_extra_1 = require("fs-extra");
const lodash_1 = require("lodash");
const util_1 = require("@burstjs/util");
const configPath = path.join(__filename, "../config.json");
const asAccountId = (account) => {
let accountId = account + '';
if (util_1.isBurstAddress(account)) {
accountId = util_1.convertAddressToNumericId(account);
}
return accountId;
};
class Config {
static load() {
return __awaiter(this, void 0, void 0, function* () {
if (!fs_1.existsSync(configPath)) {
const configDialog = new configDialog_1.ConfigDialog();
const answers = yield configDialog.run();
fs_extra_1.writeJsonSync(configPath, answers);
return answers;
}
return fs_extra_1.readJsonSync(configPath);
});
}
static addAccounts(accounts) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield Config.load();
const updatedConfig = Object.assign(Object.assign({}, config), { accounts: lodash_1.uniq(config.accounts.concat(accounts.map(asAccountId))) });
fs_extra_1.writeJsonSync(configPath, updatedConfig);
return updatedConfig;
});
}
static removeAccounts(accounts) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield Config.load();
const updatedConfig = Object.assign(Object.assign({}, config), { accounts: lodash_1.difference(config.accounts, accounts) });
fs_extra_1.writeJsonSync(configPath, updatedConfig);
return updatedConfig;
});
}
static clearAccounts() {
return __awaiter(this, void 0, void 0, function* () {
const config = yield Config.load();
config.accounts = [];
fs_extra_1.writeJsonSync(configPath, config);
return config;
});
}
static delete() {
return __awaiter(this, void 0, void 0, function* () {
yield fs_extra_1.remove(configPath);
});
}
}
exports.Config = Config;
//# sourceMappingURL=config.js.map