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