@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.
Files changed (68) hide show
  1. package/README.md +3 -4
  2. package/lib/_version.d.ts +1 -1
  3. package/lib/_version.js +1 -1
  4. package/lib/abi-coder.d.ts.map +1 -1
  5. package/lib/abi-coder.js +54 -54
  6. package/lib/abi-coder.js.map +1 -1
  7. package/lib/coders/abstract-coder.d.ts.map +1 -1
  8. package/lib/coders/abstract-coder.js +75 -84
  9. package/lib/coders/abstract-coder.js.map +1 -1
  10. package/lib/coders/address.d.ts.map +1 -1
  11. package/lib/coders/address.js +15 -32
  12. package/lib/coders/address.js.map +1 -1
  13. package/lib/coders/anonymous.js +12 -30
  14. package/lib/coders/anonymous.js.map +1 -1
  15. package/lib/coders/array.d.ts.map +1 -1
  16. package/lib/coders/array.js +71 -87
  17. package/lib/coders/array.js.map +1 -1
  18. package/lib/coders/boolean.d.ts.map +1 -1
  19. package/lib/coders/boolean.js +11 -28
  20. package/lib/coders/boolean.js.map +1 -1
  21. package/lib/coders/bytes.js +20 -39
  22. package/lib/coders/bytes.js.map +1 -1
  23. package/lib/coders/fixed-bytes.d.ts.map +1 -1
  24. package/lib/coders/fixed-bytes.js +16 -35
  25. package/lib/coders/fixed-bytes.js.map +1 -1
  26. package/lib/coders/function.d.ts +8 -0
  27. package/lib/coders/function.d.ts.map +1 -0
  28. package/lib/coders/function.js +46 -0
  29. package/lib/coders/function.js.map +1 -0
  30. package/lib/coders/null.d.ts.map +1 -1
  31. package/lib/coders/null.js +11 -28
  32. package/lib/coders/null.js.map +1 -1
  33. package/lib/coders/number.js +20 -39
  34. package/lib/coders/number.js.map +1 -1
  35. package/lib/coders/string.d.ts.map +1 -1
  36. package/lib/coders/string.js +14 -31
  37. package/lib/coders/string.js.map +1 -1
  38. package/lib/coders/tuple.d.ts.map +1 -1
  39. package/lib/coders/tuple.js +23 -42
  40. package/lib/coders/tuple.js.map +1 -1
  41. package/lib/fragments.d.ts.map +1 -1
  42. package/lib/fragments.js +256 -231
  43. package/lib/fragments.js.map +1 -1
  44. package/lib/index.d.ts +1 -1
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +3 -3
  47. package/lib/index.js.map +1 -1
  48. package/lib/interface.d.ts +1 -1
  49. package/lib/interface.d.ts.map +1 -1
  50. package/lib/interface.js +240 -247
  51. package/lib/interface.js.map +1 -1
  52. package/package.json +35 -31
  53. package/src.ts/_version.ts +1 -1
  54. package/src.ts/abi-coder.ts +64 -26
  55. package/src.ts/coders/abstract-coder.ts +78 -33
  56. package/src.ts/coders/address.ts +3 -5
  57. package/src.ts/coders/array.ts +90 -47
  58. package/src.ts/coders/boolean.ts +1 -3
  59. package/src.ts/coders/bytes.ts +1 -3
  60. package/src.ts/coders/fixed-bytes.ts +7 -2
  61. package/src.ts/coders/function.ts +64 -0
  62. package/src.ts/coders/null.ts +4 -3
  63. package/src.ts/coders/number.ts +1 -2
  64. package/src.ts/coders/string.ts +0 -1
  65. package/src.ts/coders/tuple.ts +31 -16
  66. package/src.ts/fragments.ts +411 -178
  67. package/src.ts/index.ts +20 -8
  68. package/src.ts/interface.ts +405 -153
package/lib/interface.js CHANGED
@@ -1,75 +1,49 @@
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.Interface = exports.Indexed = exports.ErrorDescription = exports.TransactionDescription = exports.LogDescription = exports.checkResultErrors = void 0;
19
- var address_1 = require("@qevm/address");
20
- var bignumber_1 = require("@qevm/bignumber");
21
- var bytes_1 = require("@qevm/bytes");
22
- var hash_1 = require("@qevm/hash");
23
- var keccak256_1 = require("@qevm/keccak256");
24
- var properties_1 = require("@ethersproject/properties");
25
- var abi_coder_1 = require("./abi-coder");
26
- var abstract_coder_1 = require("./coders/abstract-coder");
4
+ const address_1 = require("@qevm/address");
5
+ const bignumber_1 = require("@qevm/bignumber");
6
+ const bytes_1 = require("@qevm/bytes");
7
+ const hash_1 = require("@qevm/hash");
8
+ const keccak256_1 = require("@qevm/keccak256");
9
+ const properties_1 = require("@qevm/properties");
10
+ const abi_coder_1 = require("./abi-coder");
11
+ const abstract_coder_1 = require("./coders/abstract-coder");
27
12
  Object.defineProperty(exports, "checkResultErrors", { enumerable: true, get: function () { return abstract_coder_1.checkResultErrors; } });
