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