lisk-framework
Version:
Lisk blockchain application platform
45 lines • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.StateEndpoint = void 0;
const lisk_validator_1 = require("@liskhq/lisk-validator");
const stateProveRequestSchema = {
$id: '/node/endpoint/stateProveRequestSchema',
type: 'object',
required: ['queryKeys'],
properties: {
queryKeys: {
type: 'array',
items: {
dataType: 'string',
},
},
},
};
class StateEndpoint {
constructor(args) {
this._abi = args.abi;
this._chain = args.chain;
}
async prove(ctx) {
lisk_validator_1.validator.validate(stateProveRequestSchema, ctx.params);
if (!this._chain.lastBlock.header.stateRoot) {
throw new Error('Last block header state root is empty.');
}
const { proof } = await this._abi.prove({
stateRoot: this._chain.lastBlock.header.stateRoot,
keys: ctx.params.queryKeys.map(key => Buffer.from(key, 'hex')),
});
return {
proof: {
queries: proof.queries.map(query => ({
bitmap: query.bitmap.toString('hex'),
key: query.key.toString('hex'),
value: query.value.toString('hex'),
})),
siblingHashes: proof.siblingHashes.map(s => s.toString('hex')),
},
};
}
}
exports.StateEndpoint = StateEndpoint;
//# sourceMappingURL=state.js.map
;