UNPKG

@swaptoshi/governance-module

Version:

Klayr governance on-chain module

41 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigRegistryStore = void 0; const klayr_framework_1 = require("klayr-framework"); const db = require("@liskhq/lisk-db"); const schema_1 = require("../schema"); class ConfigRegistryStore extends klayr_framework_1.Modules.BaseStore { constructor() { super(...arguments); this.schema = schema_1.configRegistryStoreSchema; } async getOrDefault(context) { try { const castedVote = await this.get(context, Buffer.alloc(0)); return castedVote; } catch (error) { if (!(error instanceof db.NotFoundError)) { throw error; } return { registry: [] }; } } async register(context, module, index) { const store = await this.getOrDefault(context); const registryIndex = store.registry.findIndex(t => t.module === module); if (registryIndex === -1) { store.registry.push({ module, index }); store.registry.sort((a, b) => { if (a.module > b.module) return -1; if (b.module > a.module) return 1; return 0; }); } await this.set(context, Buffer.alloc(0), store); } } exports.ConfigRegistryStore = ConfigRegistryStore; //# sourceMappingURL=config_registry.js.map