@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
71 lines • 3.41 kB
JavaScript
;
// Copyright 2017-2025 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const services_1 = require("../../services");
const AbstractController_1 = __importDefault(require("../AbstractController"));
class ParasInclusionController extends AbstractController_1.default {
constructor(api) {
super(api, '', new services_1.ParasInclusionService(api));
/**
* Get inclusion information for a specific parachain block.
*
* @param number - The parachain block number
* @param at - Optional relay chain block hash to search from
* @param depth - Optional search depth (must be divisible by 5, defaults to 10)
*/
this.getParachainInclusion = async ({ params: { number }, query: { depth } }, res) => {
const [hash, paraId] = await Promise.all([
this.getHashFromAt(number),
this.api.query.parachainInfo.parachainId(),
]);
// Validate and parse depth parameter
let searchDepth = 10; // default
if (depth) {
const parsedDepth = parseInt(depth, 10);
if (isNaN(parsedDepth) || parsedDepth <= 0) {
ParasInclusionController.sanitizedSend(res, { error: 'Invalid depth parameter. Must be a positive integer.' });
return;
}
if (parsedDepth % 5 !== 0) {
ParasInclusionController.sanitizedSend(res, {
error: 'Depth parameter must be divisible by 5 for optimal performance.',
});
return;
}
if (parsedDepth > 100) {
ParasInclusionController.sanitizedSend(res, {
error: 'Depth parameter cannot exceed 100 to prevent excessive network requests.',
});
return;
}
searchDepth = parsedDepth;
}
ParasInclusionController.sanitizedSend(res, await this.service.getParachainInclusion(hash, paraId, number, searchDepth));
};
this.initRoutes();
}
initRoutes() {
this.safeMountAsyncGetHandlers([['/paras/:number/inclusion', this.getParachainInclusion]]);
}
}
ParasInclusionController.controllerName = 'ParasInclusion';
ParasInclusionController.requiredPallets = [['parachainInfo']];
exports.default = ParasInclusionController;
//# sourceMappingURL=ParasInclusionController.js.map