@qevm/logger 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ Logger
2
+ ======
3
+
4
+ This sub-module is part of the qethers project, a fork of [ethers project](https://github.com/ethers-io/ethers.js).
5
+
6
+ It is responsible for managing logging and errors to maintain a standard
7
+ structure.
8
+
9
+
10
+ Importing
11
+ ---------
12
+
13
+ Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/@qevm/qethers),
14
+ but for those with more specific needs, individual components can be imported.
15
+
16
+ ```javascript
17
+ const {
18
+
19
+ Logger,
20
+
21
+ // Enums
22
+
23
+ ErrorCode,
24
+
25
+ LogLevel,
26
+
27
+ } = require("@qevm/logger");
28
+ ```
29
+
30
+
31
+ License
32
+ -------
33
+
34
+ MIT License.
@@ -0,0 +1,2 @@
1
+ export declare const version = "logger/5.7.1";
2
+ //# sourceMappingURL=_version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_version.d.ts","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ exports.version = "logger/5.7.1";
5
+ //# sourceMappingURL=_version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,cAAc,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = "DEBUG",
3
+ INFO = "INFO",
4
+ WARNING = "WARNING",
5
+ ERROR = "ERROR",
6
+ OFF = "OFF"
7
+ }
8
+ export declare enum ErrorCode {
9
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
10
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
11
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
12
+ NETWORK_ERROR = "NETWORK_ERROR",
13
+ SERVER_ERROR = "SERVER_ERROR",
14
+ TIMEOUT = "TIMEOUT",
15
+ BUFFER_OVERRUN = "BUFFER_OVERRUN",
16
+ NUMERIC_FAULT = "NUMERIC_FAULT",
17
+ MISSING_NEW = "MISSING_NEW",
18
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
19
+ MISSING_ARGUMENT = "MISSING_ARGUMENT",
20
+ UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT",
21
+ CALL_EXCEPTION = "CALL_EXCEPTION",
22
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
23
+ NONCE_EXPIRED = "NONCE_EXPIRED",
24
+ REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED",
25
+ UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
26
+ TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
27
+ ACTION_REJECTED = "ACTION_REJECTED"
28
+ }
29
+ export declare class Logger {
30
+ readonly version: string;
31
+ static errors: typeof ErrorCode;
32
+ static levels: typeof LogLevel;
33
+ constructor(version: string);
34
+ _log(logLevel: LogLevel, args: Array<any>): void;
35
+ debug(...args: Array<any>): void;
36
+ info(...args: Array<any>): void;
37
+ warn(...args: Array<any>): void;
38
+ makeError(message: string, code?: ErrorCode, params?: any): Error;
39
+ throwError(message: string, code?: ErrorCode, params?: any): never;
40
+ throwArgumentError(message: string, name: string, value: any): never;
41
+ assert(condition: any, message: string, code?: ErrorCode, params?: any): void;
42
+ assertArgument(condition: any, message: string, name: string, value: any): void;
43
+ checkNormalize(message?: string): void;
44
+ checkSafeUint53(value: number, message?: string): void;
45
+ checkArgumentCount(count: number, expectedCount: number, message?: string): void;
46
+ checkNew(target: any, kind: any): void;
47
+ checkAbstract(target: any, kind: any): void;
48
+ static globalLogger(): Logger;
49
+ static setCensorship(censorship: boolean, permanent?: boolean): void;
50
+ static setLogLevel(logLevel: LogLevel): void;
51
+ static from(version: string): Logger;
52
+ }
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAqDA,oBAAY,QAAQ;IAChB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,GAAG,QAAQ;CACd;AAED,oBAAY,SAAS;IAKjB,aAAa,kBAAkB;IAG/B,eAAe,oBAAoB;IAInC,qBAAqB,0BAA0B;IAI/C,aAAa,kBAAkB;IAG/B,YAAY,iBAAiB;IAG7B,OAAO,YAAY;IAMnB,cAAc,mBAAmB;IAKjC,aAAa,kBAAkB;IAO/B,WAAW,gBAAgB;IAK3B,gBAAgB,qBAAqB;IAKrC,gBAAgB,qBAAqB;IAKrC,mBAAmB,wBAAwB;IAa3C,cAAc,mBAAmB;IAIjC,kBAAkB,uBAAuB;IAIzC,aAAa,kBAAkB;IAI/B,uBAAuB,4BAA4B;IAInD,uBAAuB,4BAA4B;IAQnD,oBAAoB,yBAAyB;IAO7C,eAAe,oBAAoB;CACtC;AAID,qBAAa,MAAM;IACf,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,MAAM,CAAC,MAAM,mBAAa;IAE1B,MAAM,CAAC,MAAM,kBAAY;gBAEb,OAAO,EAAE,MAAM;IAQ3B,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI;IAehD,KAAK,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI;IAIhC,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI;IAI/B,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CA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
package/lib/index.js ADDED
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = exports.ErrorCode = exports.LogLevel = void 0;
4
+ let _permanentCensorErrors = false;
5
+ let _censorErrors = false;
6
+ const LogLevels = {
7
+ debug: 1,
8
+ default: 2,
9
+ info: 2,
10
+ warning: 3,
11
+ error: 4,
12
+ off: 5,
13
+ };
14
+ let _logLevel = LogLevels["default"];
15
+ const _version_1 = require("./_version");
16
+ let _globalLogger = null;
17
+ function _checkNormalize() {
18
+ try {
19
+ const missing = [];
20
+ // Make sure all forms of normalization are supported
21
+ ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
22
+ try {
23
+ if ("test".normalize(form) !== "test") {
24
+ throw new Error("bad normalize");
25
+ }
26
+ }
27
+ catch (error) {
28
+ missing.push(form);
29
+ }
30
+ });
31
+ if (missing.length) {
32
+ throw new Error("missing " + missing.join(", "));
33
+ }
34
+ if (String.fromCharCode(0xe9).normalize("NFD") !==
35
+ String.fromCharCode(0x65, 0x0301)) {
36
+ throw new Error("broken implementation");
37
+ }
38
+ }
39
+ catch (error) {
40
+ return error.message;
41
+ }
42
+ return null;
43
+ }
44
+ const _normalizeError = _checkNormalize();
45
+ var LogLevel;
46
+ (function (LogLevel) {
47
+ LogLevel["DEBUG"] = "DEBUG";
48
+ LogLevel["INFO"] = "INFO";
49
+ LogLevel["WARNING"] = "WARNING";
50
+ LogLevel["ERROR"] = "ERROR";
51
+ LogLevel["OFF"] = "OFF";
52
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
53
+ var ErrorCode;
54
+ (function (ErrorCode) {
55
+ ///////////////////
56
+ // Generic Errors
57
+ // Unknown Error
58
+ ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
59
+ // Not Implemented
60
+ ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
61
+ // Unsupported Operation
62
+ // - operation
63
+ ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
64
+ // Network Error (i.e. Ethereum Network, such as an invalid chain ID)
65
+ // - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
66
+ ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
67
+ // Some sort of bad response from the server
68
+ ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
69
+ // Timeout
70
+ ErrorCode["TIMEOUT"] = "TIMEOUT";
71
+ ///////////////////
72
+ // Operational Errors
73
+ // Buffer Overrun
74
+ ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
75
+ // Numeric Fault
76
+ // - operation: the operation being executed
77
+ // - fault: the reason this faulted
78
+ ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
79
+ ///////////////////
80
+ // Argument Errors
81
+ // Missing new operator to an object
82
+ // - name: The name of the class
83
+ ErrorCode["MISSING_NEW"] = "MISSING_NEW";
84
+ // Invalid argument (e.g. value is incompatible with type) to a function:
85
+ // - argument: The argument name that was invalid
86
+ // - value: The value of the argument
87
+ ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
88
+ // Missing argument to a function:
89
+ // - count: The number of arguments received
90
+ // - expectedCount: The number of arguments expected
91
+ ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
92
+ // Too many arguments
93
+ // - count: The number of arguments received
94
+ // - expectedCount: The number of arguments expected
95
+ ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
96
+ ///////////////////
97
+ // Blockchain Errors
98
+ // Call exception
99
+ // - transaction: the transaction
100
+ // - address?: the contract address
101
+ // - args?: The arguments passed into the function
102
+ // - method?: The Solidity method signature
103
+ // - errorSignature?: The EIP848 error signature
104
+ // - errorArgs?: The EIP848 error parameters
105
+ // - reason: The reason (only for EIP848 "Error(string)")
106
+ ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
107
+ // Insufficient funds (< value + gasLimit * gasPrice)
108
+ // - transaction: the transaction attempted
109
+ ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
110
+ // Nonce has already been used
111
+ // - transaction: the transaction attempted
112
+ ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
113
+ // The replacement fee for the transaction is too low
114
+ // - transaction: the transaction attempted
115
+ ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
116
+ // The gas limit could not be estimated
117
+ // - transaction: the transaction passed to estimateGas
118
+ ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
119
+ // The transaction was replaced by one with a higher gas price
120
+ // - reason: "cancelled", "replaced" or "repriced"
121
+ // - cancelled: true if reason == "cancelled" or reason == "replaced")
122
+ // - hash: original transaction hash
123
+ // - replacement: the full TransactionsResponse for the replacement
124
+ // - receipt: the receipt of the replacement
125
+ ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
126
+ ///////////////////
127
+ // Interaction Errors
128
+ // The user rejected the action, such as signing a message or sending
129
+ // a transaction
130
+ ErrorCode["ACTION_REJECTED"] = "ACTION_REJECTED";
131
+ })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
132
+ const HEX = "0123456789abcdef";
133
+ class Logger {
134
+ constructor(version) {
135
+ Object.defineProperty(this, "version", {
136
+ enumerable: true,
137
+ value: version,
138
+ writable: false,
139
+ });
140
+ }
141
+ _log(logLevel, args) {
142
+ const level = logLevel.toLowerCase();
143
+ if (LogLevels[level] == null) {
144
+ this.throwArgumentError("invalid log level name", "logLevel", logLevel);
145
+ }
146
+ if (_logLevel > LogLevels[level]) {
147
+ return;
148
+ }
149
+ console.log.apply(console, args);
150
+ }
151
+ debug(...args) {
152
+ this._log(Logger.levels.DEBUG, args);
153
+ }
154
+ info(...args) {
155
+ this._log(Logger.levels.INFO, args);
156
+ }
157
+ warn(...args) {
158
+ this._log(Logger.levels.WARNING, args);
159
+ }
160
+ makeError(message, code, params) {
161
+ // Errors are being censored
162
+ if (_censorErrors) {
163
+ return this.makeError("censored error", code, {});
164
+ }
165
+ if (!code) {
166
+ code = Logger.errors.UNKNOWN_ERROR;
167
+ }
168
+ if (!params) {
169
+ params = {};
170
+ }
171
+ const messageDetails = [];
172
+ Object.keys(params).forEach((key) => {
173
+ const value = params[key];
174
+ try {
175
+ if (value instanceof Uint8Array) {
176
+ let hex = "";
177
+ for (let i = 0; i < value.length; i++) {
178
+ hex += HEX[value[i] >> 4];
179
+ hex += HEX[value[i] & 0x0f];
180
+ }
181
+ messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
182
+ }
183
+ else {
184
+ messageDetails.push(key + "=" + JSON.stringify(value));
185
+ }
186
+ }
187
+ catch (error) {
188
+ messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
189
+ }
190
+ });
191
+ messageDetails.push(`code=${code}`);
192
+ messageDetails.push(`version=${this.version}`);
193
+ const reason = message;
194
+ let url = "";
195
+ switch (code) {
196
+ case ErrorCode.NUMERIC_FAULT: {
197
+ url = "NUMERIC_FAULT";
198
+ const fault = message;
199
+ switch (fault) {
200
+ case "overflow":
201
+ case "underflow":
202
+ case "division-by-zero":
203
+ url += "-" + fault;
204
+ break;
205
+ case "negative-power":
206
+ case "negative-width":
207
+ url += "-unsupported";
208
+ break;
209
+ case "unbound-bitwise-result":
210
+ url += "-unbound-result";
211
+ break;
212
+ }
213
+ break;
214
+ }
215
+ case ErrorCode.CALL_EXCEPTION:
216
+ case ErrorCode.INSUFFICIENT_FUNDS:
217
+ case ErrorCode.MISSING_NEW:
218
+ case ErrorCode.NONCE_EXPIRED:
219
+ case ErrorCode.REPLACEMENT_UNDERPRICED:
220
+ case ErrorCode.TRANSACTION_REPLACED:
221
+ case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
222
+ url = code;
223
+ break;
224
+ }
225
+ if (url) {
226
+ message +=
227
+ " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
228
+ }
229
+ if (messageDetails.length) {
230
+ message += " (" + messageDetails.join(", ") + ")";
231
+ }
232
+ // @TODO: Any??
233
+ const error = new Error(message);
234
+ error.reason = reason;
235
+ error.code = code;
236
+ Object.keys(params).forEach(function (key) {
237
+ error[key] = params[key];
238
+ });
239
+ return error;
240
+ }
241
+ throwError(message, code, params) {
242
+ throw this.makeError(message, code, params);
243
+ }
244
+ throwArgumentError(message, name, value) {
245
+ return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
246
+ argument: name,
247
+ value: value,
248
+ });
249
+ }
250
+ assert(condition, message, code, params) {
251
+ if (!!condition) {
252
+ return;
253
+ }
254
+ this.throwError(message, code, params);
255
+ }
256
+ assertArgument(condition, message, name, value) {
257
+ if (!!condition) {
258
+ return;
259
+ }
260
+ this.throwArgumentError(message, name, value);
261
+ }
262
+ checkNormalize(message) {
263
+ if (message == null) {
264
+ message = "platform missing String.prototype.normalize";
265
+ }
266
+ if (_normalizeError) {
267
+ this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
268
+ operation: "String.prototype.normalize",
269
+ form: _normalizeError,
270
+ });
271
+ }
272
+ }
273
+ checkSafeUint53(value, message) {
274
+ if (typeof value !== "number") {
275
+ return;
276
+ }
277
+ if (message == null) {
278
+ message = "value not safe";
279
+ }
280
+ if (value < 0 || value >= 0x1fffffffffffff) {
281
+ this.throwError(message, Logger.errors.NUMERIC_FAULT, {
282
+ operation: "checkSafeInteger",
283
+ fault: "out-of-safe-range",
284
+ value: value,
285
+ });
286
+ }
287
+ if (value % 1) {
288
+ this.throwError(message, Logger.errors.NUMERIC_FAULT, {
289
+ operation: "checkSafeInteger",
290
+ fault: "non-integer",
291
+ value: value,
292
+ });
293
+ }
294
+ }
295
+ checkArgumentCount(count, expectedCount, message) {
296
+ if (message) {
297
+ message = ": " + message;
298
+ }
299
+ else {
300
+ message = "";
301
+ }
302
+ if (count < expectedCount) {
303
+ this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
304
+ count: count,
305
+ expectedCount: expectedCount,
306
+ });
307
+ }
308
+ if (count > expectedCount) {
309
+ this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
310
+ count: count,
311
+ expectedCount: expectedCount,
312
+ });
313
+ }
314
+ }
315
+ checkNew(target, kind) {
316
+ if (target === Object || target == null) {
317
+ this.throwError("missing new", Logger.errors.MISSING_NEW, {
318
+ name: kind.name,
319
+ });
320
+ }
321
+ }
322
+ checkAbstract(target, kind) {
323
+ if (target === kind) {
324
+ this.throwError("cannot instantiate abstract class " +
325
+ JSON.stringify(kind.name) +
326
+ " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
327
+ }
328
+ else if (target === Object || target == null) {
329
+ this.throwError("missing new", Logger.errors.MISSING_NEW, {
330
+ name: kind.name,
331
+ });
332
+ }
333
+ }
334
+ static globalLogger() {
335
+ if (!_globalLogger) {
336
+ _globalLogger = new Logger(_version_1.version);
337
+ }
338
+ return _globalLogger;
339
+ }
340
+ static setCensorship(censorship, permanent) {
341
+ if (!censorship && permanent) {
342
+ this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
343
+ operation: "setCensorship",
344
+ });
345
+ }
346
+ if (_permanentCensorErrors) {
347
+ if (!censorship) {
348
+ return;
349
+ }
350
+ this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
351
+ operation: "setCensorship",
352
+ });
353
+ }
354
+ _censorErrors = !!censorship;
355
+ _permanentCensorErrors = !!permanent;
356
+ }
357
+ static setLogLevel(logLevel) {
358
+ const level = LogLevels[logLevel.toLowerCase()];
359
+ if (level == null) {
360
+ Logger.globalLogger().warn("invalid log level - " + logLevel);
361
+ return;
362
+ }
363
+ _logLevel = level;
364
+ }
365
+ static from(version) {
366
+ return new Logger(version);
367
+ }
368
+ }
369
+ exports.Logger = Logger;
370
+ Logger.errors = ErrorCode;
371
+ Logger.levels = LogLevel;
372
+ //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EAAE,CAAC,IAAI,CAAC,sBAAsB,GAAG,QAAQ,CAAC,CAAC;YAC9D,OAAO;QACX,CAAC;QACD,SAAS,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe;QACvB,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;;AA5TL,wBA6TC;AA1TU,aAAM,GAAG,SAAS,CAAC;AAEnB,aAAM,GAAG,QAAQ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "contributors": [
3
+ "Eugene Kuleshov <kulevgen32@gmail.com>",
4
+ "Richard Moore <me@ricmoo.com>"
5
+ ],
6
+ "dependencies": {},
7
+ "description": "Logger utility functions for qethers.",
8
+ "keywords": [
9
+ "QEVM",
10
+ "QuantumEVM",
11
+ "qethers"
12
+ ],
13
+ "license": "MIT",
14
+ "main": "./lib/index.js",
15
+ "module": "./lib.esm/index.js",
16
+ "name": "@qevm/logger",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1"
22
+ },
23
+ "sideEffects": false,
24
+ "tarballHash": "0x0e4fe629df0eded870b7750df05006454d92ebaa1c57279e846f5c41c131b816",
25
+ "types": "./lib/index.d.ts",
26
+ "version": "5.7.1"
27
+ }
@@ -0,0 +1 @@
1
+ export const version = "logger/5.7.1";
@@ -0,0 +1,483 @@
1
+ "use strict";
2
+
3
+ let _permanentCensorErrors = false;
4
+ let _censorErrors = false;
5
+
6
+ const LogLevels: { [name: string]: number } = {
7
+ debug: 1,
8
+ default: 2,
9
+ info: 2,
10
+ warning: 3,
11
+ error: 4,
12
+ off: 5,
13
+ };
14
+ let _logLevel = LogLevels["default"];
15
+
16
+ import { version } from "./_version";
17
+
18
+ let _globalLogger: Logger = null;
19
+
20
+ function _checkNormalize(): string {
21
+ try {
22
+ const missing: Array<string> = [];
23
+
24
+ // Make sure all forms of normalization are supported
25
+ ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
26
+ try {
27
+ if ("test".normalize(form) !== "test") {
28
+ throw new Error("bad normalize");
29
+ }
30
+ } catch (error) {
31
+ missing.push(form);
32
+ }
33
+ });
34
+
35
+ if (missing.length) {
36
+ throw new Error("missing " + missing.join(", "));
37
+ }
38
+
39
+ if (
40
+ String.fromCharCode(0xe9).normalize("NFD") !==
41
+ String.fromCharCode(0x65, 0x0301)
42
+ ) {
43
+ throw new Error("broken implementation");
44
+ }
45
+ } catch (error) {
46
+ return error.message;
47
+ }
48
+
49
+ return null;
50
+ }
51
+
52
+ const _normalizeError = _checkNormalize();
53
+
54
+ export enum LogLevel {
55
+ DEBUG = "DEBUG",
56
+ INFO = "INFO",
57
+ WARNING = "WARNING",
58
+ ERROR = "ERROR",
59
+ OFF = "OFF",
60
+ }
61
+
62
+ export enum ErrorCode {
63
+ ///////////////////
64
+ // Generic Errors
65
+
66
+ // Unknown Error
67
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
68
+
69
+ // Not Implemented
70
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
71
+
72
+ // Unsupported Operation
73
+ // - operation
74
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
75
+
76
+ // Network Error (i.e. Ethereum Network, such as an invalid chain ID)
77
+ // - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
78
+ NETWORK_ERROR = "NETWORK_ERROR",
79
+
80
+ // Some sort of bad response from the server
81
+ SERVER_ERROR = "SERVER_ERROR",
82
+
83
+ // Timeout
84
+ TIMEOUT = "TIMEOUT",
85
+
86
+ ///////////////////
87
+ // Operational Errors
88
+
89
+ // Buffer Overrun
90
+ BUFFER_OVERRUN = "BUFFER_OVERRUN",
91
+
92
+ // Numeric Fault
93
+ // - operation: the operation being executed
94
+ // - fault: the reason this faulted
95
+ NUMERIC_FAULT = "NUMERIC_FAULT",
96
+
97
+ ///////////////////
98
+ // Argument Errors
99
+
100
+ // Missing new operator to an object
101
+ // - name: The name of the class
102
+ MISSING_NEW = "MISSING_NEW",
103
+
104
+ // Invalid argument (e.g. value is incompatible with type) to a function:
105
+ // - argument: The argument name that was invalid
106
+ // - value: The value of the argument
107
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
108
+
109
+ // Missing argument to a function:
110
+ // - count: The number of arguments received
111
+ // - expectedCount: The number of arguments expected
112
+ MISSING_ARGUMENT = "MISSING_ARGUMENT",
113
+
114
+ // Too many arguments
115
+ // - count: The number of arguments received
116
+ // - expectedCount: The number of arguments expected
117
+ UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT",
118
+
119
+ ///////////////////
120
+ // Blockchain Errors
121
+
122
+ // Call exception
123
+ // - transaction: the transaction
124
+ // - address?: the contract address
125
+ // - args?: The arguments passed into the function
126
+ // - method?: The Solidity method signature
127
+ // - errorSignature?: The EIP848 error signature
128
+ // - errorArgs?: The EIP848 error parameters
129
+ // - reason: The reason (only for EIP848 "Error(string)")
130
+ CALL_EXCEPTION = "CALL_EXCEPTION",
131
+
132
+ // Insufficient funds (< value + gasLimit * gasPrice)
133
+ // - transaction: the transaction attempted
134
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
135
+
136
+ // Nonce has already been used
137
+ // - transaction: the transaction attempted
138
+ NONCE_EXPIRED = "NONCE_EXPIRED",
139
+
140
+ // The replacement fee for the transaction is too low
141
+ // - transaction: the transaction attempted
142
+ REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED",
143
+
144
+ // The gas limit could not be estimated
145
+ // - transaction: the transaction passed to estimateGas
146
+ UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT",
147
+
148
+ // The transaction was replaced by one with a higher gas price
149
+ // - reason: "cancelled", "replaced" or "repriced"
150
+ // - cancelled: true if reason == "cancelled" or reason == "replaced")
151
+ // - hash: original transaction hash
152
+ // - replacement: the full TransactionsResponse for the replacement
153
+ // - receipt: the receipt of the replacement
154
+ TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
155
+
156
+ ///////////////////
157
+ // Interaction Errors
158
+
159
+ // The user rejected the action, such as signing a message or sending
160
+ // a transaction
161
+ ACTION_REJECTED = "ACTION_REJECTED",
162
+ }
163
+
164
+ const HEX = "0123456789abcdef";
165
+
166
+ export class Logger {
167
+ readonly version: string;
168
+
169
+ static errors = ErrorCode;
170
+
171
+ static levels = LogLevel;
172
+
173
+ constructor(version: string) {
174
+ Object.defineProperty(this, "version", {
175
+ enumerable: true,
176
+ value: version,
177
+ writable: false,
178
+ });
179
+ }
180
+
181
+ _log(logLevel: LogLevel, args: Array<any>): void {
182
+ const level = logLevel.toLowerCase();
183
+ if (LogLevels[level] == null) {
184
+ this.throwArgumentError(
185
+ "invalid log level name",
186
+ "logLevel",
187
+ logLevel,
188
+ );
189
+ }
190
+ if (_logLevel > LogLevels[level]) {
191
+ return;
192
+ }
193
+ console.log.apply(console, args);
194
+ }
195
+
196
+ debug(...args: Array<any>): void {
197
+ this._log(Logger.levels.DEBUG, args);
198
+ }
199
+
200
+ info(...args: Array<any>): void {
201
+ this._log(Logger.levels.INFO, args);
202
+ }
203
+
204
+ warn(...args: Array<any>): void {
205
+ this._log(Logger.levels.WARNING, args);
206
+ }
207
+
208
+ makeError(message: string, code?: ErrorCode, params?: any): Error {
209
+ // Errors are being censored
210
+ if (_censorErrors) {
211
+ return this.makeError("censored error", code, {});
212
+ }
213
+
214
+ if (!code) {
215
+ code = Logger.errors.UNKNOWN_ERROR;
216
+ }
217
+ if (!params) {
218
+ params = {};
219
+ }
220
+
221
+ const messageDetails: Array<string> = [];
222
+ Object.keys(params).forEach((key) => {
223
+ const value = params[key];
224
+ try {
225
+ if (value instanceof Uint8Array) {
226
+ let hex = "";
227
+ for (let i = 0; i < value.length; i++) {
228
+ hex += HEX[value[i] >> 4];
229
+ hex += HEX[value[i] & 0x0f];
230
+ }
231
+ messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
232
+ } else {
233
+ messageDetails.push(key + "=" + JSON.stringify(value));
234
+ }
235
+ } catch (error) {
236
+ messageDetails.push(
237
+ key + "=" + JSON.stringify(params[key].toString()),
238
+ );
239
+ }
240
+ });
241
+ messageDetails.push(`code=${code}`);
242
+ messageDetails.push(`version=${this.version}`);
243
+
244
+ const reason = message;
245
+
246
+ let url = "";
247
+
248
+ switch (code) {
249
+ case ErrorCode.NUMERIC_FAULT: {
250
+ url = "NUMERIC_FAULT";
251
+ const fault = message;
252
+
253
+ switch (fault) {
254
+ case "overflow":
255
+ case "underflow":
256
+ case "division-by-zero":
257
+ url += "-" + fault;
258
+ break;
259
+ case "negative-power":
260
+ case "negative-width":
261
+ url += "-unsupported";
262
+ break;
263
+ case "unbound-bitwise-result":
264
+ url += "-unbound-result";
265
+ break;
266
+ }
267
+ break;
268
+ }
269
+ case ErrorCode.CALL_EXCEPTION:
270
+ case ErrorCode.INSUFFICIENT_FUNDS:
271
+ case ErrorCode.MISSING_NEW:
272
+ case ErrorCode.NONCE_EXPIRED:
273
+ case ErrorCode.REPLACEMENT_UNDERPRICED:
274
+ case ErrorCode.TRANSACTION_REPLACED:
275
+ case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
276
+ url = code;
277
+ break;
278
+ }
279
+
280
+ if (url) {
281
+ message +=
282
+ " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
283
+ }
284
+
285
+ if (messageDetails.length) {
286
+ message += " (" + messageDetails.join(", ") + ")";
287
+ }
288
+
289
+ // @TODO: Any??
290
+ const error: any = new Error(message);
291
+ error.reason = reason;
292
+ error.code = code;
293
+
294
+ Object.keys(params).forEach(function (key) {
295
+ error[key] = params[key];
296
+ });
297
+
298
+ return error;
299
+ }
300
+
301
+ throwError(message: string, code?: ErrorCode, params?: any): never {
302
+ throw this.makeError(message, code, params);
303
+ }
304
+
305
+ throwArgumentError(message: string, name: string, value: any): never {
306
+ return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
307
+ argument: name,
308
+ value: value,
309
+ });
310
+ }
311
+
312
+ assert(
313
+ condition: any,
314
+ message: string,
315
+ code?: ErrorCode,
316
+ params?: any,
317
+ ): void {
318
+ if (!!condition) {
319
+ return;
320
+ }
321
+ this.throwError(message, code, params);
322
+ }
323
+
324
+ assertArgument(
325
+ condition: any,
326
+ message: string,
327
+ name: string,
328
+ value: any,
329
+ ): void {
330
+ if (!!condition) {
331
+ return;
332
+ }
333
+ this.throwArgumentError(message, name, value);
334
+ }
335
+
336
+ checkNormalize(message?: string): void {
337
+ if (message == null) {
338
+ message = "platform missing String.prototype.normalize";
339
+ }
340
+ if (_normalizeError) {
341
+ this.throwError(
342
+ "platform missing String.prototype.normalize",
343
+ Logger.errors.UNSUPPORTED_OPERATION,
344
+ {
345
+ operation: "String.prototype.normalize",
346
+ form: _normalizeError,
347
+ },
348
+ );
349
+ }
350
+ }
351
+
352
+ checkSafeUint53(value: number, message?: string): void {
353
+ if (typeof value !== "number") {
354
+ return;
355
+ }
356
+
357
+ if (message == null) {
358
+ message = "value not safe";
359
+ }
360
+
361
+ if (value < 0 || value >= 0x1fffffffffffff) {
362
+ this.throwError(message, Logger.errors.NUMERIC_FAULT, {
363
+ operation: "checkSafeInteger",
364
+ fault: "out-of-safe-range",
365
+ value: value,
366
+ });
367
+ }
368
+
369
+ if (value % 1) {
370
+ this.throwError(message, Logger.errors.NUMERIC_FAULT, {
371
+ operation: "checkSafeInteger",
372
+ fault: "non-integer",
373
+ value: value,
374
+ });
375
+ }
376
+ }
377
+
378
+ checkArgumentCount(
379
+ count: number,
380
+ expectedCount: number,
381
+ message?: string,
382
+ ): void {
383
+ if (message) {
384
+ message = ": " + message;
385
+ } else {
386
+ message = "";
387
+ }
388
+
389
+ if (count < expectedCount) {
390
+ this.throwError(
391
+ "missing argument" + message,
392
+ Logger.errors.MISSING_ARGUMENT,
393
+ {
394
+ count: count,
395
+ expectedCount: expectedCount,
396
+ },
397
+ );
398
+ }
399
+
400
+ if (count > expectedCount) {
401
+ this.throwError(
402
+ "too many arguments" + message,
403
+ Logger.errors.UNEXPECTED_ARGUMENT,
404
+ {
405
+ count: count,
406
+ expectedCount: expectedCount,
407
+ },
408
+ );
409
+ }
410
+ }
411
+
412
+ checkNew(target: any, kind: any): void {
413
+ if (target === Object || target == null) {
414
+ this.throwError("missing new", Logger.errors.MISSING_NEW, {
415
+ name: kind.name,
416
+ });
417
+ }
418
+ }
419
+
420
+ checkAbstract(target: any, kind: any): void {
421
+ if (target === kind) {
422
+ this.throwError(
423
+ "cannot instantiate abstract class " +
424
+ JSON.stringify(kind.name) +
425
+ " directly; use a sub-class",
426
+ Logger.errors.UNSUPPORTED_OPERATION,
427
+ { name: target.name, operation: "new" },
428
+ );
429
+ } else if (target === Object || target == null) {
430
+ this.throwError("missing new", Logger.errors.MISSING_NEW, {
431
+ name: kind.name,
432
+ });
433
+ }
434
+ }
435
+
436
+ static globalLogger(): Logger {
437
+ if (!_globalLogger) {
438
+ _globalLogger = new Logger(version);
439
+ }
440
+ return _globalLogger;
441
+ }
442
+
443
+ static setCensorship(censorship: boolean, permanent?: boolean): void {
444
+ if (!censorship && permanent) {
445
+ this.globalLogger().throwError(
446
+ "cannot permanently disable censorship",
447
+ Logger.errors.UNSUPPORTED_OPERATION,
448
+ {
449
+ operation: "setCensorship",
450
+ },
451
+ );
452
+ }
453
+
454
+ if (_permanentCensorErrors) {
455
+ if (!censorship) {
456
+ return;
457
+ }
458
+ this.globalLogger().throwError(
459
+ "error censorship permanent",
460
+ Logger.errors.UNSUPPORTED_OPERATION,
461
+ {
462
+ operation: "setCensorship",
463
+ },
464
+ );
465
+ }
466
+
467
+ _censorErrors = !!censorship;
468
+ _permanentCensorErrors = !!permanent;
469
+ }
470
+
471
+ static setLogLevel(logLevel: LogLevel): void {
472
+ const level = LogLevels[logLevel.toLowerCase()];
473
+ if (level == null) {
474
+ Logger.globalLogger().warn("invalid log level - " + logLevel);
475
+ return;
476
+ }
477
+ _logLevel = level;
478
+ }
479
+
480
+ static from(version: string): Logger {
481
+ return new Logger(version);
482
+ }
483
+ }