UNPKG

lisk-framework

Version:

Lisk blockchain application platform

131 lines 4.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChainAccountStore = exports.allChainAccountsSchema = exports.chainDataSchema = exports.chainDataJSONSchema = void 0; const lisk_cryptography_1 = require("@liskhq/lisk-cryptography"); const lisk_db_1 = require("@liskhq/lisk-db"); const base_store_1 = require("../../base_store"); const constants_1 = require("../constants"); exports.chainDataJSONSchema = { type: 'object', required: ['name', 'lastCertificate', 'status'], properties: { name: { dataType: 'string', fieldNumber: 1, }, lastCertificate: { type: 'object', fieldNumber: 2, required: ['height', 'timestamp', 'stateRoot', 'validatorsHash'], properties: { height: { dataType: 'uint32', fieldNumber: 1, }, timestamp: { dataType: 'uint32', fieldNumber: 2, }, stateRoot: { dataType: 'string', format: 'hex', fieldNumber: 3, }, validatorsHash: { dataType: 'string', format: 'hex', fieldNumber: 4, }, }, }, status: { dataType: 'uint32', fieldNumber: 3, }, }, }; exports.chainDataSchema = { $id: '/modules/interoperability/chainData', type: 'object', required: ['name', 'lastCertificate', 'status'], properties: { name: { dataType: 'string', minLength: constants_1.MIN_CHAIN_NAME_LENGTH, maxLength: constants_1.MAX_CHAIN_NAME_LENGTH, fieldNumber: 1, }, lastCertificate: { type: 'object', fieldNumber: 2, required: ['height', 'timestamp', 'stateRoot', 'validatorsHash'], properties: { height: { dataType: 'uint32', fieldNumber: 1, }, timestamp: { dataType: 'uint32', fieldNumber: 2, }, stateRoot: { dataType: 'bytes', minLength: constants_1.HASH_LENGTH, maxLength: constants_1.HASH_LENGTH, fieldNumber: 3, }, validatorsHash: { dataType: 'bytes', minLength: constants_1.HASH_LENGTH, maxLength: constants_1.HASH_LENGTH, fieldNumber: 4, }, }, }, status: { dataType: 'uint32', fieldNumber: 3, }, }, }; exports.allChainAccountsSchema = { $id: '/modules/interoperability/allChainAccounts', type: 'object', required: ['chains'], properties: { chains: { type: 'array', items: exports.chainDataJSONSchema, }, }, }; class ChainAccountStore extends base_store_1.BaseStore { constructor() { super(...arguments); this.schema = exports.chainDataSchema; } get storePrefix() { return constants_1.STORE_PREFIX; } async getAllAccounts(context, startChainID) { const endBuf = lisk_cryptography_1.utils.intToBuffer(constants_1.MAX_UINT32, 4); const chainAccounts = await this.iterate(context, { gte: startChainID, lte: endBuf, }); return chainAccounts.map(chainAccount => chainAccount.value); } async getOrUndefined(context, key) { try { return await super.get(context, key); } catch (error) { if (!(error instanceof lisk_db_1.NotFoundError)) { throw error; } return undefined; } } } exports.ChainAccountStore = ChainAccountStore; //# sourceMappingURL=chain_account.js.map