28
- var fragments_1 = require("./fragments");
29
- var logger_1 = require("@ethersproject/logger");
30
- var _version_1 = require("./_version");
31
- var logger = new logger_1.Logger(_version_1.version);
32
- var LogDescription = /** @class */ (function (_super) {
33
- __extends(LogDescription, _super);
34
- function LogDescription() {
35
- return _super !== null && _super.apply(this, arguments) || this;
36
- }
37
- return LogDescription;
38
- }(properties_1.Description));
13
+ const fragments_1 = require("./fragments");
14
+ const logger_1 = require("@qevm/logger");
15
+ const _version_1 = require("./_version");
16
+ const logger = new logger_1.Logger(_version_1.version);
17
+ class LogDescription extends properties_1.Description {
18
+ }
39
19
  exports.LogDescription = LogDescription;
40
- var TransactionDescription = /** @class */ (function (_super) {
41
- __extends(TransactionDescription, _super);
42
- function TransactionDescription() {
43
- return _super !== null && _super.apply(this, arguments) || this;
44
- }
45
- return TransactionDescription;
46
- }(properties_1.Description));
20
+ class TransactionDescription extends properties_1.Description {
21
+ }
47
22
  exports.TransactionDescription = TransactionDescription;
48
- var ErrorDescription = /** @class */ (function (_super) {
49
- __extends(ErrorDescription, _super);
50
- function ErrorDescription() {
51
- return _super !== null && _super.apply(this, arguments) || this;
52
- }
53
- return ErrorDescription;
54
- }(properties_1.Description));
23
+ class ErrorDescription extends properties_1.Description {
24
+ }
55
25
  exports.ErrorDescription = ErrorDescription;
56
- var Indexed = /** @class */ (function (_super) {
57
- __extends(Indexed, _super);
58
- function Indexed() {
59
- return _super !== null && _super.apply(this, arguments) || this;
60
- }
61
- Indexed.isIndexed = function (value) {
26
+ class Indexed extends properties_1.Description {
27
+ static isIndexed(value) {
62
28
  return !!(value && value._isIndexed);
63
- };
64
- return Indexed;
65
- }(properties_1.Description));
29
+ }
30
+ }
66
31
  exports.Indexed = Indexed;
67
- var BuiltinErrors = {
68
- "0x08c379a0": { signature: "Error(string)", name: "Error", inputs: ["string"], reason: true },
69
- "0x4e487b71": { signature: "Panic(uint256)", name: "Panic", inputs: ["uint256"] }
32
+ const BuiltinErrors = {
33
+ "0x08c379a0": {
34
+ signature: "Error(string)",
35
+ name: "Error",
36
+ inputs: ["string"],
37
+ reason: true,
38
+ },
39
+ "0x4e487b71": {
40
+ signature: "Panic(uint256)",
41
+ name: "Panic",
42
+ inputs: ["uint256"],
43
+ },
70
44
  };
71
45
  function wrapAccessError(property, error) {
72
- var wrap = new Error("deferred error during ABI decoding triggered accessing ".concat(property));
46
+ const wrap = new Error(`deferred error during ABI decoding triggered accessing ${property}`);
73
47
  wrap.error = error;
74
48
  return wrap;
75
49
  }
@@ -86,53 +60,53 @@ function checkNames(fragment: Fragment, type: "input" | "output", params: Array<
86
60
  }, <{ [ name: string ]: boolean }>{ });
87
61
  }
88
62
  */
