@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
73 lines • 2.75 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.AbstractService = exports.EtheuremAddressNotSupported = void 0;
const util_crypto_1 = require("@polkadot/util-crypto");
const http_errors_1 = require("http-errors");
const apiRegistry_1 = require("../../src/apiRegistry");
class EtheuremAddressNotSupported extends Error {
constructor(msg) {
super(`Etheurem addresses may not be supported on this network: ${msg}`);
this.expose = true;
this.status = 400;
this.statusCode = 400;
this.name = EtheuremAddressNotSupported.name;
}
}
exports.EtheuremAddressNotSupported = EtheuremAddressNotSupported;
class AbstractService {
constructor(specName) {
this.specName = specName;
}
/**
* Process metadata documention.
*
* @param docs metadata doucumentation array
*/
sanitizeDocs(docs) {
return docs.map((l, idx, arr) => (idx === arr.length - 1 ? l.toString() : `${l.toString()}\n`)).join('');
}
/**
* Returns HttpError with the correct err message for querying accounts balances.
*
* @function
* @param {string} address Address that was queried
* @param {Error} err Error returned from the promise
* @returns {HttpError}
*/
createHttpErrorForAddr(address, err) {
if ((0, util_crypto_1.isEthereumAddress)(address)) {
return new EtheuremAddressNotSupported(err.message);
}
return new http_errors_1.BadRequest(err.message);
}
get api() {
const api = apiRegistry_1.ApiPromiseRegistry.getApi(this.specName);
if (!api) {
throw new Error(`API not found for spec name: ${this.specName}`);
}
return api;
}
get assetHubInfo() {
return apiRegistry_1.ApiPromiseRegistry.assetHubInfo;
}
getSpecName() {
return this.specName;
}
}
exports.AbstractService = AbstractService;
//# sourceMappingURL=AbstractService.js.map