@rarible/estimate-middleware
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -23,5 +23,4 @@ "use strict"; | ||
if (req.method === "eth_subscribe") { | ||
res.id = req.id; | ||
res.error = (0, utils_1.createNotSupportedError)(); | ||
return [2 /*return*/]; | ||
res.error = new utils_1.RpcError("Notifications not supported", -32000); | ||
return [2 /*return*/, next()]; | ||
} | ||
@@ -34,3 +33,8 @@ if (!(req.method === "eth_sendTransaction")) return [3 /*break*/, 5]; | ||
if (!(force || !params.gas)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, engine.handle((0, tslib_1.__assign)((0, tslib_1.__assign)({}, req), { params: [getEstimateParams(params)], method: "eth_estimateGas" }))]; | ||
return [4 /*yield*/, engine.handle({ | ||
jsonrpc: "2.0", | ||
id: (0, json_rpc_engine_1.getUniqueId)(), | ||
params: [getEstimateParams(params)], | ||
method: "eth_estimateGas", | ||
})]; | ||
case 2: | ||
@@ -48,7 +52,5 @@ response = _a.sent(); | ||
error_1 = _a.sent(); | ||
res.error = (0, utils_1.extractError)(error_1); | ||
return [3 /*break*/, 5]; | ||
case 5: return [4 /*yield*/, next()]; | ||
case 6: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
case 5: return [2 /*return*/, next()]; | ||
} | ||
@@ -74,3 +76,3 @@ }); | ||
} | ||
throw new Error("Can't handle JSON rpc response"); | ||
throw new utils_1.RpcError("Can't handle JSON rpc response", -32700); | ||
} | ||
@@ -84,3 +86,3 @@ function getTransactionParams(request) { | ||
} | ||
throw new Error("Can't parse eth_sendTransaction params"); | ||
throw new utils_1.RpcError("Can't parse eth_sendTransaction params", -32600); | ||
} | ||
@@ -87,0 +89,0 @@ function isJSONRpcResponse(x) { |
import type { SafeEventEmitterProvider } from "eth-json-rpc-middleware/dist/utils/cache"; | ||
import type { JsonRpcError } from "json-rpc-engine"; | ||
export declare function isSafeEventEmitterProvider(x: unknown): x is SafeEventEmitterProvider; | ||
export declare function createNotSupportedError(): JsonRpcError; | ||
export declare class RpcError extends Error implements JsonRpcError { | ||
readonly code: number; | ||
constructor(message: string, code: number); | ||
} | ||
export declare function extractError(error: unknown): Error; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createNotSupportedError = exports.isSafeEventEmitterProvider = void 0; | ||
exports.extractError = exports.RpcError = exports.isSafeEventEmitterProvider = void 0; | ||
var tslib_1 = require("tslib"); | ||
function isSafeEventEmitterProvider(x) { | ||
@@ -8,8 +9,37 @@ return typeof x === "object" && x !== null && "send" in x && "sendAsync" in x; | ||
exports.isSafeEventEmitterProvider = isSafeEventEmitterProvider; | ||
function createNotSupportedError() { | ||
return { | ||
code: -32000, | ||
message: "Notifications not supported", | ||
}; | ||
var RpcError = /** @class */ (function (_super) { | ||
(0, tslib_1.__extends)(RpcError, _super); | ||
function RpcError(message, code) { | ||
var _this = _super.call(this, message) || this; | ||
_this.code = code; | ||
// eslint-disable-next-line unicorn/custom-error-definition | ||
_this.name = "JsonRpcError"; | ||
return _this; | ||
} | ||
return RpcError; | ||
}(Error)); | ||
exports.RpcError = RpcError; | ||
function extractError(error) { | ||
if (isObject(error)) { | ||
if ("data" in error) { | ||
var data = error.data; | ||
if (isObject(data) && isJsonRpcError(data)) { | ||
return new RpcError(data.message, data.code); | ||
} | ||
} | ||
if (isJsonRpcError(error)) { | ||
return new RpcError(error.message, error.code); | ||
} | ||
} | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
return new Error("Unknown error"); | ||
} | ||
exports.createNotSupportedError = createNotSupportedError; | ||
exports.extractError = extractError; | ||
function isJsonRpcError(x) { | ||
return "code" in x && "message" in x; | ||
} | ||
function isObject(x) { | ||
return typeof x === "object" && x !== null; | ||
} |
{ | ||
"name": "@rarible/estimate-middleware", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"keywords": [ | ||
@@ -39,3 +39,3 @@ "rarible", | ||
}, | ||
"gitHead": "169b69c24186ad9fbb4f959b2b7f96386279a881" | ||
"gitHead": "e7f65a9aeafb82e17d084c88a04e90221918d3f0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32229
209