zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
35 lines (34 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchRuntimeVersion = fetchRuntimeVersion;
exports.isVersionAtLeast = isVersionAtLeast;
exports.isVersionBetween = isVersionBetween;
exports.isVersionExactly = isVersionExactly;
exports.requireVersionAtLeast = requireVersionAtLeast;
/**
* Fetches the runtime spec from the chain.
* @param api - The ApiPromise instance.
* @returns The runtime spec.
*/
function fetchRuntimeVersion(api) {
const version = api.consts.system.version;
return {
specVersion: version.specVersion.toNumber(),
specName: version.specName.toString(),
};
}
function isVersionAtLeast(runtimeSpec, targetVersion) {
return runtimeSpec.specVersion >= targetVersion;
}
function isVersionBetween(runtimeSpec, minVersion, maxVersion) {
return (runtimeSpec.specVersion >= minVersion &&
runtimeSpec.specVersion <= maxVersion);
}
function isVersionExactly(runtimeSpec, targetVersion) {
return runtimeSpec.specVersion === targetVersion;
}
function requireVersionAtLeast(runtimeSpec, targetVersion, featureName) {
if (!isVersionAtLeast(runtimeSpec, targetVersion)) {
throw new Error(`${featureName} is only available in runtime version ${targetVersion} or later`);
}
}