UNPKG

@swaptoshi/governance-module

Version:

Klayr governance on-chain module

77 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseInstance = void 0; class BaseInstance { constructor(storeKey, stores, events, config, genesisConfig, moduleName, key) { this.mutableDependencyReady = false; this.immutableDependencyReady = false; this.key = Buffer.alloc(0); this.stores = stores; this.events = events; this.moduleName = moduleName; this.config = config; this.genesisConfig = genesisConfig; this.instanceStore = stores.get(storeKey); if (key) this.key = key; } toJSON() { throw new Error('toJSON() method is not implemented'); } toObject() { throw new Error('toObject() method is not implemented'); } addImmutableDependencies(param) { if (this.mutableDependencyReady || this.immutableDependencyReady) { throw new Error('this instance dependencies already been configured'); } const { context, ...methods } = param; Object.assign(this, methods); this.immutableContext = context; this.immutableDependencyReady = true; } addMutableDependencies(param) { if (this.mutableDependencyReady || this.immutableDependencyReady) { throw new Error('this instance dependencies already been configured'); } const { context, ...methods } = param; Object.assign(this, methods); this.mutableContext = context; this.context = context; this.immutableContext = context; this.mutableDependencyReady = true; this.immutableDependencyReady = true; } addDependencies(param) { this.addMutableDependencies(param); } async getConfig(context) { const config = await this.config.getConfig(context); return config; } _checkMutableDependencies() { if (!this.mutableDependencyReady) { throw new Error('dependencies not configured'); } } _checkImmutableDependencies() { if (!this.immutableDependencyReady) { throw new Error('dependencies not configured'); } } _checkDependencies() { this._checkMutableDependencies(); } _setKey(key) { this.key = key; } async _saveStore() { this._checkMutableDependencies(); if (this.key.compare(Buffer.alloc(0)) === 0) { throw new Error("instance _saveStore() can't store data with empty buffer as key"); } await this.instanceStore.set(this.mutableContext.context, this.key, this.toObject()); } } exports.BaseInstance = BaseInstance; //# sourceMappingURL=base.js.map