@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
57 lines • 2.66 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/>.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParasInclusionService = void 0;
const apiRegistry_1 = require("../../apiRegistry");
const getRelayParentNumber_1 = require("../../util/relay/getRelayParentNumber");
const AbstractService_1 = require("../AbstractService");
class ParasInclusionService extends AbstractService_1.AbstractService {
constructor(api) {
super(api);
}
/**
* Find the relay chain inclusion information for a specific parachain block.
*
* @param hash - The parachain block hash
* @param paraId - The parachain ID
* @param number - The parachain block number
* @param depth - Search depth (defaults to 10)
*/
async getParachainInclusion(hash, paraId, number, depth = 10) {
var _a;
const { api } = this;
const rcApi = (_a = apiRegistry_1.ApiPromiseRegistry.getApiByType('relay')[0]) === null || _a === void 0 ? void 0 : _a.api;
if (!rcApi) {
throw new Error('Relay chain api must be available');
}
// Extract relay parent number from the parachain block
const relayParentNumber = await (0, getRelayParentNumber_1.getRelayParentNumberRaw)(api, hash);
// Search for inclusion starting from relay_parent_number + 1
const inclusionNumber = await (0, getRelayParentNumber_1.searchForInclusionBlock)(rcApi, paraId.toNumber(), number, // parachain block number
relayParentNumber, depth);
return {
parachainBlock: parseInt(number, 10),
parachainBlockHash: hash.toString(),
parachainId: paraId.toNumber(),
relayParentNumber,
inclusionNumber: inclusionNumber || null,
found: inclusionNumber !== null,
};
}
}
exports.ParasInclusionService = ParasInclusionService;
//# sourceMappingURL=ParasInclusionService.js.map