@@ -23,12 +23,10 @@ import constants from '../../lib/constants';
2323export class JsonRpcError {
2424 public code : number ;
2525 public message : string ;
26- public name ?: string ;
2726 public data ?: string ;
2827
29- constructor ( args : { name ?: string ; code : number ; message : string ; data ?: string } , requestId ?: string ) {
28+ constructor ( args : { code : number ; message : string ; data ?: string } , requestId ?: string ) {
3029 this . code = args . code ;
31- this . name = args . name ;
3230 this . message = requestId ? `[${ constants . REQUEST_ID_STRING } ${ requestId } ] ` + args . message : args . message ;
3331 this . data = args . data ;
3432 }
@@ -43,139 +41,114 @@ export const predefined = {
4341 } ) ,
4442 GAS_LIMIT_TOO_HIGH : ( gasLimit , maxGas ) =>
4543 new JsonRpcError ( {
46- name : 'gasLimit too high' ,
4744 code : - 32005 ,
4845 message : `Transaction gas limit '${ gasLimit } ' exceeds block gas limit '${ maxGas } '` ,
4946 } ) ,
5047 GAS_LIMIT_TOO_LOW : ( gasLimit , requiredGas ) =>
5148 new JsonRpcError ( {
52- name : 'gasLimit too low' ,
5349 code : - 32003 ,
5450 message : `Transaction gas limit provided '${ gasLimit } ' is insufficient of intrinsic gas required '${ requiredGas } '` ,
5551 } ) ,
5652 GAS_PRICE_TOO_LOW : ( gasPrice , minGasPrice ) =>
5753 new JsonRpcError ( {
58- name : 'Gas price too low' ,
5954 code : - 32009 ,
6055 message : `Gas price '${ gasPrice } ' is below configured minimum gas price '${ minGasPrice } '` ,
6156 } ) ,
6257 HBAR_RATE_LIMIT_EXCEEDED : new JsonRpcError ( {
63- name : 'HBAR Rate limit exceeded' ,
6458 code : - 32606 ,
6559 message : 'HBAR Rate limit exceeded' ,
6660 } ) ,
6761 INSUFFICIENT_ACCOUNT_BALANCE : new JsonRpcError ( {
68- name : 'Insufficient account balance' ,
6962 code : - 32000 ,
7063 message : 'Insufficient funds for transfer' ,
7164 } ) ,
7265 INTERNAL_ERROR : ( message = '' ) =>
7366 new JsonRpcError ( {
74- name : 'Internal error' ,
7567 code : - 32603 ,
7668 message : message === '' || undefined ? 'Unknown error invoking RPC' : `Error invoking RPC: ${ message } ` ,
7769 } ) ,
7870 INVALID_PARAMETER : ( index : number | string , message : string ) =>
7971 new JsonRpcError ( {
80- name : 'Invalid parameter' ,
8172 code : - 32602 ,
8273 message : `Invalid parameter ${ index } : ${ message } ` ,
8374 } ) ,
8475 INVALID_PARAMETERS : new JsonRpcError ( {
85- name : 'Invalid parameters' ,
8676 code : - 32602 ,
8777 message : 'Invalid params' ,
8878 } ) ,
8979 INVALID_REQUEST : new JsonRpcError ( {
90- name : 'Invalid request' ,
9180 code : - 32600 ,
9281 message : 'Invalid request' ,
9382 } ) ,
9483 IP_RATE_LIMIT_EXCEEDED : ( methodName : string ) =>
9584 new JsonRpcError ( {
96- name : 'IP Rate limit exceeded' ,
9785 code : - 32605 ,
9886 message : `IP Rate limit exceeded on ${ methodName } ` ,
9987 } ) ,
10088 MISSING_FROM_BLOCK_PARAM : new JsonRpcError ( {
101- name : 'Missing fromBlock parameter' ,
10289 code : - 32011 ,
10390 message : 'Provided toBlock parameter without specifying fromBlock' ,
10491 } ) ,
10592 MISSING_REQUIRED_PARAMETER : ( index : number | string ) =>
10693 new JsonRpcError ( {
107- name : 'Missing required parameters' ,
10894 code : - 32602 ,
10995 message : `Missing value for required parameter ${ index } ` ,
11096 } ) ,
11197 NONCE_TOO_LOW : ( nonce , currentNonce ) =>
11298 new JsonRpcError ( {
113- name : 'Nonce too low' ,
11499 code : 32001 ,
115100 message : `Nonce too low. Provided nonce: ${ nonce } , current nonce: ${ currentNonce } ` ,
116101 } ) ,
117102 NONCE_TOO_HIGH : ( nonce , currentNonce ) =>
118103 new JsonRpcError ( {
119- name : 'Nonce too high' ,
120104 code : 32002 ,
121105 message : `Nonce too high. Provided nonce: ${ nonce } , current nonce: ${ currentNonce } ` ,
122106 } ) ,
123107 NO_MINING_WORK : new JsonRpcError ( {
124- name : 'No mining work' ,
125108 code : - 32000 ,
126109 message : 'No mining work available yet' ,
127110 } ) ,
128111 PARSE_ERROR : new JsonRpcError ( {
129- name : 'Parse error' ,
130112 code : - 32700 ,
131113 message : 'Unable to parse JSON' ,
132114 } ) ,
133115 RANGE_TOO_LARGE : ( blockRange : number ) =>
134116 new JsonRpcError ( {
135- name : 'Block range too large' ,
136117 code : - 32000 ,
137118 message : `Exceeded maximum block range: ${ blockRange } ` ,
138119 } ) ,
139120 REQUEST_BEYOND_HEAD_BLOCK : ( requested : number , latest : number ) =>
140121 new JsonRpcError ( {
141- name : 'Incorrect block' ,
142122 code : - 32000 ,
143123 message : `Request beyond head block: requested ${ requested } , head ${ latest } ` ,
144124 } ) ,
145125 REQUEST_TIMEOUT : new JsonRpcError ( {
146- name : 'Request timeout' ,
147126 code : - 32010 ,
148127 message : 'Request timeout. Please try again.' ,
149128 } ) ,
150129 RESOURCE_NOT_FOUND : ( message = '' ) =>
151130 new JsonRpcError ( {
152- name : 'Resource not found' ,
153131 code : - 32001 ,
154132 message : `Requested resource not found. ${ message } ` ,
155133 } ) ,
156134 UNKNOWN_HISTORICAL_BALANCE : new JsonRpcError ( {
157- name : 'Unavailable balance' ,
158135 code : - 32007 ,
159136 message : 'Historical balance data is available only after 15 minutes.' ,
160137 } ) ,
161138 UNSUPPORTED_CHAIN_ID : ( requested : string | number , current : string | number ) =>
162139 new JsonRpcError ( {
163- name : 'ChainId not supported' ,
164140 code : - 32000 ,
165141 message : `ChainId (${ requested } ) not supported. The correct chainId is ${ current } ` ,
166142 } ) ,
167143 UNSUPPORTED_METHOD : new JsonRpcError ( {
168- name : 'Method not found' ,
169144 code : - 32601 ,
170145 message : 'Unsupported JSON-RPC method' ,
171146 } ) ,
172147 UNSUPPORTED_TRANSACTION_TYPE : new JsonRpcError ( {
173- name : 'Unsupported transaction type' ,
174148 code : - 32611 ,
175149 message : 'Unsupported transaction type' ,
176150 } ) ,
177151 VALUE_TOO_LOW : new JsonRpcError ( {
178- name : 'Value too low' ,
179152 code : - 32602 ,
180153 message : 'Value below 10_000_000_000 wei which is 1 tinybar' ,
181154 } ) ,
@@ -186,7 +159,6 @@ export const predefined = {
186159 }
187160
188161 return new JsonRpcError ( {
189- name : 'Invalid Contract Address' ,
190162 code : - 32012 ,
191163 message : message ,
192164 } ) ;
@@ -198,7 +170,6 @@ export const predefined = {
198170 }
199171
200172 return new JsonRpcError ( {
201- name : 'Non Existing Contract Address' ,
202173 code : - 32013 ,
203174 message : message ,
204175 } ) ;
@@ -210,97 +181,80 @@ export const predefined = {
210181 }
211182
212183 return new JsonRpcError ( {
213- name : 'Non Existing Account Address' ,
214184 code : - 32014 ,
215185 message : message ,
216186 } ) ;
217187 } ,
218188 COULD_NOT_ESTIMATE_GAS_PRICE : new JsonRpcError ( {
219- name : 'Could not estimate gas price' ,
220189 code : - 32604 ,
221190 message : 'Error encountered estimating the gas price' ,
222191 } ) ,
223192 COULD_NOT_RETRIEVE_LATEST_BLOCK : new JsonRpcError ( {
224- name : 'Could not retrieve latest block' ,
225193 code : - 32607 ,
226194 message : 'Error encountered retrieving latest block' ,
227195 } ) ,
228196 MAX_SUBSCRIPTIONS : new JsonRpcError ( {
229- name : 'Exceeded maximum allowed subscriptions' ,
230197 code : - 32608 ,
231198 message : 'Exceeded maximum allowed subscriptions' ,
232199 } ) ,
233200 UNSUPPORTED_HISTORICAL_EXECUTION : ( blockId : string ) =>
234201 new JsonRpcError ( {
235- name : 'Unsupported historical block request' ,
236202 code : - 32609 ,
237203 message : `Unsupported historical block identifier encountered: ${ blockId } ` ,
238204 } ) ,
239205 UNSUPPORTED_OPERATION : ( message : string ) =>
240206 new JsonRpcError ( {
241- name : 'Unsupported operation' ,
242207 code : - 32610 ,
243208 message : `Unsupported operation. ${ message } ` ,
244209 } ) ,
245210 PAGINATION_MAX : ( count : number ) =>
246211 new JsonRpcError ( {
247- name : 'Mirror Node pagination count range too large' ,
248212 code : - 32011 ,
249213 message : `Exceeded maximum mirror node pagination count: ${ count } ` ,
250214 } ) ,
251215 MAX_BLOCK_SIZE : ( count : number ) =>
252216 new JsonRpcError ( {
253- name : 'Block size too large' ,
254217 code : - 32000 ,
255218 message : `Exceeded max transactions that can be returned in a block: ${ count } ` ,
256219 } ) ,
257220 UNKNOWN_BLOCK : ( msg ?: string | null ) =>
258221 new JsonRpcError ( {
259- name : 'Unknown block' ,
260222 code : - 39012 ,
261223 message : msg || 'Unknown block' ,
262224 } ) ,
263225 INVALID_BLOCK_RANGE : new JsonRpcError ( {
264- name : 'Invalid block range' ,
265226 code : - 39013 ,
266227 message : 'Invalid block range' ,
267228 } ) ,
268229 FILTER_NOT_FOUND : new JsonRpcError ( {
269- name : 'Filter not found' ,
270230 code : - 32001 ,
271231 message : 'Filter not found' ,
272232 } ) ,
273233 TRANSACTION_SIZE_TOO_BIG : ( actualSize : string , expectedSize : string ) =>
274234 new JsonRpcError ( {
275- name : 'Transaction size too big' ,
276235 code : - 32201 ,
277236 message : `Oversized data: transaction size ${ actualSize } , transaction limit ${ expectedSize } ` ,
278237 } ) ,
279238 BATCH_REQUESTS_DISABLED : new JsonRpcError ( {
280- name : 'Batch requests disabled' ,
281239 code : - 32202 ,
282240 message : 'Batch requests are disabled' ,
283241 } ) ,
284242 BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED : ( amount : number , max : number ) =>
285243 new JsonRpcError ( {
286- name : 'Batch requests amount max exceeded' ,
287244 code : - 32203 ,
288245 message : `Batch request amount ${ amount } exceeds max ${ max } ` ,
289246 } ) ,
290247 WS_BATCH_REQUESTS_DISABLED : new JsonRpcError ( {
291- name : 'WS batch requests disabled' ,
292248 code : - 32205 ,
293249 message : 'WS batch requests are disabled' ,
294250 } ) ,
295251 WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED : ( amount : number , max : number ) =>
296252 new JsonRpcError ( {
297- name : 'WS batch requests amount max exceeded' ,
298253 code : - 32206 ,
299254 message : `Batch request amount ${ amount } exceeds max ${ max } ` ,
300255 } ) ,
301256 INVALID_ARGUMENTS : ( message : string ) =>
302257 new JsonRpcError ( {
303- name : 'Invalid argument' ,
304258 code : - 32000 ,
305259 message : `Invalid arguments: ${ message } ` ,
306260 } ) ,
0 commit comments