@qevm/abi 5.7.1 → 5.7.2
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/lib/abi-coder.js +51 -46
- package/lib/abi-coder.js.map +1 -1
- package/lib/coders/abstract-coder.js +80 -60
- package/lib/coders/abstract-coder.js.map +1 -1
- package/lib/coders/address.js +30 -13
- package/lib/coders/address.js.map +1 -1
- package/lib/coders/anonymous.js +30 -12
- package/lib/coders/anonymous.js.map +1 -1
- package/lib/coders/array.js +82 -60
- package/lib/coders/array.js.map +1 -1
- package/lib/coders/boolean.js +28 -11
- package/lib/coders/boolean.js.map +1 -1
- package/lib/coders/bytes.js +39 -20
- package/lib/coders/bytes.js.map +1 -1
- package/lib/coders/fixed-bytes.js +34 -15
- package/lib/coders/fixed-bytes.js.map +1 -1
- package/lib/coders/null.js +28 -11
- package/lib/coders/null.js.map +1 -1
- package/lib/coders/number.js +39 -20
- package/lib/coders/number.js.map +1 -1
- package/lib/coders/string.js +31 -14
- package/lib/coders/string.js.map +1 -1
- package/lib/coders/tuple.js +42 -23
- package/lib/coders/tuple.js.map +1 -1
- package/lib/fragments.js +179 -142
- package/lib/fragments.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/interface.js +216 -169
- package/lib/interface.js.map +1 -1
- package/package.json +1 -1
- package/src.ts/coders/string.ts +1 -1
- package/src.ts/interface.ts +1 -1
package/lib/fragments.js
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.ErrorFragment = exports.FunctionFragment = exports.ConstructorFragment = exports.EventFragment = exports.Fragment = exports.ParamType = exports.FormatTypes = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
var bignumber_1 = require("@qevm/bignumber");
|
|
20
|
+
var properties_1 = require("@ethersproject/properties");
|
|
21
|
+
var logger_1 = require("@ethersproject/logger");
|
|
22
|
+
var _version_1 = require("./_version");
|
|
23
|
+
var logger = new logger_1.Logger(_version_1.version);
|
|
9
24
|
;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
var _constructorGuard = {};
|
|
26
|
+
var ModifiersBytes = { calldata: true, memory: true, storage: true };
|
|
27
|
+
var ModifiersNest = { calldata: true, memory: true };
|
|
13
28
|
function checkModifier(type, name) {
|
|
14
29
|
if (type === "bytes" || type === "string") {
|
|
15
30
|
if (ModifiersBytes[name]) {
|
|
@@ -33,22 +48,22 @@ function checkModifier(type, name) {
|
|
|
33
48
|
}
|
|
34
49
|
// @TODO: Make sure that children of an indexed tuple are marked with a null indexed
|
|
35
50
|
function parseParamType(param, allowIndexed) {
|
|
36
|
-
|
|
51
|
+
var originalParam = param;
|
|
37
52
|
function throwError(i) {
|
|
38
|
-
logger.throwArgumentError(
|
|
53
|
+
logger.throwArgumentError("unexpected character at position ".concat(i), "param", param);
|
|
39
54
|
}
|
|
40
55
|
param = param.replace(/\s/g, " ");
|
|
41
56
|
function newNode(parent) {
|
|
42
|
-
|
|
57
|
+
var node = { type: "", name: "", parent: parent, state: { allowType: true } };
|
|
43
58
|
if (allowIndexed) {
|
|
44
59
|
node.indexed = false;
|
|
45
60
|
}
|
|
46
61
|
return node;
|
|
47
62
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (
|
|
51
|
-
|
|
63
|
+
var parent = { type: "", name: "", state: { allowType: true } };
|
|
64
|
+
var node = parent;
|
|
65
|
+
for (var i = 0; i < param.length; i++) {
|
|
66
|
+
var c = param[i];
|
|
52
67
|
switch (c) {
|
|
53
68
|
case "(":
|
|
54
69
|
if (node.state.allowType && node.type === "") {
|
|
@@ -75,7 +90,7 @@ function parseParamType(param, allowIndexed) {
|
|
|
75
90
|
node.name = "";
|
|
76
91
|
}
|
|
77
92
|
node.type = verifyType(node.type);
|
|
78
|
-
|
|
93
|
+
var child = node;
|
|
79
94
|
node = node.parent;
|
|
80
95
|
if (!node) {
|
|
81
96
|
throwError(i);
|
|
@@ -98,7 +113,7 @@ function parseParamType(param, allowIndexed) {
|
|
|
98
113
|
node.name = "";
|
|
99
114
|
}
|
|
100
115
|
node.type = verifyType(node.type);
|
|
101
|
-
|
|
116
|
+
var sibling = newNode(node.parent);
|
|
102
117
|
//{ type: "", name: "", parent: node.parent, state: { allowType: true } };
|
|
103
118
|
node.parent.components.push(sibling);
|
|
104
119
|
delete node.parent;
|
|
@@ -194,7 +209,7 @@ function parseParamType(param, allowIndexed) {
|
|
|
194
209
|
return parent;
|
|
195
210
|
}
|
|
196
211
|
function populate(object, params) {
|
|
197
|
-
for (
|
|
212
|
+
for (var key in params) {
|
|
198
213
|
(0, properties_1.defineReadOnly)(object, key, params[key]);
|
|
199
214
|
}
|
|
200
215
|
}
|
|
@@ -208,16 +223,16 @@ exports.FormatTypes = Object.freeze({
|
|
|
208
223
|
// JSON-format a la Solidity
|
|
209
224
|
json: "json"
|
|
210
225
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
226
|
+
var paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
|
|
227
|
+
var ParamType = /** @class */ (function () {
|
|
228
|
+
function ParamType(constructorGuard, params) {
|
|
214
229
|
if (constructorGuard !== _constructorGuard) {
|
|
215
230
|
logger.throwError("use fromString", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
216
231
|
operation: "new ParamType()"
|
|
217
232
|
});
|
|
218
233
|
}
|
|
219
234
|
populate(this, params);
|
|
220
|
-
|
|
235
|
+
var match = this.type.match(paramTypeArray);
|
|
221
236
|
if (match) {
|
|
222
237
|
populate(this, {
|
|
223
238
|
arrayLength: parseInt(match[2] || "-1"),
|
|
@@ -242,7 +257,7 @@ class ParamType {
|
|
|
242
257
|
// - sighash: "(uint256,address)"
|
|
243
258
|
// - minimal: "tuple(uint256,address) indexed"
|
|
244
259
|
// - full: "tuple(uint256 foo, address bar) indexed baz"
|
|
245
|
-
format(format) {
|
|
260
|
+
ParamType.prototype.format = function (format) {
|
|
246
261
|
if (!format) {
|
|
247
262
|
format = exports.FormatTypes.sighash;
|
|
248
263
|
}
|
|
@@ -250,19 +265,19 @@ class ParamType {
|
|
|
250
265
|
logger.throwArgumentError("invalid format type", "format", format);
|
|
251
266
|
}
|
|
252
267
|
if (format === exports.FormatTypes.json) {
|
|
253
|
-
|
|
268
|
+
var result_1 = {
|
|
254
269
|
type: ((this.baseType === "tuple") ? "tuple" : this.type),
|
|
255
270
|
name: (this.name || undefined)
|
|
256
271
|
};
|
|
257
272
|
if (typeof (this.indexed) === "boolean") {
|
|
258
|
-
|
|
273
|
+
result_1.indexed = this.indexed;
|
|
259
274
|
}
|
|
260
275
|
if (this.components) {
|
|
261
|
-
|
|
276
|
+
result_1.components = this.components.map(function (comp) { return JSON.parse(comp.format(format)); });
|
|
262
277
|
}
|
|
263
|
-
return JSON.stringify(
|
|
278
|
+
return JSON.stringify(result_1);
|
|
264
279
|
}
|
|
265
|
-
|
|
280
|
+
var result = "";
|
|
266
281
|
// Array
|
|
267
282
|
if (this.baseType === "array") {
|
|
268
283
|
result += this.arrayChildren.format(format);
|
|
@@ -273,7 +288,7 @@ class ParamType {
|
|
|
273
288
|
if (format !== exports.FormatTypes.sighash) {
|
|
274
289
|
result += this.type;
|
|
275
290
|
}
|
|
276
|
-
result += "(" + this.components.map((comp)
|
|
291
|
+
result += "(" + this.components.map(function (comp) { return comp.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ")";
|
|
277
292
|
}
|
|
278
293
|
else {
|
|
279
294
|
result += this.type;
|
|
@@ -288,14 +303,14 @@ class ParamType {
|
|
|
288
303
|
}
|
|
289
304
|
}
|
|
290
305
|
return result;
|
|
291
|
-
}
|
|
292
|
-
|
|
306
|
+
};
|
|
307
|
+
ParamType.from = function (value, allowIndexed) {
|
|
293
308
|
if (typeof (value) === "string") {
|
|
294
309
|
return ParamType.fromString(value, allowIndexed);
|
|
295
310
|
}
|
|
296
311
|
return ParamType.fromObject(value);
|
|
297
|
-
}
|
|
298
|
-
|
|
312
|
+
};
|
|
313
|
+
ParamType.fromObject = function (value) {
|
|
299
314
|
if (ParamType.isParamType(value)) {
|
|
300
315
|
return value;
|
|
301
316
|
}
|
|
@@ -305,8 +320,8 @@ class ParamType {
|
|
|
305
320
|
indexed: ((value.indexed == null) ? null : !!value.indexed),
|
|
306
321
|
components: (value.components ? value.components.map(ParamType.fromObject) : null)
|
|
307
322
|
});
|
|
308
|
-
}
|
|
309
|
-
|
|
323
|
+
};
|
|
324
|
+
ParamType.fromString = function (value, allowIndexed) {
|
|
310
325
|
function ParamTypify(node) {
|
|
311
326
|
return ParamType.fromObject({
|
|
312
327
|
name: node.name,
|
|
@@ -316,18 +331,19 @@ class ParamType {
|
|
|
316
331
|
});
|
|
317
332
|
}
|
|
318
333
|
return ParamTypify(parseParamType(value, !!allowIndexed));
|
|
319
|
-
}
|
|
320
|
-
|
|
334
|
+
};
|
|
335
|
+
ParamType.isParamType = function (value) {
|
|
321
336
|
return !!(value != null && value._isParamType);
|
|
322
|
-
}
|
|
323
|
-
|
|
337
|
+
};
|
|
338
|
+
return ParamType;
|
|
339
|
+
}());
|
|
324
340
|
exports.ParamType = ParamType;
|
|
325
341
|
;
|
|
326
342
|
function parseParams(value, allowIndex) {
|
|
327
|
-
return splitNesting(value).map((param)
|
|
343
|
+
return splitNesting(value).map(function (param) { return ParamType.fromString(param, allowIndex); });
|
|
328
344
|
}
|
|
329
|
-
|
|
330
|
-
|
|
345
|
+
var Fragment = /** @class */ (function () {
|
|
346
|
+
function Fragment(constructorGuard, params) {
|
|
331
347
|
if (constructorGuard !== _constructorGuard) {
|
|
332
348
|
logger.throwError("use a static from method", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
333
349
|
operation: "new Fragment()"
|
|
@@ -337,7 +353,7 @@ class Fragment {
|
|
|
337
353
|
this._isFragment = true;
|
|
338
354
|
Object.freeze(this);
|
|
339
355
|
}
|
|
340
|
-
|
|
356
|
+
Fragment.from = function (value) {
|
|
341
357
|
if (Fragment.isFragment(value)) {
|
|
342
358
|
return value;
|
|
343
359
|
}
|
|
@@ -345,8 +361,8 @@ class Fragment {
|
|
|
345
361
|
return Fragment.fromString(value);
|
|
346
362
|
}
|
|
347
363
|
return Fragment.fromObject(value);
|
|
348
|
-
}
|
|
349
|
-
|
|
364
|
+
};
|
|
365
|
+
Fragment.fromObject = function (value) {
|
|
350
366
|
if (Fragment.isFragment(value)) {
|
|
351
367
|
return value;
|
|
352
368
|
}
|
|
@@ -365,8 +381,8 @@ class Fragment {
|
|
|
365
381
|
return null;
|
|
366
382
|
}
|
|
367
383
|
return logger.throwArgumentError("invalid fragment object", "value", value);
|
|
368
|
-
}
|
|
369
|
-
|
|
384
|
+
};
|
|
385
|
+
Fragment.fromString = function (value) {
|
|
370
386
|
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
|
371
387
|
value = value.replace(/\s/g, " ");
|
|
372
388
|
value = value.replace(/\(/g, " (").replace(/\)/g, ") ").replace(/\s+/g, " ");
|
|
@@ -384,14 +400,19 @@ class Fragment {
|
|
|
384
400
|
return ErrorFragment.fromString(value.substring(5).trim());
|
|
385
401
|
}
|
|
386
402
|
return logger.throwArgumentError("unsupported fragment", "value", value);
|
|
387
|
-
}
|
|
388
|
-
|
|
403
|
+
};
|
|
404
|
+
Fragment.isFragment = function (value) {
|
|
389
405
|
return !!(value && value._isFragment);
|
|
390
|
-
}
|
|
391
|
-
|
|
406
|
+
};
|
|
407
|
+
return Fragment;
|
|
408
|
+
}());
|
|
392
409
|
exports.Fragment = Fragment;
|
|
393
|
-
|
|
394
|
-
|
|
410
|
+
var EventFragment = /** @class */ (function (_super) {
|
|
411
|
+
__extends(EventFragment, _super);
|
|
412
|
+
function EventFragment() {
|
|
413
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
414
|
+
}
|
|
415
|
+
EventFragment.prototype.format = function (format) {
|
|
395
416
|
if (!format) {
|
|
396
417
|
format = exports.FormatTypes.sighash;
|
|
397
418
|
}
|
|
@@ -403,49 +424,49 @@ class EventFragment extends Fragment {
|
|
|
403
424
|
type: "event",
|
|
404
425
|
anonymous: this.anonymous,
|
|
405
426
|
name: this.name,
|
|
406
|
-
inputs: this.inputs.map((input)
|
|
427
|
+
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); })
|
|
407
428
|
});
|
|
408
429
|
}
|
|
409
|
-
|
|
430
|
+
var result = "";
|
|
410
431
|
if (format !== exports.FormatTypes.sighash) {
|
|
411
432
|
result += "event ";
|
|
412
433
|
}
|
|
413
|
-
result += this.name + "(" + this.inputs.map((input)
|
|
434
|
+
result += this.name + "(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
|
414
435
|
if (format !== exports.FormatTypes.sighash) {
|
|
415
436
|
if (this.anonymous) {
|
|
416
437
|
result += "anonymous ";
|
|
417
438
|
}
|
|
418
439
|
}
|
|
419
440
|
return result.trim();
|
|
420
|
-
}
|
|
421
|
-
|
|
441
|
+
};
|
|
442
|
+
EventFragment.from = function (value) {
|
|
422
443
|
if (typeof (value) === "string") {
|
|
423
444
|
return EventFragment.fromString(value);
|
|
424
445
|
}
|
|
425
446
|
return EventFragment.fromObject(value);
|
|
426
|
-
}
|
|
427
|
-
|
|
447
|
+
};
|
|
448
|
+
EventFragment.fromObject = function (value) {
|
|
428
449
|
if (EventFragment.isEventFragment(value)) {
|
|
429
450
|
return value;
|
|
430
451
|
}
|
|
431
452
|
if (value.type !== "event") {
|
|
432
453
|
logger.throwArgumentError("invalid event object", "value", value);
|
|
433
454
|
}
|
|
434
|
-
|
|
455
|
+
var params = {
|
|
435
456
|
name: verifyIdentifier(value.name),
|
|
436
457
|
anonymous: value.anonymous,
|
|
437
458
|
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
|
438
459
|
type: "event"
|
|
439
460
|
};
|
|
440
461
|
return new EventFragment(_constructorGuard, params);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
462
|
+
};
|
|
463
|
+
EventFragment.fromString = function (value) {
|
|
464
|
+
var match = value.match(regexParen);
|
|
444
465
|
if (!match) {
|
|
445
466
|
logger.throwArgumentError("invalid event string", "value", value);
|
|
446
467
|
}
|
|
447
|
-
|
|
448
|
-
match[3].split(" ").forEach((modifier)
|
|
468
|
+
var anonymous = false;
|
|
469
|
+
match[3].split(" ").forEach(function (modifier) {
|
|
449
470
|
switch (modifier.trim()) {
|
|
450
471
|
case "anonymous":
|
|
451
472
|
anonymous = true;
|
|
@@ -462,15 +483,16 @@ class EventFragment extends Fragment {
|
|
|
462
483
|
inputs: parseParams(match[2], true),
|
|
463
484
|
type: "event"
|
|
464
485
|
});
|
|
465
|
-
}
|
|
466
|
-
|
|
486
|
+
};
|
|
487
|
+
EventFragment.isEventFragment = function (value) {
|
|
467
488
|
return (value && value._isFragment && value.type === "event");
|
|
468
|
-
}
|
|
469
|
-
|
|
489
|
+
};
|
|
490
|
+
return EventFragment;
|
|
491
|
+
}(Fragment));
|
|
470
492
|
exports.EventFragment = EventFragment;
|
|
471
493
|
function parseGas(value, params) {
|
|
472
494
|
params.gas = null;
|
|
473
|
-
|
|
495
|
+
var comps = value.split("@");
|
|
474
496
|
if (comps.length !== 1) {
|
|
475
497
|
if (comps.length > 2) {
|
|
476
498
|
logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
|
|
@@ -487,7 +509,7 @@ function parseModifiers(value, params) {
|
|
|
487
509
|
params.constant = false;
|
|
488
510
|
params.payable = false;
|
|
489
511
|
params.stateMutability = "nonpayable";
|
|
490
|
-
value.split(" ").forEach((modifier)
|
|
512
|
+
value.split(" ").forEach(function (modifier) {
|
|
491
513
|
switch (modifier.trim()) {
|
|
492
514
|
case "constant":
|
|
493
515
|
params.constant = true;
|
|
@@ -518,7 +540,7 @@ function parseModifiers(value, params) {
|
|
|
518
540
|
});
|
|
519
541
|
}
|
|
520
542
|
function verifyState(value) {
|
|
521
|
-
|
|
543
|
+
var result = {
|
|
522
544
|
constant: false,
|
|
523
545
|
payable: true,
|
|
524
546
|
stateMutability: "payable"
|
|
@@ -567,8 +589,12 @@ function verifyState(value) {
|
|
|
567
589
|
}
|
|
568
590
|
return result;
|
|
569
591
|
}
|
|
570
|
-
|
|
571
|
-
|
|
592
|
+
var ConstructorFragment = /** @class */ (function (_super) {
|
|
593
|
+
__extends(ConstructorFragment, _super);
|
|
594
|
+
function ConstructorFragment() {
|
|
595
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
596
|
+
}
|
|
597
|
+
ConstructorFragment.prototype.format = function (format) {
|
|
572
598
|
if (!format) {
|
|
573
599
|
format = exports.FormatTypes.sighash;
|
|
574
600
|
}
|
|
@@ -581,7 +607,7 @@ class ConstructorFragment extends Fragment {
|
|
|
581
607
|
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
|
582
608
|
payable: this.payable,
|
|
583
609
|
gas: (this.gas ? this.gas.toNumber() : undefined),
|
|
584
|
-
inputs: this.inputs.map((input)
|
|
610
|
+
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); })
|
|
585
611
|
});
|
|
586
612
|
}
|
|
587
613
|
if (format === exports.FormatTypes.sighash) {
|
|
@@ -589,30 +615,30 @@ class ConstructorFragment extends Fragment {
|
|
|
589
615
|
operation: "format(sighash)"
|
|
590
616
|
});
|
|
591
617
|
}
|
|
592
|
-
|
|
618
|
+
var result = "constructor(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
|
593
619
|
if (this.stateMutability && this.stateMutability !== "nonpayable") {
|
|
594
620
|
result += this.stateMutability + " ";
|
|
595
621
|
}
|
|
596
622
|
return result.trim();
|
|
597
|
-
}
|
|
598
|
-
|
|
623
|
+
};
|
|
624
|
+
ConstructorFragment.from = function (value) {
|
|
599
625
|
if (typeof (value) === "string") {
|
|
600
626
|
return ConstructorFragment.fromString(value);
|
|
601
627
|
}
|
|
602
628
|
return ConstructorFragment.fromObject(value);
|
|
603
|
-
}
|
|
604
|
-
|
|
629
|
+
};
|
|
630
|
+
ConstructorFragment.fromObject = function (value) {
|
|
605
631
|
if (ConstructorFragment.isConstructorFragment(value)) {
|
|
606
632
|
return value;
|
|
607
633
|
}
|
|
608
634
|
if (value.type !== "constructor") {
|
|
609
635
|
logger.throwArgumentError("invalid constructor object", "value", value);
|
|
610
636
|
}
|
|
611
|
-
|
|
637
|
+
var state = verifyState(value);
|
|
612
638
|
if (state.constant) {
|
|
613
639
|
logger.throwArgumentError("constructor cannot be constant", "value", value);
|
|
614
640
|
}
|
|
615
|
-
|
|
641
|
+
var params = {
|
|
616
642
|
name: null,
|
|
617
643
|
type: value.type,
|
|
618
644
|
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
|
@@ -621,25 +647,30 @@ class ConstructorFragment extends Fragment {
|
|
|
621
647
|
gas: (value.gas ? bignumber_1.BigNumber.from(value.gas) : null)
|
|
622
648
|
};
|
|
623
649
|
return new ConstructorFragment(_constructorGuard, params);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
650
|
+
};
|
|
651
|
+
ConstructorFragment.fromString = function (value) {
|
|
652
|
+
var params = { type: "constructor" };
|
|
627
653
|
value = parseGas(value, params);
|
|
628
|
-
|
|
654
|
+
var parens = value.match(regexParen);
|
|
629
655
|
if (!parens || parens[1].trim() !== "constructor") {
|
|
630
656
|
logger.throwArgumentError("invalid constructor string", "value", value);
|
|
631
657
|
}
|
|
632
658
|
params.inputs = parseParams(parens[2].trim(), false);
|
|
633
659
|
parseModifiers(parens[3].trim(), params);
|
|
634
660
|
return ConstructorFragment.fromObject(params);
|
|
635
|
-
}
|
|
636
|
-
|
|
661
|
+
};
|
|
662
|
+
ConstructorFragment.isConstructorFragment = function (value) {
|
|
637
663
|
return (value && value._isFragment && value.type === "constructor");
|
|
638
|
-
}
|
|
639
|
-
|
|
664
|
+
};
|
|
665
|
+
return ConstructorFragment;
|
|
666
|
+
}(Fragment));
|
|
640
667
|
exports.ConstructorFragment = ConstructorFragment;
|
|
641
|
-
|
|
642
|
-
|
|
668
|
+
var FunctionFragment = /** @class */ (function (_super) {
|
|
669
|
+
__extends(FunctionFragment, _super);
|
|
670
|
+
function FunctionFragment() {
|
|
671
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
672
|
+
}
|
|
673
|
+
FunctionFragment.prototype.format = function (format) {
|
|
643
674
|
if (!format) {
|
|
644
675
|
format = exports.FormatTypes.sighash;
|
|
645
676
|
}
|
|
@@ -654,15 +685,15 @@ class FunctionFragment extends ConstructorFragment {
|
|
|
654
685
|
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
|
655
686
|
payable: this.payable,
|
|
656
687
|
gas: (this.gas ? this.gas.toNumber() : undefined),
|
|
657
|
-
inputs: this.inputs.map((input)
|
|
658
|
-
outputs: this.outputs.map((output)
|
|
688
|
+
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); }),
|
|
689
|
+
outputs: this.outputs.map(function (output) { return JSON.parse(output.format(format)); }),
|
|
659
690
|
});
|
|
660
691
|
}
|
|
661
|
-
|
|
692
|
+
var result = "";
|
|
662
693
|
if (format !== exports.FormatTypes.sighash) {
|
|
663
694
|
result += "function ";
|
|
664
695
|
}
|
|
665
|
-
result += this.name + "(" + this.inputs.map((input)
|
|
696
|
+
result += this.name + "(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
|
666
697
|
if (format !== exports.FormatTypes.sighash) {
|
|
667
698
|
if (this.stateMutability) {
|
|
668
699
|
if (this.stateMutability !== "nonpayable") {
|
|
@@ -673,29 +704,29 @@ class FunctionFragment extends ConstructorFragment {
|
|
|
673
704
|
result += "view ";
|
|
674
705
|
}
|
|
675
706
|
if (this.outputs && this.outputs.length) {
|
|
676
|
-
result += "returns (" + this.outputs.map((output)
|
|
707
|
+
result += "returns (" + this.outputs.map(function (output) { return output.format(format); }).join(", ") + ") ";
|
|
677
708
|
}
|
|
678
709
|
if (this.gas != null) {
|
|
679
710
|
result += "@" + this.gas.toString() + " ";
|
|
680
711
|
}
|
|
681
712
|
}
|
|
682
713
|
return result.trim();
|
|
683
|
-
}
|
|
684
|
-
|
|
714
|
+
};
|
|
715
|
+
FunctionFragment.from = function (value) {
|
|
685
716
|
if (typeof (value) === "string") {
|
|
686
717
|
return FunctionFragment.fromString(value);
|
|
687
718
|
}
|
|
688
719
|
return FunctionFragment.fromObject(value);
|
|
689
|
-
}
|
|
690
|
-
|
|
720
|
+
};
|
|
721
|
+
FunctionFragment.fromObject = function (value) {
|
|
691
722
|
if (FunctionFragment.isFunctionFragment(value)) {
|
|
692
723
|
return value;
|
|
693
724
|
}
|
|
694
725
|
if (value.type !== "function") {
|
|
695
726
|
logger.throwArgumentError("invalid function object", "value", value);
|
|
696
727
|
}
|
|
697
|
-
|
|
698
|
-
|
|
728
|
+
var state = verifyState(value);
|
|
729
|
+
var params = {
|
|
699
730
|
type: value.type,
|
|
700
731
|
name: verifyIdentifier(value.name),
|
|
701
732
|
constant: state.constant,
|
|
@@ -706,15 +737,15 @@ class FunctionFragment extends ConstructorFragment {
|
|
|
706
737
|
gas: (value.gas ? bignumber_1.BigNumber.from(value.gas) : null)
|
|
707
738
|
};
|
|
708
739
|
return new FunctionFragment(_constructorGuard, params);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
740
|
+
};
|
|
741
|
+
FunctionFragment.fromString = function (value) {
|
|
742
|
+
var params = { type: "function" };
|
|
712
743
|
value = parseGas(value, params);
|
|
713
|
-
|
|
744
|
+
var comps = value.split(" returns ");
|
|
714
745
|
if (comps.length > 2) {
|
|
715
746
|
logger.throwArgumentError("invalid function string", "value", value);
|
|
716
747
|
}
|
|
717
|
-
|
|
748
|
+
var parens = comps[0].match(regexParen);
|
|
718
749
|
if (!parens) {
|
|
719
750
|
logger.throwArgumentError("invalid function signature", "value", value);
|
|
720
751
|
}
|
|
@@ -726,7 +757,7 @@ class FunctionFragment extends ConstructorFragment {
|
|
|
726
757
|
parseModifiers(parens[3].trim(), params);
|
|
727
758
|
// We have outputs
|
|
728
759
|
if (comps.length > 1) {
|
|
729
|
-
|
|
760
|
+
var returns = comps[1].match(regexParen);
|
|
730
761
|
if (returns[1].trim() != "" || returns[3].trim() != "") {
|
|
731
762
|
logger.throwArgumentError("unexpected tokens", "value", value);
|
|
732
763
|
}
|
|
@@ -736,23 +767,28 @@ class FunctionFragment extends ConstructorFragment {
|
|
|
736
767
|
params.outputs = [];
|
|
737
768
|
}
|
|
738
769
|
return FunctionFragment.fromObject(params);
|
|
739
|
-
}
|
|
740
|
-
|
|
770
|
+
};
|
|
771
|
+
FunctionFragment.isFunctionFragment = function (value) {
|
|
741
772
|
return (value && value._isFragment && value.type === "function");
|
|
742
|
-
}
|
|
743
|
-
|
|
773
|
+
};
|
|
774
|
+
return FunctionFragment;
|
|
775
|
+
}(ConstructorFragment));
|
|
744
776
|
exports.FunctionFragment = FunctionFragment;
|
|
745
777
|
//export class StructFragment extends Fragment {
|
|
746
778
|
//}
|
|
747
779
|
function checkForbidden(fragment) {
|
|
748
|
-
|
|
780
|
+
var sig = fragment.format();
|
|
749
781
|
if (sig === "Error(string)" || sig === "Panic(uint256)") {
|
|
750
|
-
logger.throwArgumentError(
|
|
782
|
+
logger.throwArgumentError("cannot specify user defined ".concat(sig, " error"), "fragment", fragment);
|
|
751
783
|
}
|
|
752
784
|
return fragment;
|
|
753
785
|
}
|
|
754
|
-
|
|
755
|
-
|
|
786
|
+
var ErrorFragment = /** @class */ (function (_super) {
|
|
787
|
+
__extends(ErrorFragment, _super);
|
|
788
|
+
function ErrorFragment() {
|
|
789
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
790
|
+
}
|
|
791
|
+
ErrorFragment.prototype.format = function (format) {
|
|
756
792
|
if (!format) {
|
|
757
793
|
format = exports.FormatTypes.sighash;
|
|
758
794
|
}
|
|
@@ -763,39 +799,39 @@ class ErrorFragment extends Fragment {
|
|
|
763
799
|
return JSON.stringify({
|
|
764
800
|
type: "error",
|
|
765
801
|
name: this.name,
|
|
766
|
-
inputs: this.inputs.map((input)
|
|
802
|
+
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); }),
|
|
767
803
|
});
|
|
768
804
|
}
|
|
769
|
-
|
|
805
|
+
var result = "";
|
|
770
806
|
if (format !== exports.FormatTypes.sighash) {
|
|
771
807
|
result += "error ";
|
|
772
808
|
}
|
|
773
|
-
result += this.name + "(" + this.inputs.map((input)
|
|
809
|
+
result += this.name + "(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
|
774
810
|
return result.trim();
|
|
775
|
-
}
|
|
776
|
-
|
|
811
|
+
};
|
|
812
|
+
ErrorFragment.from = function (value) {
|
|
777
813
|
if (typeof (value) === "string") {
|
|
778
814
|
return ErrorFragment.fromString(value);
|
|
779
815
|
}
|
|
780
816
|
return ErrorFragment.fromObject(value);
|
|
781
|
-
}
|
|
782
|
-
|
|
817
|
+
};
|
|
818
|
+
ErrorFragment.fromObject = function (value) {
|
|
783
819
|
if (ErrorFragment.isErrorFragment(value)) {
|
|
784
820
|
return value;
|
|
785
821
|
}
|
|
786
822
|
if (value.type !== "error") {
|
|
787
823
|
logger.throwArgumentError("invalid error object", "value", value);
|
|
788
824
|
}
|
|
789
|
-
|
|
825
|
+
var params = {
|
|
790
826
|
type: value.type,
|
|
791
827
|
name: verifyIdentifier(value.name),
|
|
792
828
|
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : [])
|
|
793
829
|
};
|
|
794
830
|
return checkForbidden(new ErrorFragment(_constructorGuard, params));
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
831
|
+
};
|
|
832
|
+
ErrorFragment.fromString = function (value) {
|
|
833
|
+
var params = { type: "error" };
|
|
834
|
+
var parens = value.match(regexParen);
|
|
799
835
|
if (!parens) {
|
|
800
836
|
logger.throwArgumentError("invalid error signature", "value", value);
|
|
801
837
|
}
|
|
@@ -805,11 +841,12 @@ class ErrorFragment extends Fragment {
|
|
|
805
841
|
}
|
|
806
842
|
params.inputs = parseParams(parens[2], false);
|
|
807
843
|
return checkForbidden(ErrorFragment.fromObject(params));
|
|
808
|
-
}
|
|
809
|
-
|
|
844
|
+
};
|
|
845
|
+
ErrorFragment.isErrorFragment = function (value) {
|
|
810
846
|
return (value && value._isFragment && value.type === "error");
|
|
811
|
-
}
|
|
812
|
-
|
|
847
|
+
};
|
|
848
|
+
return ErrorFragment;
|
|
849
|
+
}(Fragment));
|
|
813
850
|
exports.ErrorFragment = ErrorFragment;
|
|
814
851
|
function verifyType(type) {
|
|
815
852
|
// These need to be transformed to their full description
|
|
@@ -823,21 +860,21 @@ function verifyType(type) {
|
|
|
823
860
|
return type;
|
|
824
861
|
}
|
|
825
862
|
// See: https://github.com/ethereum/solidity/blob/1f8f1a3db93a548d0555e3e14cfc55a10e25b60e/docs/grammar/SolidityLexer.g4#L234
|
|
826
|
-
|
|
863
|
+
var regexIdentifier = new RegExp("^[a-zA-Z$_][a-zA-Z0-9$_]*$");
|
|
827
864
|
function verifyIdentifier(value) {
|
|
828
865
|
if (!value || !value.match(regexIdentifier)) {
|
|
829
|
-
logger.throwArgumentError(
|
|
866
|
+
logger.throwArgumentError("invalid identifier \"".concat(value, "\""), "value", value);
|
|
830
867
|
}
|
|
831
868
|
return value;
|
|
832
869
|
}
|
|
833
|
-
|
|
870
|
+
var regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
|
|
834
871
|
function splitNesting(value) {
|
|
835
872
|
value = value.trim();
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
for (
|
|
840
|
-
|
|
873
|
+
var result = [];
|
|
874
|
+
var accum = "";
|
|
875
|
+
var depth = 0;
|
|
876
|
+
for (var offset = 0; offset < value.length; offset++) {
|
|
877
|
+
var c = value[offset];
|
|
841
878
|
if (c === "," && depth === 0) {
|
|
842
879
|
result.push(accum);
|
|
843
880
|
accum = "";
|