89
- var Interface = /** @class */ (function () {
90
- function Interface(fragments) {
91
- var _newTarget = this.constructor;
92
- var _this = this;
93
- var abi = [];
94
- if (typeof (fragments) === "string") {
63
+ class Interface {
64
+ constructor(fragments) {
65
+ let abi = [];
66
+ if (typeof fragments === "string") {
95
67
  abi = JSON.parse(fragments);
96
68
  }
97
69
  else {
98
70
  abi = fragments;
99
71
  }
100
- (0, properties_1.defineReadOnly)(this, "fragments", abi.map(function (fragment) {
72
+ (0, properties_1.defineReadOnly)(this, "fragments", abi
73
+ .map((fragment) => {
101
74
  return fragments_1.Fragment.from(fragment);
102
- }).filter(function (fragment) { return (fragment != null); }));
103
- (0, properties_1.defineReadOnly)(this, "_abiCoder", (0, properties_1.getStatic)(_newTarget, "getAbiCoder")());
75
+ })
76
+ .filter((fragment) => fragment != null));
77
+ (0, properties_1.defineReadOnly)(this, "_abiCoder", (0, properties_1.getStatic)(new.target, "getAbiCoder")());
104
78
  (0, properties_1.defineReadOnly)(this, "functions", {});
105
79
  (0, properties_1.defineReadOnly)(this, "errors", {});
106
80
  (0, properties_1.defineReadOnly)(this, "events", {});
107
81
  (0, properties_1.defineReadOnly)(this, "structs", {});
108
82
  // Add all fragments by their signature
109
- this.fragments.forEach(function (fragment) {
110
- var bucket = null;
83
+ this.fragments.forEach((fragment) => {
84
+ let bucket = null;
111
85
  switch (fragment.type) {
112
86
  case "constructor":
113
- if (_this.deploy) {
87
+ if (this.deploy) {
114
88
  logger.warn("duplicate definition - constructor");
115
89
  return;
116
90
  }
117
91
  //checkNames(fragment, "input", fragment.inputs);
118
- (0, properties_1.defineReadOnly)(_this, "deploy", fragment);
92
+ (0, properties_1.defineReadOnly)(this, "deploy", fragment);
119
93
  return;
120
94
  case "function":
121
95
  //checkNames(fragment, "input", fragment.inputs);
122
96
  //checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
123
- bucket = _this.functions;
97
+ bucket = this.functions;
124
98
  break;
125
99
  case "event":
126
100
  //checkNames(fragment, "input", fragment.inputs);
127
- bucket = _this.events;
101
+ bucket = this.events;
128
102
  break;
129
103
  case "error":
130
- bucket = _this.errors;
104
+ bucket = this.errors;
131
105
  break;
132
106
  default:
133
107
  return;
134
108
  }
135
- var signature = fragment.format();
109
+ let signature = fragment.format();
136
110
  if (bucket[signature]) {
137
111
  logger.warn("duplicate definition - " + signature);
138
112
  return;
@@ -143,131 +117,131 @@ var Interface = /** @class */ (function () {
143
117
  if (!this.deploy) {
144
118
  (0, properties_1.defineReadOnly)(this, "deploy", fragments_1.ConstructorFragment.from({
145
119
  payable: false,
146
- type: "constructor"
120
+ type: "constructor",
147
121
  }));
148
122
  }
149
123
  (0, properties_1.defineReadOnly)(this, "_isInterface", true);
150
124
  }
151
- Interface.prototype.format = function (format) {
125
+ format(format) {
152
126
  if (!format) {
153
127
  format = fragments_1.FormatTypes.full;
154
128
  }
155
129
  if (format === fragments_1.FormatTypes.sighash) {
156
130
  logger.throwArgumentError("interface does not support formatting sighash", "format", format);
157
131
  }
158
- var abi = this.fragments.map(function (fragment) { return fragment.format(format); });
132
+ const abi = this.fragments.map((fragment) => fragment.format(format));
159
133
  // We need to re-bundle the JSON fragments a bit
160
134
  if (format === fragments_1.FormatTypes.json) {
161
- return JSON.stringify(abi.map(function (j) { return JSON.parse(j); }));
135
+ return JSON.stringify(abi.map((j) => JSON.parse(j)));
162
136
  }
163
137
  return abi;
164
- };
138
+ }
165
139
  // Sub-classes can override these to handle other blockchains
166
- Interface.getAbiCoder = function () {
140
+ static getAbiCoder() {
167
141
  return abi_coder_1.defaultAbiCoder;
168
- };
169
- Interface.getAddress = function (address) {
142
+ }
143
+ static getAddress(address) {
170
144
  return (0, address_1.getAddress)(address);
171
- };
172
- Interface.getSighash = function (fragment) {
145
+ }
146
+ static getSighash(fragment) {
173
147
  return (0, bytes_1.hexDataSlice)((0, hash_1.id)(fragment.format()), 0, 4);
174
- };
175
- Interface.getEventTopic = function (eventFragment) {
148
+ }
149
+ static getEventTopic(eventFragment) {
176
150
  return (0, hash_1.id)(eventFragment.format());
177
- };
151
+ }
178
152
  // Find a function definition by any means necessary (unless it is ambiguous)
179
- Interface.prototype.getFunction = function (nameOrSignatureOrSighash) {
153
+ getFunction(nameOrSignatureOrSighash) {
180
154
  if ((0, bytes_1.isHexString)(nameOrSignatureOrSighash)) {
181
- for (var name_1 in this.functions) {
182
- if (nameOrSignatureOrSighash === this.getSighash(name_1)) {
183
- return this.functions[name_1];
155
+ for (const name in this.functions) {
156
+ if (nameOrSignatureOrSighash === this.getSighash(name)) {
157
+ return this.functions[name];
184
158
  }
185
159
  }
186
160
  logger.throwArgumentError("no matching function", "sighash", nameOrSignatureOrSighash);
187
161
  }
188
162
  // It is a bare name, look up the function (will return null if ambiguous)
189
163
  if (nameOrSignatureOrSighash.indexOf("(") === -1) {
190
- var name_2 = nameOrSignatureOrSighash.trim();
191
- var matching = Object.keys(this.functions).filter(function (f) { return (f.split("(" /* fix:) */)[0] === name_2); });
164
+ const name = nameOrSignatureOrSighash.trim();
165
+ const matching = Object.keys(this.functions).filter((f) => f.split("(" /* fix:) */)[0] === name);
192
166
  if (matching.length === 0) {
193
- logger.throwArgumentError("no matching function", "name", name_2);
167
+ logger.throwArgumentError("no matching function", "name", name);
194
168
  }
195
169
  else if (matching.length > 1) {
196
- logger.throwArgumentError("multiple matching functions", "name", name_2);
170
+ logger.throwArgumentError("multiple matching functions", "name", name);
197
171
  }
198
172
  return this.functions[matching[0]];
199
173
  }
200
174
  // Normalize the signature and lookup the function
201
- var result = this.functions[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
175
+ const result = this.functions[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
202
176
  if (!result) {
203
177
  logger.throwArgumentError("no matching function", "signature", nameOrSignatureOrSighash);
204
178
  }
205
179
  return result;
206
- };
180
+ }
207
181
  // Find an event definition by any means necessary (unless it is ambiguous)
208
- Interface.prototype.getEvent = function (nameOrSignatureOrTopic) {
182
+ getEvent(nameOrSignatureOrTopic) {
209
183
  if ((0, bytes_1.isHexString)(nameOrSignatureOrTopic)) {
210
- var topichash = nameOrSignatureOrTopic.toLowerCase();
211
- for (var name_3 in this.events) {
212
- if (topichash === this.getEventTopic(name_3)) {
213
- return this.events[name_3];
184
+ const topichash = nameOrSignatureOrTopic.toLowerCase();
185
+ for (const name in this.events) {
186
+ if (topichash === this.getEventTopic(name)) {
187
+ return this.events[name];
214
188
  }
215
189
  }
216
190
  logger.throwArgumentError("no matching event", "topichash", topichash);
217
191
  }
218
192
  // It is a bare name, look up the function (will return null if ambiguous)
219
193
  if (nameOrSignatureOrTopic.indexOf("(") === -1) {
220
- var name_4 = nameOrSignatureOrTopic.trim();
221
- var matching = Object.keys(this.events).filter(function (f) { return (f.split("(" /* fix:) */)[0] === name_4); });
194
+ const name = nameOrSignatureOrTopic.trim();
195
+ const matching = Object.keys(this.events).filter((f) => f.split("(" /* fix:) */)[0] === name);
222
196
  if (matching.length === 0) {
223
- logger.throwArgumentError("no matching event", "name", name_4);
197
+ logger.throwArgumentError("no matching event", "name", name);
224
198
  }
225
199
  else if (matching.length > 1) {
226
- logger.throwArgumentError("multiple matching events", "name", name_4);
200
+ logger.throwArgumentError("multiple matching events", "name", name);
227
201
  }
228
202
  return this.events[matching[0]];
229
203
  }
230
204
  // Normalize the signature and lookup the function
231
- var result = this.events[fragments_1.EventFragment.fromString(nameOrSignatureOrTopic).format()];
205
+ const result = this.events[fragments_1.EventFragment.fromString(nameOrSignatureOrTopic).format()];
232
206
  if (!result) {
233
207
  logger.throwArgumentError("no matching event", "signature", nameOrSignatureOrTopic);
234
208
  }
235
209
  return result;
236
- };
210
+ }
237
211
  // Find a function definition by any means necessary (unless it is ambiguous)
238
- Interface.prototype.getError = function (nameOrSignatureOrSighash) {
212
+ getError(nameOrSignatureOrSighash) {
239
213
  if ((0, bytes_1.isHexString)(nameOrSignatureOrSighash)) {
240
- var getSighash = (0, properties_1.getStatic)(this.constructor, "getSighash");
241
- for (var name_5 in this.errors) {
242
- var error = this.errors[name_5];
214
+ const getSighash = (0, properties_1.getStatic)(this.constructor, "getSighash");
215
+ for (const name in this.errors) {
216
+ const error = this.errors[name];
243
217
  if (nameOrSignatureOrSighash === getSighash(error)) {
244
- return this.errors[name_5];
218
+ return this.errors[name];
245
219
  }
246
220
  }
247
221
  logger.throwArgumentError("no matching error", "sighash", nameOrSignatureOrSighash);
248
222
  }
249
223
  // It is a bare name, look up the function (will return null if ambiguous)
250
224
  if (nameOrSignatureOrSighash.indexOf("(") === -1) {
251
- var name_6 = nameOrSignatureOrSighash.trim();
252
- var matching = Object.keys(this.errors).filter(function (f) { return (f.split("(" /* fix:) */)[0] === name_6); });
225
+ const name = nameOrSignatureOrSighash.trim();
226
+ const matching = Object.keys(this.errors).filter((f) => f.split("(" /* fix:) */)[0] === name);
253
227
  if (matching.length === 0) {
254
- logger.throwArgumentError("no matching error", "name", name_6);
228
+ logger.throwArgumentError("no matching error", "name", name);
255
229
  }
256
230
  else if (matching.length > 1) {
257
- logger.throwArgumentError("multiple matching errors", "name", name_6);
231
+ logger.throwArgumentError("multiple matching errors", "name", name);
258
232
  }
259
233
  return this.errors[matching[0]];
260
234
  }
261
235
  // Normalize the signature and lookup the function
262
- var result = this.errors[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
236
+ const result = this.errors[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
263
237
  if (!result) {
264
238
  logger.throwArgumentError("no matching error", "signature", nameOrSignatureOrSighash);
265
239
  }
266
240
  return result;
267
- };
241
+ }
268
242
  // Get the sighash (the bytes4 selector) used by Solidity to identify a function
269
- Interface.prototype.getSighash = function (fragment) {
270
- if (typeof (fragment) === "string") {
243
+ getSighash(fragment) {
244
+ if (typeof fragment === "string") {
271
245
  try {
272
246
  fragment = this.getFunction(fragment);
273
247
  }
@@ -281,74 +255,74 @@ var Interface = /** @class */ (function () {
281
255
  }
282
256
  }
283
257
  return (0, properties_1.getStatic)(this.constructor, "getSighash")(fragment);
284
- };
258
+ }
285
259
  // Get the topic (the bytes32 hash) used by Solidity to identify an event
286
- Interface.prototype.getEventTopic = function (eventFragment) {
287
- if (typeof (eventFragment) === "string") {
260
+ getEventTopic(eventFragment) {
261
+ if (typeof eventFragment === "string") {
288
262
  eventFragment = this.getEvent(eventFragment);
289
263
  }
290
264
  return (0, properties_1.getStatic)(this.constructor, "getEventTopic")(eventFragment);
291
- };
292
- Interface.prototype._decodeParams = function (params, data) {
265
+ }
266
+ _decodeParams(params, data) {
293
267
  return this._abiCoder.decode(params, data);
294
- };
295
- Interface.prototype._encodeParams = function (params, values) {
268
+ }
269
+ _encodeParams(params, values) {
296
270
  return this._abiCoder.encode(params, values);
297
- };
298
- Interface.prototype.encodeDeploy = function (values) {
271
+ }
272
+ encodeDeploy(values) {
299
273
  return this._encodeParams(this.deploy.inputs, values || []);
300
- };
301
- Interface.prototype.decodeErrorResult = function (fragment, data) {
302
- if (typeof (fragment) === "string") {
274
+ }
275
+ decodeErrorResult(fragment, data) {
276
+ if (typeof fragment === "string") {
303
277
  fragment = this.getError(fragment);
304
278
  }
305
- var bytes = (0, bytes_1.arrayify)(data);
279
+ const bytes = (0, bytes_1.arrayify)(data);
306
280
  if ((0, bytes_1.hexlify)(bytes.slice(0, 4)) !== this.getSighash(fragment)) {
307
- logger.throwArgumentError("data signature does not match error ".concat(fragment.name, "."), "data", (0, bytes_1.hexlify)(bytes));
281
+ logger.throwArgumentError(`data signature does not match error ${fragment.name}.`, "data", (0, bytes_1.hexlify)(bytes));
308
282
  }
309
283
  return this._decodeParams(fragment.inputs, bytes.slice(4));
310
- };
311
- Interface.prototype.encodeErrorResult = function (fragment, values) {
312
- if (typeof (fragment) === "string") {
284
+ }
285
+ encodeErrorResult(fragment, values) {
286
+ if (typeof fragment === "string") {
313
287
  fragment = this.getError(fragment);
314
288
  }
315
289
  return (0, bytes_1.hexlify)((0, bytes_1.concat)([
316
290
  this.getSighash(fragment),
317
- this._encodeParams(fragment.inputs, values || [])
291
+ this._encodeParams(fragment.inputs, values || []),
318
292
  ]));
319
- };
293
+ }
320
294
  // Decode the data for a function call (e.g. tx.data)
321
- Interface.prototype.decodeFunctionData = function (functionFragment, data) {
322
- if (typeof (functionFragment) === "string") {
295
+ decodeFunctionData(functionFragment, data) {
296
+ if (typeof functionFragment === "string") {
323
297
  functionFragment = this.getFunction(functionFragment);
324
298
  }
325
- var bytes = (0, bytes_1.arrayify)(data);
299
+ const bytes = (0, bytes_1.arrayify)(data);
326
300
  if ((0, bytes_1.hexlify)(bytes.slice(0, 4)) !== this.getSighash(functionFragment)) {
327
- logger.throwArgumentError("data signature does not match function ".concat(functionFragment.name, "."), "data", (0, bytes_1.hexlify)(bytes));
301
+ logger.throwArgumentError(`data signature does not match function ${functionFragment.name}.`, "data", (0, bytes_1.hexlify)(bytes));
328
302
  }
329
303
  return this._decodeParams(functionFragment.inputs, bytes.slice(4));
330
- };
304
+ }
331
305
  // Encode the data for a function call (e.g. tx.data)
332
- Interface.prototype.encodeFunctionData = function (functionFragment, values) {
333
- if (typeof (functionFragment) === "string") {
306
+ encodeFunctionData(functionFragment, values) {
307
+ if (typeof functionFragment === "string") {
334
308
  functionFragment = this.getFunction(functionFragment);
335
309
  }
336
310
  return (0, bytes_1.hexlify)((0, bytes_1.concat)([
337
311
  this.getSighash(functionFragment),
338
- this._encodeParams(functionFragment.inputs, values || [])
312
+ this._encodeParams(functionFragment.inputs, values || []),
339
313
  ]));
340
- };
314
+ }
341
315
  // Decode the result from a function call (e.g. from eth_call)
342
- Interface.prototype.decodeFunctionResult = function (functionFragment, data) {
343
- if (typeof (functionFragment) === "string") {
316
+ decodeFunctionResult(functionFragment, data) {
317
+ if (typeof functionFragment === "string") {
344
318
  functionFragment = this.getFunction(functionFragment);
345
319
  }
346
- var bytes = (0, bytes_1.arrayify)(data);
347
- var reason = null;
348
- var message = "";
349
- var errorArgs = null;
350
- var errorName = null;
351
- var errorSignature = null;
320
+ let bytes = (0, bytes_1.arrayify)(data);
321
+ let reason = null;
322
+ let message = "";
323
+ let errorArgs = null;
324
+ let errorName = null;
325
+ let errorSignature = null;
352
326
  switch (bytes.length % this._abiCoder._getWordSize()) {
353
327
  case 0:
354
328
  try {
@@ -357,8 +331,8 @@ var Interface = /** @class */ (function () {
357
331
  catch (error) { }
358
332
  break;
359
333
  case 4: {
360
- var selector = (0, bytes_1.hexlify)(bytes.slice(0, 4));
361
- var builtin = BuiltinErrors[selector];
334
+ const selector = (0, bytes_1.hexlify)(bytes.slice(0, 4));
335
+ const builtin = BuiltinErrors[selector];
362
336
  if (builtin) {
363
337
  errorArgs = this._abiCoder.decode(builtin.inputs, bytes.slice(4));
364
338
  errorName = builtin.name;
@@ -367,15 +341,15 @@ var Interface = /** @class */ (function () {
367
341
  reason = errorArgs[0];
368
342
  }
369
343
  if (errorName === "Error") {
370
- message = "; VM Exception while processing transaction: reverted with reason string ".concat(JSON.stringify(errorArgs[0]));
344
+ message = `; VM Exception while processing transaction: reverted with reason string ${JSON.stringify(errorArgs[0])}`;
371
345
  }
372
346
  else if (errorName === "Panic") {
373
- message = "; VM Exception while processing transaction: reverted with panic code ".concat(errorArgs[0]);
347
+ message = `; VM Exception while processing transaction: reverted with panic code ${errorArgs[0]}`;
374
348
  }
375
349
  }
376
350
  else {
377
351
  try {
378
- var error = this.getError(selector);
352
+ const error = this.getError(selector);
379
353
  errorArgs = this._abiCoder.decode(error.inputs, bytes.slice(4));
380
354
  errorName = error.name;
381
355
  errorSignature = error.format();
@@ -388,70 +362,70 @@ var Interface = /** @class */ (function () {
388
362
  return logger.throwError("call revert exception" + message, logger_1.Logger.errors.CALL_EXCEPTION, {
389
363
  method: functionFragment.format(),
390
364
  data: (0, bytes_1.hexlify)(data),
391
- errorArgs: errorArgs,
392
- errorName: errorName,
393
- errorSignature: errorSignature,
394
- reason: reason
365
+ errorArgs,
366
+ errorName,
367
+ errorSignature,
368
+ reason,
395
369
  });
396
- };
370
+ }
397
371
  // Encode the result for a function call (e.g. for eth_call)
398
- Interface.prototype.encodeFunctionResult = function (functionFragment, values) {
399
- if (typeof (functionFragment) === "string") {
372
+ encodeFunctionResult(functionFragment, values) {
373
+ if (typeof functionFragment === "string") {
400
374
  functionFragment = this.getFunction(functionFragment);
401
375
  }
402
376
  return (0, bytes_1.hexlify)(this._abiCoder.encode(functionFragment.outputs, values || []));
403
- };
377
+ }
404
378
  // Create the filter for the event with search criteria (e.g. for eth_filterLog)
405
- Interface.prototype.encodeFilterTopics = function (eventFragment, values) {
406
- var _this = this;
407
- if (typeof (eventFragment) === "string") {
379
+ encodeFilterTopics(eventFragment, values) {
380
+ if (typeof eventFragment === "string") {
408
381
  eventFragment = this.getEvent(eventFragment);
409
382
  }
410
383
  if (values.length > eventFragment.inputs.length) {
411
384
  logger.throwError("too many arguments for " + eventFragment.format(), logger_1.Logger.errors.UNEXPECTED_ARGUMENT, {
412
385
  argument: "values",
413
- value: values
386
+ value: values,
414
387
  });
415
388
  }
416
- var topics = [];
389
+ let topics = [];
417
390
  if (!eventFragment.anonymous) {
418
391
  topics.push(this.getEventTopic(eventFragment));
419
392
  }
420
- var encodeTopic = function (param, value) {
393
+ const encodeTopic = (param, value) => {
421
394
  if (param.type === "string") {
422
395
  return (0, hash_1.id)(value);
423
396
  }
424
397
  else if (param.type === "bytes") {
425
398
  return (0, keccak256_1.keccak256)((0, bytes_1.hexlify)(value));
426
399
  }
427
- if (param.type === "bool" && typeof (value) === "boolean") {
428
- value = (value ? "0x01" : "0x00");
400
+ if (param.type === "bool" && typeof value === "boolean") {
401
+ value = value ? "0x01" : "0x00";
429
402
  }
430
403
  if (param.type.match(/^u?int/)) {
431
404
  value = bignumber_1.BigNumber.from(value).toHexString();
432
405
  }
433
406
  // Check addresses are valid
434
407
  if (param.type === "address") {
435
- _this._abiCoder.encode(["address"], [value]);
408
+ this._abiCoder.encode(["address"], [value]);
436
409
  }
437
410
  return (0, bytes_1.hexZeroPad)((0, bytes_1.hexlify)(value), 32);
438
411
  };
439
- values.forEach(function (value, index) {
440
- var param = eventFragment.inputs[index];
412
+ values.forEach((value, index) => {
413
+ let param = eventFragment.inputs[index];
441
414
  if (!param.indexed) {
442
415
  if (value != null) {
443
- logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
416
+ logger.throwArgumentError("cannot filter non-indexed parameters; must be null", "contract." + param.name, value);
444
417
  }
445
418
  return;
446
419
  }
447
420
  if (value == null) {
448
421
  topics.push(null);
449
422
  }
450
- else if (param.baseType === "array" || param.baseType === "tuple") {
451
- logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
423
+ else if (param.baseType === "array" ||
424
+ param.baseType === "tuple") {
425
+ logger.throwArgumentError("filtering with tuples or arrays not supported", "contract." + param.name, value);
452
426
  }
453
427
  else if (Array.isArray(value)) {
454
- topics.push(value.map(function (value) { return encodeTopic(param, value); }));
428
+ topics.push(value.map((value) => encodeTopic(param, value)));
455
429
  }
456
430
  else {
457
431
  topics.push(encodeTopic(param, value));
@@ -462,23 +436,22 @@ var Interface = /** @class */ (function () {
462
436
  topics.pop();
463
437
  }
464
438
  return topics;
465
- };
466
- Interface.prototype.encodeEventLog = function (eventFragment, values) {
467
- var _this = this;
468
- if (typeof (eventFragment) === "string") {
439
+ }
440
+ encodeEventLog(eventFragment, values) {
441
+ if (typeof eventFragment === "string") {
469
442
  eventFragment = this.getEvent(eventFragment);
470
443
  }
471
- var topics = [];
472
- var dataTypes = [];
473
- var dataValues = [];
444
+ const topics = [];
445
+ const dataTypes = [];
446
+ const dataValues = [];
474
447
  if (!eventFragment.anonymous) {
475
448
  topics.push(this.getEventTopic(eventFragment));
476
449
  }
477
450
  if (values.length !== eventFragment.inputs.length) {
478
451
  logger.throwArgumentError("event arguments/values mismatch", "values", values);
479
452
  }
480
- eventFragment.inputs.forEach(function (param, index) {
481
- var value = values[index];
453
+ eventFragment.inputs.forEach((param, index) => {
454
+ const value = values[index];
482
455
  if (param.indexed) {
483
456
  if (param.type === "string") {
484
457
  topics.push((0, hash_1.id)(value));
@@ -486,12 +459,13 @@ var Interface = /** @class */ (function () {
486
459
  else if (param.type === "bytes") {
487
460
  topics.push((0, keccak256_1.keccak256)(value));
488
461
  }
489
- else if (param.baseType === "tuple" || param.baseType === "array") {
462
+ else if (param.baseType === "tuple" ||
463
+ param.baseType === "array") {
490
464
  // @TODO
491
465
  throw new Error("not implemented");
492
466
  }
493
467
  else {
494
- topics.push(_this._abiCoder.encode([param.type], [value]));
468
+ topics.push(this._abiCoder.encode([param.type], [value]));
495
469
  }
496
470
  }
497
471
  else {
@@ -501,28 +475,39 @@ var Interface = /** @class */ (function () {
501
475
  });
502
476
  return {
503
477
  data: this._abiCoder.encode(dataTypes, dataValues),
504
- topics: topics
478
+ topics: topics,
505
479
  };
506
- };
480
+ }
507
481
  // Decode a filter for the event and the search criteria
508
- Interface.prototype.decodeEventLog = function (eventFragment, data, topics) {
509
- if (typeof (eventFragment) === "string") {
482
+ decodeEventLog(eventFragment, data, topics) {
483
+ if (typeof eventFragment === "string") {
510
484
  eventFragment = this.getEvent(eventFragment);
511
485
  }
512
486
  if (topics != null && !eventFragment.anonymous) {
513
- var topicHash = this.getEventTopic(eventFragment);
514
- if (!(0, bytes_1.isHexString)(topics[0], 32) || topics[0].toLowerCase() !== topicHash) {
515
- logger.throwError("fragment/topic mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "topics[0]", expected: topicHash, value: topics[0] });
487
+ let topicHash = this.getEventTopic(eventFragment);
488
+ if (!(0, bytes_1.isHexString)(topics[0], 32) ||
489
+ topics[0].toLowerCase() !== topicHash) {
490
+ logger.throwError("fragment/topic mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, {
491
+ argument: "topics[0]",
492
+ expected: topicHash,
493
+ value: topics[0],
494
+ });
516
495
  }
517
496
  topics = topics.slice(1);
518
497
  }
519
- var indexed = [];
520
- var nonIndexed = [];
521
- var dynamic = [];
522
- eventFragment.inputs.forEach(function (param, index) {
498
+ let indexed = [];
499
+ let nonIndexed = [];
500
+ let dynamic = [];
501
+ eventFragment.inputs.forEach((param, index) => {
523
502
  if (param.indexed) {
524
- if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
525
- indexed.push(fragments_1.ParamType.fromObject({ type: "bytes32", name: param.name }));
503
+ if (param.type === "string" ||
504
+ param.type === "bytes" ||
505
+ param.baseType === "tuple" ||
506
+ param.baseType === "array") {
507
+ indexed.push(fragments_1.ParamType.fromObject({
508
+ type: "bytes32",
509
+ name: param.name,
510
+ }));
526
511
  dynamic.push(true);
527
512
  }
528
513
  else {
@@ -535,17 +520,25 @@ var Interface = /** @class */ (function () {
535
520
  dynamic.push(false);
536
521
  }
537
522
  });
538
- var resultIndexed = (topics != null) ? this._abiCoder.decode(indexed, (0, bytes_1.concat)(topics)) : null;
539
- var resultNonIndexed = this._abiCoder.decode(nonIndexed, data, true);
540
- var result = [];
541
- var nonIndexedIndex = 0, indexedIndex = 0;
542
- eventFragment.inputs.forEach(function (param, index) {
523
+ let resultIndexed = topics != null
524
+ ? this._abiCoder.decode(indexed, (0, bytes_1.concat)(topics))
525
+ : null;
526
+ let resultNonIndexed = this._abiCoder.decode(nonIndexed, data, true);
527
+ let result = [];
528
+ let nonIndexedIndex = 0, indexedIndex = 0;
529
+ eventFragment.inputs.forEach((param, index) => {
543
530
  if (param.indexed) {
544
531
  if (resultIndexed == null) {
545
- result[index] = new Indexed({ _isIndexed: true, hash: null });
532
+ result[index] = new Indexed({
533
+ _isIndexed: true,
534
+ hash: null,
535
+ });
546
536
  }
547
537
  else if (dynamic[index]) {
548
- result[index] = new Indexed({ _isIndexed: true, hash: resultIndexed[indexedIndex++] });
538
+ result[index] = new Indexed({
539
+ _isIndexed: true,
540
+ hash: resultIndexed[indexedIndex++],
541
+ });
549
542
  }
550
543
  else {
551
544
  try {
@@ -566,38 +559,39 @@ var Interface = /** @class */ (function () {
566
559
  }
567
560
  // Add the keyword argument if named and safe
568
561
  if (param.name && result[param.name] == null) {
569
- var value_1 = result[index];
562
+ const value = result[index];
570
563
  // Make error named values throw on access
571
- if (value_1 instanceof Error) {
564
+ if (value instanceof Error) {
572
565
  Object.defineProperty(result, param.name, {
573
566
  enumerable: true,
574
- get: function () { throw wrapAccessError("property ".concat(JSON.stringify(param.name)), value_1); }
567
+ get: () => {
568
+ throw wrapAccessError(`property ${JSON.stringify(param.name)}`, value);
569
+ },
575
570
  });
576
571
  }
577
572
  else {
578
- result[param.name] = value_1;
573
+ result[param.name] = value;
579
574
  }
580
575
  }
581
576
  });
582
- var _loop_1 = function (i) {
583
- var value = result[i];
577
+ // Make all error indexed values throw on access
578
+ for (let i = 0; i < result.length; i++) {
579
+ const value = result[i];
584
580
  if (value instanceof Error) {
585
581
  Object.defineProperty(result, i, {
586
582
  enumerable: true,
587
- get: function () { throw wrapAccessError("index ".concat(i), value); }
583
+ get: () => {
584
+ throw wrapAccessError(`index ${i}`, value);
585
+ },
588
586
  });
589
587
  }
590
- };
591
- // Make all error indexed values throw on access
592
- for (var i = 0; i < result.length; i++) {
593
- _loop_1(i);
594
588
  }
595
589
  return Object.freeze(result);
596
- };
590
+ }
597
591
  // Given a transaction, find the matching function fragment (if any) and
598
592
  // determine all its properties and call parameters
599
- Interface.prototype.parseTransaction = function (tx) {
600
- var fragment = this.getFunction(tx.data.substring(0, 10).toLowerCase());
593
+ parseTransaction(tx) {
594
+ let fragment = this.getFunction(tx.data.substring(0, 10).toLowerCase());
601
595
  if (!fragment) {
602
596
  return null;
603
597
  }
@@ -609,13 +603,13 @@ var Interface = /** @class */ (function () {
609
603
  sighash: this.getSighash(fragment),
610
604
  value: bignumber_1.BigNumber.from(tx.value || "0"),
611
605
  });
612
- };
606
+ }
613
607
  // @TODO
614
608
  //parseCallResult(data: BytesLike): ??
615
609
  // Given an event log, find the matching event fragment (if any) and
616
610
  // determine all its properties and values
617
- Interface.prototype.parseLog = function (log) {
618
- var fragment = this.getEvent(log.topics[0]);
611
+ parseLog(log) {
612
+ let fragment = this.getEvent(log.topics[0]);
619
613
  if (!fragment || fragment.anonymous) {
620
614
  return null;
621
615
  }
@@ -627,12 +621,12 @@ var Interface = /** @class */ (function () {
627
621
  name: fragment.name,
628
622
  signature: fragment.format(),
629
623
  topic: this.getEventTopic(fragment),
630
- args: this.decodeEventLog(fragment, log.data, log.topics)
624
+ args: this.decodeEventLog(fragment, log.data, log.topics),
631
625
  });
632
- };
633
- Interface.prototype.parseError = function (data) {
634
- var hexData = (0, bytes_1.hexlify)(data);
635
- var fragment = this.getError(hexData.substring(0, 10).toLowerCase());
626
+ }
627
+ parseError(data) {
628
+ const hexData = (0, bytes_1.hexlify)(data);
629
+ let fragment = this.getError(hexData.substring(0, 10).toLowerCase());
636
630
  if (!fragment) {
637
631
  return null;
638
632
  }
@@ -643,7 +637,7 @@ var Interface = /** @class */ (function () {
643
637
  signature: fragment.format(),
644
638
  sighash: this.getSighash(fragment),
645
639
  });
646
- };
640
+ }
647
641
  /*
648
642
  static from(value: Array<Fragment | string | JsonAbi> | string | Interface) {
649
643
  if (Interface.isInterface(value)) {
@@ -655,10 +649,9 @@ var Interface = /** @class */ (function () {
655
649
  return new Interface(value);
656
650
  }
657
651
  */
658
- Interface.isInterface = function (value) {
652
+ static isInterface(value) {
659
653
  return !!(value && value._isInterface);
660
- };
661
- return Interface;
662
- }());
654
+ }
655
+ }
663
656
  exports.Interface = Interface;
664
657
  //# sourceMappingURL=interface.js.map