@liskhq/lisk-api-client
Version:
An API client for the Lisk network
37 lines • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockMethods = void 0;
const codec_1 = require("./codec");
class BlockMethods {
constructor(channel, registeredSchema, moduleMetadata) {
this._channel = channel;
this._schemas = registeredSchema;
this._metadata = moduleMetadata;
}
async get(id) {
const idString = Buffer.isBuffer(id) ? id.toString('hex') : id;
const block = await this._channel.invoke('chain_getBlockByID', {
id: idString,
});
return (0, codec_1.decodeBlockJSON)(block, this._metadata);
}
async getByHeight(height) {
const block = await this._channel.invoke('chain_getBlockByHeight', { height });
return (0, codec_1.decodeBlockJSON)(block, this._metadata);
}
encode(input) {
return (0, codec_1.encodeBlock)(input, this._schemas, this._metadata);
}
decode(input) {
const inputBuffer = Buffer.isBuffer(input) ? input : Buffer.from(input, 'hex');
return (0, codec_1.decodeBlock)(inputBuffer, this._schemas, this._metadata);
}
toJSON(block) {
return (0, codec_1.toBlockJSON)(block, this._schemas, this._metadata);
}
fromJSON(block) {
return (0, codec_1.fromBlockJSON)(block, this._schemas, this._metadata);
}
}
exports.BlockMethods = BlockMethods;
//# sourceMappingURL=block_methods.js.map