UNPKG

lisk-framework

Version:

Lisk blockchain application platform

53 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LegacyEndpoint = void 0; const lisk_validator_1 = require("@liskhq/lisk-validator"); const storage_1 = require("./storage"); const codec_1 = require("./codec"); class LegacyEndpoint { constructor(args) { this.storage = new storage_1.Storage(args.db); this._legacyConfig = args.legacyConfig; } async getTransactionByID(context) { const { id } = context.params; if (!(0, lisk_validator_1.isHexString)(id)) { throw new Error('Invalid parameters. `id` must be a valid hex string.'); } const tx = await this.storage.getTransactionByID(Buffer.from(id, 'hex')); return (0, codec_1.getLegacyTransactionJSONWithSchema)(tx).transaction; } async getTransactionsByBlockID(context) { const { id } = context.params; if (!(0, lisk_validator_1.isHexString)(id)) { throw new Error('Invalid parameters. `id` must be a valid hex string.'); } const transactions = await this.storage.getTransactionsByBlockID(Buffer.from(id, 'hex')); return transactions.map(tx => (0, codec_1.getLegacyTransactionJSONWithSchema)(tx).transaction); } async getBlockByID(context) { const { id } = context.params; if (!(0, lisk_validator_1.isHexString)(id)) { throw new Error('Invalid parameters. `id` must be a valid hex string.'); } return (0, codec_1.decodeBlockJSON)(await this.storage.getBlockByID(Buffer.from(id, 'hex'))).block; } async getBlockByHeight(context) { const { height } = context.params; if (typeof height !== 'number' || height < 0) { throw new Error('Invalid parameters. `height` must be zero or a positive number.'); } return (0, codec_1.decodeBlockJSON)(await this.storage.getBlockByHeight(height)).block; } async getLegacyBrackets(_context) { return Promise.all(this._legacyConfig.brackets.map(async (bracket) => { const bracketInfo = await this.storage.getBracketInfo(Buffer.from(bracket.snapshotBlockID, 'hex')); return { ...bracketInfo, snapshotBlockID: bracket.snapshotBlockID, }; })); } } exports.LegacyEndpoint = LegacyEndpoint; //# sourceMappingURL=endpoint.js.map