UNPKG

@swaptoshi/governance-module

Version:

Klayr governance on-chain module

63 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseStoreWithInstance = void 0; const klayr_framework_1 = require("klayr-framework"); const utils = require("@klayr/utils"); const db = require("@liskhq/lisk-db"); class BaseStoreWithInstance extends klayr_framework_1.Modules.BaseStore { constructor(moduleName, index, stores, events) { super(moduleName, index); this.genesisConfig = undefined; this.config = undefined; this.dependencyReady = false; this.default = undefined; this.stores = stores; this.events = events; this.moduleName = moduleName; } getDefault() { return this.default ? utils.objects.cloneDeep(this.default) : undefined; } async getOrDefault(context, key) { try { const store = await this.get(context, key); return store; } catch (error) { if (!(error instanceof db.NotFoundError)) { throw error; } return { ...this.getDefault() }; } } async getOrUndefined(context, key) { try { const store = await this.get(context, key); return store; } catch (error) { if (!(error instanceof db.NotFoundError)) { throw error; } return undefined; } } addDependencies(params) { Object.assign(this, params); if (this.genesisConfig !== undefined && this.config !== undefined) this.dependencyReady = true; } init(genesisConfig, governableConfig) { this.genesisConfig = genesisConfig; this.config = governableConfig; if (this.tokenMethod !== undefined) this.dependencyReady = true; } _checkDependencies() { if (!this.dependencyReady) { throw new Error('dependencies not configured'); } } } exports.BaseStoreWithInstance = BaseStoreWithInstance; //# sourceMappingURL=base.js.map