@zilliqa-js/core
Advanced tools
Comparing version 0.2.10 to 0.3.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Errors; | ||
(function (Errors) { | ||
// Unknown Error | ||
Errors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
// Not implemented | ||
Errors["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED"; | ||
// Missing new operator to an object | ||
// - name: The name of the class | ||
Errors["MISSING_NEW"] = "MISSING_NEW"; | ||
// Call exception | ||
// - transaction: the transaction | ||
// - address?: the contract address | ||
// - args?: The arguments passed into the function | ||
// - method?: The Solidity method signature | ||
Errors["CALL_EXCEPTION"] = "CALL_EXCEPTION"; | ||
Errors["TIMED_OUT"] = "TIMED_OUT"; | ||
// Invalid argument (e.g. value is incompatible with type) to a function: | ||
// - arg: The argument name that was invalid | ||
// - value: The value of the argument | ||
Errors["INVALID_ARGUMENT"] = "INVALID_ARGUMENT"; | ||
// Missing argument to a function: | ||
// - count: The number of arguments received | ||
// - expectedCount: The number of arguments expected | ||
Errors["MISSING_ARGUMENT"] = "MISSING_ARGUMENT"; | ||
// Too many arguments | ||
// - count: The number of arguments received | ||
// - expectedCount: The number of arguments expected | ||
Errors["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT"; | ||
// Numeric Fault | ||
// - operation: the operation being executed | ||
// - fault: the reason this faulted | ||
Errors["NUMERIC_FAULT"] = "NUMERIC_FAULT"; | ||
// Insufficien funds (< value + gasLimit * gasPrice) | ||
// - transaction: the transaction attempted | ||
Errors["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS"; | ||
// Nonce has already been used | ||
// - transaction: the transaction attempted | ||
Errors["NONCE_EXPIRED"] = "NONCE_EXPIRED"; | ||
// The replacement fee for the transaction is too low | ||
// - transaction: the transaction attempted | ||
Errors["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED"; | ||
// Unsupported operation | ||
// - operation | ||
Errors["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION"; | ||
})(Errors = exports.Errors || (exports.Errors = {})); | ||
/** | ||
@@ -5,0 +50,0 @@ * ZjsError |
@@ -154,2 +154,76 @@ import fetch from 'cross-fetch'; | ||
var _this = undefined; | ||
/** | ||
* TODO: Enable commented-out methods when they are implemented | ||
* blockchain-side. | ||
*/ | ||
var RPCMethod; | ||
(function (RPCMethod) { | ||
// Network-related methods | ||
RPCMethod["GetNetworkId"] = "GetNetworkId"; | ||
// GetClientVersion = 'GetClientVersion', | ||
// GetProtocolVersion = 'GetProtocolVersion', | ||
// Blockchain-related methods | ||
RPCMethod["GetBlockchainInfo"] = "GetBlockchainInfo"; | ||
RPCMethod["GetShardingStructure"] = "GetShardingStructure"; | ||
RPCMethod["GetDSBlock"] = "GetDsBlock"; | ||
RPCMethod["GetLatestDSBlock"] = "GetLatestDsBlock"; | ||
RPCMethod["GetNumDSBlocks"] = "GetNumDSBlocks"; | ||
RPCMethod["GetDSBlockRate"] = "GetDSBlockRate"; | ||
RPCMethod["DSBlockListing"] = "DSBlockListing"; | ||
RPCMethod["GetTxBlock"] = "GetTxBlock"; | ||
RPCMethod["GetLatestTxBlock"] = "GetLatestTxBlock"; | ||
RPCMethod["GetNumTxBlocks"] = "GetNumTxBlocks"; | ||
RPCMethod["GetTxBlockRate"] = "GetTxBlockRate"; | ||
RPCMethod["TxBlockListing"] = "TxBlockListing"; | ||
RPCMethod["GetNumTransactions"] = "GetNumTransactions"; | ||
RPCMethod["GetTransactionRate"] = "GetTransactionRate"; | ||
RPCMethod["GetCurrentMiniEpoch"] = "GetCurrentMiniEpoch"; | ||
RPCMethod["GetCurrentDSEpoch"] = "GetCurrentDSEpoch"; | ||
RPCMethod["GetPrevDifficulty"] = "GetPrevDifficulty"; | ||
RPCMethod["GetPrevDSDifficulty"] = "GetPrevDSDifficulty"; | ||
// GetBlockTransactionCount = 'GetBlockTransactionCount', | ||
// Transaction-related methods | ||
RPCMethod["CreateTransaction"] = "CreateTransaction"; | ||
RPCMethod["GetTransaction"] = "GetTransaction"; | ||
// GetTransactionReceipt = 'GetTransactionReceipt', | ||
RPCMethod["GetRecentTransactions"] = "GetRecentTransactions"; | ||
RPCMethod["GetNumTxnsTxEpoch"] = "GetNumTxnsTxEpoch"; | ||
RPCMethod["GetNumTxnsDSEpoch"] = "GetNumTxnsDSEpoch"; | ||
RPCMethod["GetMinimumGasPrice"] = "GetMinimumGasPrice"; | ||
// GetGasEstimate = 'GetGasEstimate', | ||
// Contract-related methods | ||
RPCMethod["GetSmartContractCode"] = "GetSmartContractCode"; | ||
RPCMethod["GetSmartContractInit"] = "GetSmartContractInit"; | ||
RPCMethod["GetSmartContractState"] = "GetSmartContractState"; | ||
RPCMethod["GetContractAddressFromTransactionID"] = "GetContractAddressFromTransactionID"; | ||
// GetStorageAt = 'GetStorageAt', | ||
// Account-related methods | ||
RPCMethod["GetBalance"] = "GetBalance"; | ||
})(RPCMethod || (RPCMethod = {})); | ||
var RPCErrorCode; | ||
(function (RPCErrorCode) { | ||
// Standard JSON-RPC 2.0 errors | ||
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_REQUEST"] = -32600] = "RPC_INVALID_REQUEST"; | ||
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_NOT_FOUND"] = -32601] = "RPC_METHOD_NOT_FOUND"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMS"] = -32602] = "RPC_INVALID_PARAMS"; | ||
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind | ||
// (for example datadir corruption). | ||
RPCErrorCode[RPCErrorCode["RPC_INTERNAL_ERROR"] = -32603] = "RPC_INTERNAL_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_PARSE_ERROR"] = -32700] = "RPC_PARSE_ERROR"; | ||
// General application defined errors | ||
RPCErrorCode[RPCErrorCode["RPC_MISC_ERROR"] = -1] = "RPC_MISC_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_TYPE_ERROR"] = -3] = "RPC_TYPE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_ADDRESS_OR_KEY"] = -5] = "RPC_INVALID_ADDRESS_OR_KEY"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMETER"] = -8] = "RPC_INVALID_PARAMETER"; | ||
RPCErrorCode[RPCErrorCode["RPC_DATABASE_ERROR"] = -20] = "RPC_DATABASE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_DESERIALIZATION_ERROR"] = -22] = "RPC_DESERIALIZATION_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_ERROR"] = -25] = "RPC_VERIFY_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_REJECTED"] = -26] = "RPC_VERIFY_REJECTED"; | ||
RPCErrorCode[RPCErrorCode["RPC_IN_WARMUP"] = -28] = "RPC_IN_WARMUP"; | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_DEPRECATED"] = -32] = "RPC_METHOD_DEPRECATED"; | ||
})(RPCErrorCode || (RPCErrorCode = {})); | ||
var DEFAULT_HEADERS = { 'Content-Type': 'application/json' }; | ||
@@ -176,3 +250,3 @@ var performRPC = function (request, handler) { return __awaiter(_this, void 0, void 0, function () { | ||
.then(function (body) { | ||
return { result: body.result || body, req: request }; | ||
return __assign({}, body, { req: request }); | ||
}) | ||
@@ -188,2 +262,10 @@ .then(handler)]; | ||
function isValidResponse(response) { | ||
if (response.jsonrpc === '2.0' && | ||
(response.id === '1' || response.id === 1) && | ||
(response.error || response.result)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function composeMiddleware() { | ||
@@ -203,2 +285,7 @@ var fns = []; | ||
var MiddlewareType; | ||
(function (MiddlewareType) { | ||
MiddlewareType[MiddlewareType["REQ"] = 0] = "REQ"; | ||
MiddlewareType[MiddlewareType["RES"] = 1] = "RES"; | ||
})(MiddlewareType || (MiddlewareType = {})); | ||
var BaseProvider = /** @class */ (function () { | ||
@@ -342,3 +429,3 @@ function BaseProvider(nodeURL, reqMiddleware, resMiddleware) { | ||
export { Signer, sign, performRPC, composeMiddleware, HTTPProvider }; | ||
export { Signer, sign, RPCMethod, RPCErrorCode, performRPC, isValidResponse, composeMiddleware, HTTPProvider }; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -160,2 +160,70 @@ (function (global, factory) { | ||
var _this = undefined; | ||
(function (RPCMethod) { | ||
// Network-related methods | ||
RPCMethod["GetNetworkId"] = "GetNetworkId"; | ||
// GetClientVersion = 'GetClientVersion', | ||
// GetProtocolVersion = 'GetProtocolVersion', | ||
// Blockchain-related methods | ||
RPCMethod["GetBlockchainInfo"] = "GetBlockchainInfo"; | ||
RPCMethod["GetShardingStructure"] = "GetShardingStructure"; | ||
RPCMethod["GetDSBlock"] = "GetDsBlock"; | ||
RPCMethod["GetLatestDSBlock"] = "GetLatestDsBlock"; | ||
RPCMethod["GetNumDSBlocks"] = "GetNumDSBlocks"; | ||
RPCMethod["GetDSBlockRate"] = "GetDSBlockRate"; | ||
RPCMethod["DSBlockListing"] = "DSBlockListing"; | ||
RPCMethod["GetTxBlock"] = "GetTxBlock"; | ||
RPCMethod["GetLatestTxBlock"] = "GetLatestTxBlock"; | ||
RPCMethod["GetNumTxBlocks"] = "GetNumTxBlocks"; | ||
RPCMethod["GetTxBlockRate"] = "GetTxBlockRate"; | ||
RPCMethod["TxBlockListing"] = "TxBlockListing"; | ||
RPCMethod["GetNumTransactions"] = "GetNumTransactions"; | ||
RPCMethod["GetTransactionRate"] = "GetTransactionRate"; | ||
RPCMethod["GetCurrentMiniEpoch"] = "GetCurrentMiniEpoch"; | ||
RPCMethod["GetCurrentDSEpoch"] = "GetCurrentDSEpoch"; | ||
RPCMethod["GetPrevDifficulty"] = "GetPrevDifficulty"; | ||
RPCMethod["GetPrevDSDifficulty"] = "GetPrevDSDifficulty"; | ||
// GetBlockTransactionCount = 'GetBlockTransactionCount', | ||
// Transaction-related methods | ||
RPCMethod["CreateTransaction"] = "CreateTransaction"; | ||
RPCMethod["GetTransaction"] = "GetTransaction"; | ||
// GetTransactionReceipt = 'GetTransactionReceipt', | ||
RPCMethod["GetRecentTransactions"] = "GetRecentTransactions"; | ||
RPCMethod["GetNumTxnsTxEpoch"] = "GetNumTxnsTxEpoch"; | ||
RPCMethod["GetNumTxnsDSEpoch"] = "GetNumTxnsDSEpoch"; | ||
RPCMethod["GetMinimumGasPrice"] = "GetMinimumGasPrice"; | ||
// GetGasEstimate = 'GetGasEstimate', | ||
// Contract-related methods | ||
RPCMethod["GetSmartContractCode"] = "GetSmartContractCode"; | ||
RPCMethod["GetSmartContractInit"] = "GetSmartContractInit"; | ||
RPCMethod["GetSmartContractState"] = "GetSmartContractState"; | ||
RPCMethod["GetContractAddressFromTransactionID"] = "GetContractAddressFromTransactionID"; | ||
// GetStorageAt = 'GetStorageAt', | ||
// Account-related methods | ||
RPCMethod["GetBalance"] = "GetBalance"; | ||
})(exports.RPCMethod || (exports.RPCMethod = {})); | ||
(function (RPCErrorCode) { | ||
// Standard JSON-RPC 2.0 errors | ||
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_REQUEST"] = -32600] = "RPC_INVALID_REQUEST"; | ||
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_NOT_FOUND"] = -32601] = "RPC_METHOD_NOT_FOUND"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMS"] = -32602] = "RPC_INVALID_PARAMS"; | ||
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind | ||
// (for example datadir corruption). | ||
RPCErrorCode[RPCErrorCode["RPC_INTERNAL_ERROR"] = -32603] = "RPC_INTERNAL_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_PARSE_ERROR"] = -32700] = "RPC_PARSE_ERROR"; | ||
// General application defined errors | ||
RPCErrorCode[RPCErrorCode["RPC_MISC_ERROR"] = -1] = "RPC_MISC_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_TYPE_ERROR"] = -3] = "RPC_TYPE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_ADDRESS_OR_KEY"] = -5] = "RPC_INVALID_ADDRESS_OR_KEY"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMETER"] = -8] = "RPC_INVALID_PARAMETER"; | ||
RPCErrorCode[RPCErrorCode["RPC_DATABASE_ERROR"] = -20] = "RPC_DATABASE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_DESERIALIZATION_ERROR"] = -22] = "RPC_DESERIALIZATION_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_ERROR"] = -25] = "RPC_VERIFY_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_REJECTED"] = -26] = "RPC_VERIFY_REJECTED"; | ||
RPCErrorCode[RPCErrorCode["RPC_IN_WARMUP"] = -28] = "RPC_IN_WARMUP"; | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_DEPRECATED"] = -32] = "RPC_METHOD_DEPRECATED"; | ||
})(exports.RPCErrorCode || (exports.RPCErrorCode = {})); | ||
var DEFAULT_HEADERS = { 'Content-Type': 'application/json' }; | ||
@@ -182,3 +250,3 @@ var performRPC = function (request, handler) { return __awaiter(_this, void 0, void 0, function () { | ||
.then(function (body) { | ||
return { result: body.result || body, req: request }; | ||
return __assign({}, body, { req: request }); | ||
}) | ||
@@ -194,2 +262,10 @@ .then(handler)]; | ||
function isValidResponse(response) { | ||
if (response.jsonrpc === '2.0' && | ||
(response.id === '1' || response.id === 1) && | ||
(response.error || response.result)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function composeMiddleware() { | ||
@@ -209,2 +285,7 @@ var fns = []; | ||
var MiddlewareType; | ||
(function (MiddlewareType) { | ||
MiddlewareType[MiddlewareType["REQ"] = 0] = "REQ"; | ||
MiddlewareType[MiddlewareType["RES"] = 1] = "RES"; | ||
})(MiddlewareType || (MiddlewareType = {})); | ||
var BaseProvider = /** @class */ (function () { | ||
@@ -351,2 +432,3 @@ function BaseProvider(nodeURL, reqMiddleware, resMiddleware) { | ||
exports.performRPC = performRPC; | ||
exports.isValidResponse = isValidResponse; | ||
exports.composeMiddleware = composeMiddleware; | ||
@@ -353,0 +435,0 @@ exports.HTTPProvider = HTTPProvider; |
@@ -38,2 +38,19 @@ import { WithRequest } from './util'; | ||
} | ||
export declare const enum RPCErrorCode { | ||
RPC_INVALID_REQUEST = -32600, | ||
RPC_METHOD_NOT_FOUND = -32601, | ||
RPC_INVALID_PARAMS = -32602, | ||
RPC_INTERNAL_ERROR = -32603, | ||
RPC_PARSE_ERROR = -32700, | ||
RPC_MISC_ERROR = -1, | ||
RPC_TYPE_ERROR = -3, | ||
RPC_INVALID_ADDRESS_OR_KEY = -5, | ||
RPC_INVALID_PARAMETER = -8, | ||
RPC_DATABASE_ERROR = -20, | ||
RPC_DESERIALIZATION_ERROR = -22, | ||
RPC_VERIFY_ERROR = -25, | ||
RPC_VERIFY_REJECTED = -26, | ||
RPC_IN_WARMUP = -28, | ||
RPC_METHOD_DEPRECATED = -32 | ||
} | ||
export interface RPCRequestPayload<T> { | ||
@@ -54,11 +71,19 @@ id: 1; | ||
} | ||
export interface RPCResponseSuccess<R = any> { | ||
interface RPCResponseBase { | ||
jsonrpc: '2.0'; | ||
id: '1'; | ||
} | ||
export interface RPCResponseSuccess<R = any> extends RPCResponseBase { | ||
result: R; | ||
error: undefined; | ||
} | ||
export interface RPCResponseError<E> { | ||
result: { | ||
error: E; | ||
Error: E; | ||
}; | ||
export interface RPCResponseError<E = any> extends RPCResponseBase { | ||
result: undefined; | ||
error: RPCError<E>; | ||
} | ||
export interface RPCError<E> { | ||
code: RPCErrorCode; | ||
message: string; | ||
data?: E; | ||
} | ||
export declare type RPCResponse<R, E> = RPCResponseSuccess<R> | RPCResponseError<E>; | ||
@@ -65,0 +90,0 @@ export declare type RPCResponseHandler<R, E, T> = (response: WithRequest<RPCResponse<R, E>>) => T; |
@@ -6,2 +6,76 @@ "use strict"; | ||
var cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch")); | ||
/** | ||
* TODO: Enable commented-out methods when they are implemented | ||
* blockchain-side. | ||
*/ | ||
var RPCMethod; | ||
(function (RPCMethod) { | ||
// Network-related methods | ||
RPCMethod["GetNetworkId"] = "GetNetworkId"; | ||
// GetClientVersion = 'GetClientVersion', | ||
// GetProtocolVersion = 'GetProtocolVersion', | ||
// Blockchain-related methods | ||
RPCMethod["GetBlockchainInfo"] = "GetBlockchainInfo"; | ||
RPCMethod["GetShardingStructure"] = "GetShardingStructure"; | ||
RPCMethod["GetDSBlock"] = "GetDsBlock"; | ||
RPCMethod["GetLatestDSBlock"] = "GetLatestDsBlock"; | ||
RPCMethod["GetNumDSBlocks"] = "GetNumDSBlocks"; | ||
RPCMethod["GetDSBlockRate"] = "GetDSBlockRate"; | ||
RPCMethod["DSBlockListing"] = "DSBlockListing"; | ||
RPCMethod["GetTxBlock"] = "GetTxBlock"; | ||
RPCMethod["GetLatestTxBlock"] = "GetLatestTxBlock"; | ||
RPCMethod["GetNumTxBlocks"] = "GetNumTxBlocks"; | ||
RPCMethod["GetTxBlockRate"] = "GetTxBlockRate"; | ||
RPCMethod["TxBlockListing"] = "TxBlockListing"; | ||
RPCMethod["GetNumTransactions"] = "GetNumTransactions"; | ||
RPCMethod["GetTransactionRate"] = "GetTransactionRate"; | ||
RPCMethod["GetCurrentMiniEpoch"] = "GetCurrentMiniEpoch"; | ||
RPCMethod["GetCurrentDSEpoch"] = "GetCurrentDSEpoch"; | ||
RPCMethod["GetPrevDifficulty"] = "GetPrevDifficulty"; | ||
RPCMethod["GetPrevDSDifficulty"] = "GetPrevDSDifficulty"; | ||
// GetBlockTransactionCount = 'GetBlockTransactionCount', | ||
// Transaction-related methods | ||
RPCMethod["CreateTransaction"] = "CreateTransaction"; | ||
RPCMethod["GetTransaction"] = "GetTransaction"; | ||
// GetTransactionReceipt = 'GetTransactionReceipt', | ||
RPCMethod["GetRecentTransactions"] = "GetRecentTransactions"; | ||
RPCMethod["GetNumTxnsTxEpoch"] = "GetNumTxnsTxEpoch"; | ||
RPCMethod["GetNumTxnsDSEpoch"] = "GetNumTxnsDSEpoch"; | ||
RPCMethod["GetMinimumGasPrice"] = "GetMinimumGasPrice"; | ||
// GetGasEstimate = 'GetGasEstimate', | ||
// Contract-related methods | ||
RPCMethod["GetSmartContractCode"] = "GetSmartContractCode"; | ||
RPCMethod["GetSmartContractInit"] = "GetSmartContractInit"; | ||
RPCMethod["GetSmartContractState"] = "GetSmartContractState"; | ||
RPCMethod["GetContractAddressFromTransactionID"] = "GetContractAddressFromTransactionID"; | ||
// GetStorageAt = 'GetStorageAt', | ||
// Account-related methods | ||
RPCMethod["GetBalance"] = "GetBalance"; | ||
})(RPCMethod = exports.RPCMethod || (exports.RPCMethod = {})); | ||
var RPCErrorCode; | ||
(function (RPCErrorCode) { | ||
// Standard JSON-RPC 2.0 errors | ||
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_REQUEST"] = -32600] = "RPC_INVALID_REQUEST"; | ||
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404). | ||
// It should not be used for application-layer errors. | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_NOT_FOUND"] = -32601] = "RPC_METHOD_NOT_FOUND"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMS"] = -32602] = "RPC_INVALID_PARAMS"; | ||
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind | ||
// (for example datadir corruption). | ||
RPCErrorCode[RPCErrorCode["RPC_INTERNAL_ERROR"] = -32603] = "RPC_INTERNAL_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_PARSE_ERROR"] = -32700] = "RPC_PARSE_ERROR"; | ||
// General application defined errors | ||
RPCErrorCode[RPCErrorCode["RPC_MISC_ERROR"] = -1] = "RPC_MISC_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_TYPE_ERROR"] = -3] = "RPC_TYPE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_ADDRESS_OR_KEY"] = -5] = "RPC_INVALID_ADDRESS_OR_KEY"; | ||
RPCErrorCode[RPCErrorCode["RPC_INVALID_PARAMETER"] = -8] = "RPC_INVALID_PARAMETER"; | ||
RPCErrorCode[RPCErrorCode["RPC_DATABASE_ERROR"] = -20] = "RPC_DATABASE_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_DESERIALIZATION_ERROR"] = -22] = "RPC_DESERIALIZATION_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_ERROR"] = -25] = "RPC_VERIFY_ERROR"; | ||
RPCErrorCode[RPCErrorCode["RPC_VERIFY_REJECTED"] = -26] = "RPC_VERIFY_REJECTED"; | ||
RPCErrorCode[RPCErrorCode["RPC_IN_WARMUP"] = -28] = "RPC_IN_WARMUP"; | ||
RPCErrorCode[RPCErrorCode["RPC_METHOD_DEPRECATED"] = -32] = "RPC_METHOD_DEPRECATED"; | ||
})(RPCErrorCode = exports.RPCErrorCode || (exports.RPCErrorCode = {})); | ||
var DEFAULT_HEADERS = { 'Content-Type': 'application/json' }; | ||
@@ -28,3 +102,3 @@ exports.performRPC = function (request, handler) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
.then(function (body) { | ||
return { result: body.result || body, req: request }; | ||
return tslib_1.__assign({}, body, { req: request }); | ||
}) | ||
@@ -31,0 +105,0 @@ .then(handler)]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var MiddlewareType; | ||
(function (MiddlewareType) { | ||
MiddlewareType[MiddlewareType["REQ"] = 0] = "REQ"; | ||
MiddlewareType[MiddlewareType["RES"] = 1] = "RES"; | ||
})(MiddlewareType || (MiddlewareType = {})); | ||
var BaseProvider = /** @class */ (function () { | ||
@@ -5,0 +10,0 @@ function BaseProvider(nodeURL, reqMiddleware, resMiddleware) { |
@@ -17,4 +17,5 @@ import { RPCMethod, RPCRequest, RPCResponse } from './net'; | ||
export declare type ResMiddlewareFn<I = any, O = any, E = any> = Transformer<WithRequest<RPCResponse<I, E>>, WithRequest<RPCResponse<O, E>>>; | ||
export declare function isValidResponse<T, E>(response: any): response is RPCResponse<T, E>; | ||
export declare function composeMiddleware<T extends ReqMiddlewareFn[]>(...fns: T): ReqMiddlewareFn; | ||
export declare function composeMiddleware<T extends ResMiddlewareFn[]>(...fns: T): ResMiddlewareFn; | ||
//# sourceMappingURL=util.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isValidResponse(response) { | ||
if (response.jsonrpc === '2.0' && | ||
(response.id === '1' || response.id === 1) && | ||
(response.error || response.result)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
exports.isValidResponse = isValidResponse; | ||
function composeMiddleware() { | ||
@@ -4,0 +13,0 @@ var fns = []; |
{ | ||
"name": "@zilliqa-js/core", | ||
"version": "0.2.10", | ||
"version": "0.3.0", | ||
"description": "Core abstractions that power the zilliqa JS client.", | ||
@@ -22,2 +22,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@zilliqa-js/util": "0.3.0", | ||
"axios": "^0.18.0", | ||
@@ -27,3 +28,3 @@ "cross-fetch": "^2.2.2", | ||
}, | ||
"gitHead": "5c213717525c658e5ac1a9c1efeb46bdd856e204" | ||
"gitHead": "7099301a8c3cde45cf083f9f947ba6461001c927" | ||
} |
import fetch from 'cross-fetch'; | ||
// import { validation } from '@zilliqa-js/util'; | ||
import { WithRequest } from './util'; | ||
@@ -56,2 +57,29 @@ | ||
export const enum RPCErrorCode { | ||
// Standard JSON-RPC 2.0 errors | ||
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400). | ||
// It should not be used for application-layer errors. | ||
RPC_INVALID_REQUEST = -32600, | ||
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404). | ||
// It should not be used for application-layer errors. | ||
RPC_METHOD_NOT_FOUND = -32601, | ||
RPC_INVALID_PARAMS = -32602, | ||
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind | ||
// (for example datadir corruption). | ||
RPC_INTERNAL_ERROR = -32603, | ||
RPC_PARSE_ERROR = -32700, | ||
// General application defined errors | ||
RPC_MISC_ERROR = -1, // std::exception thrown in command handling | ||
RPC_TYPE_ERROR = -3, // Unexpected type was passed as parameter | ||
RPC_INVALID_ADDRESS_OR_KEY = -5, // Invalid address or key | ||
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter | ||
RPC_DATABASE_ERROR = -20, // Database error | ||
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format | ||
RPC_VERIFY_ERROR = -25, // General error during transaction or block submission | ||
RPC_VERIFY_REJECTED = -26, // Transaction or block was rejected by network rules | ||
RPC_IN_WARMUP = -28, // Client still warming up | ||
RPC_METHOD_DEPRECATED = -32, // RPC method is deprecated | ||
} | ||
export interface RPCRequestPayload<T> { | ||
@@ -75,10 +103,23 @@ id: 1; | ||
export interface RPCResponseSuccess<R = any> { | ||
interface RPCResponseBase { | ||
jsonrpc: '2.0'; | ||
id: '1'; | ||
} | ||
export interface RPCResponseSuccess<R = any> extends RPCResponseBase { | ||
result: R; | ||
error: undefined; | ||
} | ||
export interface RPCResponseError<E> { | ||
result: { error: E; Error: E }; | ||
export interface RPCResponseError<E = any> extends RPCResponseBase { | ||
result: undefined; | ||
error: RPCError<E>; | ||
} | ||
export interface RPCError<E> { | ||
code: RPCErrorCode; | ||
message: string; | ||
data?: E; | ||
} | ||
export type RPCResponse<R, E> = RPCResponseSuccess<R> | RPCResponseError<E>; | ||
@@ -113,3 +154,3 @@ | ||
.then((body) => { | ||
return { result: body.result || body, req: request }; | ||
return { ...body, req: request }; | ||
}) | ||
@@ -116,0 +157,0 @@ .then(handler); |
@@ -27,2 +27,16 @@ import { RPCMethod, RPCRequest, RPCResponse } from './net'; | ||
export function isValidResponse<T, E>( | ||
response: any, | ||
): response is RPCResponse<T, E> { | ||
if ( | ||
response.jsonrpc === '2.0' && | ||
(response.id === '1' || response.id === 1) && | ||
(response.error || response.result) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
export function composeMiddleware<T extends ReqMiddlewareFn[]>( | ||
@@ -29,0 +43,0 @@ ...fns: T |
@@ -10,4 +10,6 @@ import { ReqMiddlewareFn, ResMiddlewareFn } from '../src/util'; | ||
export const mockResMiddleware: ResMiddlewareFn = (res) => { | ||
if (typeof res.result === 'string') { | ||
export const mockResMiddleware: ResMiddlewareFn<string, string, never> = ( | ||
res, | ||
) => { | ||
if (res.result && typeof res.result === 'string') { | ||
return { ...res, result: res.result.toUpperCase() }; | ||
@@ -14,0 +16,0 @@ } |
@@ -54,3 +54,9 @@ import fetch from 'jest-fetch-mock'; | ||
fetch.mockResponseOnce(JSON.stringify('something')); | ||
fetch.mockResponseOnce( | ||
JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: '1', | ||
result: 'something', | ||
}), | ||
); | ||
const res = await withMiddleware.send( | ||
@@ -57,0 +63,0 @@ RPCMethod.CreateTransaction, |
@@ -7,4 +7,3 @@ { | ||
}, | ||
"include": ["src", "../../typings/**/*.d.ts"], | ||
"references": [] | ||
"include": ["src", "../../typings/**/*.d.ts"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
177833
2111
4
+ Added@zilliqa-js/util@0.3.0
+ Added@types/bn.js@4.11.6(transitive)
+ Added@types/long@4.0.2(transitive)
+ Added@types/node@22.10.0(transitive)
+ Added@zilliqa-js/util@0.3.0(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedundici-types@6.20.0(transitive)