UNPKG

starknet-devnet

Version:
48 lines (47 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GithubError = exports.DevnetError = exports.DevnetProviderError = void 0; exports.toRpcBlockId = toRpcBlockId; const axios_1 = require("axios"); class DevnetProviderError extends Error { constructor(msg) { super(msg); // Set the prototype explicitly. Object.setPrototypeOf(this, DevnetProviderError.prototype); } static fromAxiosError(err) { if (err.code === axios_1.AxiosError.ECONNABORTED) { return new this(`${err.message}. Try specifying a greater timeout in DevnetProvider({...})`); } throw new Error(`Cannot create a DevnetProviderError from ${err}`); } } exports.DevnetProviderError = DevnetProviderError; class DevnetError extends Error { constructor(msg) { super(msg); // Set the prototype explicitly. Object.setPrototypeOf(this, DevnetError.prototype); } } exports.DevnetError = DevnetError; class GithubError extends Error { constructor(msg) { super(`Unexpected response from GitHub: ${msg}`); // Set the prototype explicitly. Object.setPrototypeOf(this, DevnetError.prototype); } } exports.GithubError = GithubError; function toRpcBlockId(blockId) { if (blockId === "latest" || blockId === "pending") { return blockId; } else if (typeof blockId === "number" && blockId >= 0) { return { block_number: blockId }; } else if (typeof blockId === "string" && /0[xX][a-fA-F0-9]+/.test(blockId)) { return { block_hash: blockId }; } throw new DevnetProviderError(`Invalid block ID: ${blockId}`); }