Current Folder
This commit is contained in:
1 parent
8b3382289b
commit
cfcada880d
4379 files changed
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
export const version = "abi/5.0.0-beta.153";
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
||||
import { arrayify } from "@ethersproject/bytes";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
import { Reader, Writer } from "./coders/abstract-coder";
|
||||
import { AddressCoder } from "./coders/address";
|
||||
import { ArrayCoder } from "./coders/array";
|
||||
import { BooleanCoder } from "./coders/boolean";
|
||||
import { BytesCoder } from "./coders/bytes";
|
||||
import { FixedBytesCoder } from "./coders/fixed-bytes";
|
||||
import { NullCoder } from "./coders/null";
|
||||
import { NumberCoder } from "./coders/number";
|
||||
import { StringCoder } from "./coders/string";
|
||||
import { TupleCoder } from "./coders/tuple";
|
||||
import { ParamType } from "./fragments";
|
||||
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
||||
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
||||
export class AbiCoder {
|
||||
constructor(coerceFunc) {
|
||||
logger.checkNew(new.target, AbiCoder);
|
||||
defineReadOnly(this, "coerceFunc", coerceFunc || null);
|
||||
}
|
||||
_getCoder(param) {
|
||||
switch (param.baseType) {
|
||||
case "address":
|
||||
return new AddressCoder(param.name);
|
||||
case "bool":
|
||||
return new BooleanCoder(param.name);
|
||||
case "string":
|
||||
return new StringCoder(param.name);
|
||||
case "bytes":
|
||||
return new BytesCoder(param.name);
|
||||
case "array":
|
||||
return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
|
||||
case "tuple":
|
||||
return new TupleCoder((param.components || []).map((component) => {
|
||||
return this._getCoder(component);
|
||||
}), param.name);
|
||||
case "":
|
||||
return new NullCoder(param.name);
|
||||
}
|
||||
// u?int[0-9]*
|
||||
let match = param.type.match(paramTypeNumber);
|
||||
if (match) {
|
||||
let size = parseInt(match[2] || "256");
|
||||
if (size === 0 || size > 256 || (size % 8) !== 0) {
|
||||
logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
|
||||
}
|
||||
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
|
||||
}
|
||||
// bytes[0-9]+
|
||||
match = param.type.match(paramTypeBytes);
|
||||
if (match) {
|
||||
let size = parseInt(match[1]);
|
||||
if (size === 0 || size > 32) {
|
||||
logger.throwArgumentError("invalid bytes length", "param", param);
|
||||
}
|
||||
return new FixedBytesCoder(size, param.name);
|
||||
}
|
||||
return logger.throwArgumentError("invalid type", "type", param.type);
|
||||
}
|
||||
_getWordSize() { return 32; }
|
||||
_getReader(data) {
|
||||
return new Reader(data, this._getWordSize(), this.coerceFunc);
|
||||
}
|
||||
_getWriter() {
|
||||
return new Writer(this._getWordSize());
|
||||
}
|
||||
encode(types, values) {
|
||||
if (types.length !== values.length) {
|
||||
logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, {
|
||||
count: { types: types.length, values: values.length },
|
||||
value: { types: types, values: values }
|
||||
});
|
||||
}
|
||||
const coders = types.map((type) => this._getCoder(ParamType.from(type)));
|
||||
const coder = (new TupleCoder(coders, "_"));
|
||||
const writer = this._getWriter();
|
||||
coder.encode(writer, values);
|
||||
return writer.data;
|
||||
}
|
||||
decode(types, data) {
|
||||
const coders = types.map((type) => this._getCoder(ParamType.from(type)));
|
||||
const coder = new TupleCoder(coders, "_");
|
||||
return coder.decode(this._getReader(arrayify(data)));
|
||||
}
|
||||
}
|
||||
export const defaultAbiCoder = new AbiCoder();
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
import { arrayify, concat, hexlify } from "@ethersproject/bytes";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "../_version";
|
||||
const logger = new Logger(version);
|
||||
export function checkResultErrors(result) {
|
||||
// Find the first error (if any)
|
||||
const errors = [];
|
||||
const checkErrors = function (path, object) {
|
||||
if (!Array.isArray(object)) {
|
||||
return;
|
||||
}
|
||||
for (let key in object) {
|
||||
const childPath = path.slice();
|
||||
childPath.push(key);
|
||||
try {
|
||||
checkErrors(childPath, object[key]);
|
||||
}
|
||||
catch (error) {
|
||||
errors.push({ path: childPath, error: error });
|
||||
}
|
||||
}
|
||||
};
|
||||
checkErrors([], result);
|
||||
return errors;
|
||||
}
|
||||
export class Coder {
|
||||
constructor(name, type, localName, dynamic) {
|
||||
// @TODO: defineReadOnly these
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.localName = localName;
|
||||
this.dynamic = dynamic;
|
||||
}
|
||||
_throwError(message, value) {
|
||||
logger.throwArgumentError(message, this.localName, value);
|
||||
}
|
||||
}
|
||||
export class Writer {
|
||||
constructor(wordSize) {
|
||||
defineReadOnly(this, "wordSize", wordSize || 32);
|
||||
this._data = arrayify([]);
|
||||
this._padding = new Uint8Array(wordSize);
|
||||
}
|
||||
get data() { return hexlify(this._data); }
|
||||
get length() { return this._data.length; }
|
||||
_writeData(data) {
|
||||
this._data = concat([this._data, data]);
|
||||
return data.length;
|
||||
}
|
||||
// Arrayish items; padded on the right to wordSize
|
||||
writeBytes(value) {
|
||||
let bytes = arrayify(value);
|
||||
if (bytes.length % this.wordSize) {
|
||||
bytes = concat([bytes, this._padding.slice(bytes.length % this.wordSize)]);
|
||||
}
|
||||
return this._writeData(bytes);
|
||||
}
|
||||
_getValue(value) {
|
||||
let bytes = arrayify(BigNumber.from(value));
|
||||
if (bytes.length > this.wordSize) {
|
||||
logger.throwError("value out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
|
||||
length: this.wordSize,
|
||||
offset: bytes.length
|
||||
});
|
||||
}
|
||||
if (bytes.length % this.wordSize) {
|
||||
bytes = concat([this._padding.slice(bytes.length % this.wordSize), bytes]);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
// BigNumberish items; padded on the left to wordSize
|
||||
writeValue(value) {
|
||||
return this._writeData(this._getValue(value));
|
||||
}
|
||||
writeUpdatableValue() {
|
||||
let offset = this.length;
|
||||
this.writeValue(0);
|
||||
return (value) => {
|
||||
this._data.set(this._getValue(value), offset);
|
||||
};
|
||||
}
|
||||
}
|
||||
export class Reader {
|
||||
constructor(data, wordSize, coerceFunc) {
|
||||
defineReadOnly(this, "_data", arrayify(data));
|
||||
defineReadOnly(this, "wordSize", wordSize || 32);
|
||||
defineReadOnly(this, "_coerceFunc", coerceFunc);
|
||||
this._offset = 0;
|
||||
}
|
||||
get data() { return hexlify(this._data); }
|
||||
get consumed() { return this._offset; }
|
||||
// The default Coerce function
|
||||
static coerce(name, value) {
|
||||
let match = name.match("^u?int([0-9]+)$");
|
||||
if (match && parseInt(match[1]) <= 48) {
|
||||
value = value.toNumber();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
coerce(name, value) {
|
||||
if (this._coerceFunc) {
|
||||
return this._coerceFunc(name, value);
|
||||
}
|
||||
return Reader.coerce(name, value);
|
||||
}
|
||||
_peekBytes(offset, length) {
|
||||
let alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
|
||||
if (this._offset + alignedLength > this._data.length) {
|
||||
logger.throwError("data out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
|
||||
length: this._data.length,
|
||||
offset: this._offset + alignedLength
|
||||
});
|
||||
}
|
||||
return this._data.slice(this._offset, this._offset + alignedLength);
|
||||
}
|
||||
subReader(offset) {
|
||||
return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc);
|
||||
}
|
||||
readBytes(length) {
|
||||
let bytes = this._peekBytes(0, length);
|
||||
this._offset += bytes.length;
|
||||
// @TODO: Make sure the length..end bytes are all 0?
|
||||
return bytes.slice(0, length);
|
||||
}
|
||||
readValue() {
|
||||
return BigNumber.from(this.readBytes(this.wordSize));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
import { getAddress } from "@ethersproject/address";
|
||||
import { hexZeroPad } from "@ethersproject/bytes";
|
||||
import { Coder } from "./abstract-coder";
|
||||
export class AddressCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("address", "address", localName, false);
|
||||
}
|
||||
encode(writer, value) {
|
||||
try {
|
||||
getAddress(value);
|
||||
}
|
||||
catch (error) {
|
||||
this._throwError(error.message, value);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
}
|
||||
decode(reader) {
|
||||
return getAddress(hexZeroPad(reader.readValue().toHexString(), 20));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
import { Coder } from "./abstract-coder";
|
||||
// Clones the functionality of an existing Coder, but without a localName
|
||||
export class AnonymousCoder extends Coder {
|
||||
constructor(coder) {
|
||||
super(coder.name, coder.type, undefined, coder.dynamic);
|
||||
this.coder = coder;
|
||||
}
|
||||
encode(writer, value) {
|
||||
return this.coder.encode(writer, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return this.coder.decode(reader);
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "../_version";
|
||||
const logger = new Logger(version);
|
||||
import { Coder, Writer } from "./abstract-coder";
|
||||
import { AnonymousCoder } from "./anonymous";
|
||||
export function pack(writer, coders, values) {
|
||||
if (Array.isArray(values)) {
|
||||
// do nothing
|
||||
}
|
||||
else if (values && typeof (values) === "object") {
|
||||
let arrayValues = [];
|
||||
coders.forEach(function (coder) {
|
||||
arrayValues.push(values[coder.localName]);
|
||||
});
|
||||
values = arrayValues;
|
||||
}
|
||||
else {
|
||||
logger.throwArgumentError("invalid tuple value", "tuple", values);
|
||||
}
|
||||
if (coders.length !== values.length) {
|
||||
logger.throwArgumentError("types/value length mismatch", "tuple", values);
|
||||
}
|
||||
let staticWriter = new Writer(writer.wordSize);
|
||||
let dynamicWriter = new Writer(writer.wordSize);
|
||||
let updateFuncs = [];
|
||||
coders.forEach((coder, index) => {
|
||||
let value = values[index];
|
||||
if (coder.dynamic) {
|
||||
// Get current dynamic offset (for the future pointer)
|
||||
let dynamicOffset = dynamicWriter.length;
|
||||
// Encode the dynamic value into the dynamicWriter
|
||||
coder.encode(dynamicWriter, value);
|
||||
// Prepare to populate the correct offset once we are done
|
||||
let updateFunc = staticWriter.writeUpdatableValue();
|
||||
updateFuncs.push((baseOffset) => {
|
||||
updateFunc(baseOffset + dynamicOffset);
|
||||
});
|
||||
}
|
||||
else {
|
||||
coder.encode(staticWriter, value);
|
||||
}
|
||||
});
|
||||
// Backfill all the dynamic offsets, now that we know the static length
|
||||
updateFuncs.forEach((func) => { func(staticWriter.length); });
|
||||
let length = writer.writeBytes(staticWriter.data);
|
||||
length += writer.writeBytes(dynamicWriter.data);
|
||||
return length;
|
||||
}
|
||||
export function unpack(reader, coders) {
|
||||
let values = [];
|
||||
// A reader anchored to this base
|
||||
let baseReader = reader.subReader(0);
|
||||
// The amount of dynamic data read; to consume later to synchronize
|
||||
let dynamicLength = 0;
|
||||
coders.forEach((coder) => {
|
||||
let value = null;
|
||||
if (coder.dynamic) {
|
||||
let offset = reader.readValue();
|
||||
let offsetReader = baseReader.subReader(offset.toNumber());
|
||||
try {
|
||||
value = coder.decode(offsetReader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (error.code === Logger.errors.BUFFER_OVERRUN) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
dynamicLength += offsetReader.consumed;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = coder.decode(reader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (error.code === Logger.errors.BUFFER_OVERRUN) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
if (value != undefined) {
|
||||
values.push(value);
|
||||
}
|
||||
});
|
||||
// @TODO: get rid of this an see if it still works?
|
||||
// Consume the dynamic components in the main reader
|
||||
reader.readBytes(dynamicLength);
|
||||
// Add any named parameters (i.e. tuples)
|
||||
coders.forEach((coder, index) => {
|
||||
let name = coder.localName;
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
if (name === "length") {
|
||||
name = "_length";
|
||||
}
|
||||
if (values[name] != null) {
|
||||
return;
|
||||
}
|
||||
const value = values[index];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(values, name, {
|
||||
get: () => { throw value; }
|
||||
});
|
||||
}
|
||||
else {
|
||||
values[name] = value;
|
||||
}
|
||||
});
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
const value = values[i];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(values, i, {
|
||||
get: () => { throw value; }
|
||||
});
|
||||
}
|
||||
}
|
||||
return Object.freeze(values);
|
||||
}
|
||||
export class ArrayCoder extends Coder {
|
||||
constructor(coder, length, localName) {
|
||||
const type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
||||
const dynamic = (length === -1 || coder.dynamic);
|
||||
super("array", type, localName, dynamic);
|
||||
this.coder = coder;
|
||||
this.length = length;
|
||||
}
|
||||
encode(writer, value) {
|
||||
if (!Array.isArray(value)) {
|
||||
this._throwError("expected array value", value);
|
||||
}
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = value.length;
|
||||
writer.writeValue(value.length);
|
||||
}
|
||||
logger.checkArgumentCount(count, value.length, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
||||
let coders = [];
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
}
|
||||
return pack(writer, coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = reader.readValue().toNumber();
|
||||
}
|
||||
let coders = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
coders.push(new AnonymousCoder(this.coder));
|
||||
}
|
||||
return reader.coerce(this.name, unpack(reader, coders));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
import { Coder } from "./abstract-coder";
|
||||
export class BooleanCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("bool", "bool", localName, false);
|
||||
}
|
||||
encode(writer, value) {
|
||||
return writer.writeValue(value ? 1 : 0);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.type, !reader.readValue().isZero());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
import { arrayify, hexlify } from "@ethersproject/bytes";
|
||||
import { Coder } from "./abstract-coder";
|
||||
export class DynamicBytesCoder extends Coder {
|
||||
constructor(type, localName) {
|
||||
super(type, type, localName, true);
|
||||
}
|
||||
encode(writer, value) {
|
||||
value = arrayify(value);
|
||||
let length = writer.writeValue(value.length);
|
||||
length += writer.writeBytes(value);
|
||||
return length;
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.readBytes(reader.readValue().toNumber());
|
||||
}
|
||||
}
|
||||
export class BytesCoder extends DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("bytes", localName);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, hexlify(super.decode(reader)));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
import { arrayify, hexlify } from "@ethersproject/bytes";
|
||||
import { Coder } from "./abstract-coder";
|
||||
// @TODO: Merge this with bytes
|
||||
export class FixedBytesCoder extends Coder {
|
||||
constructor(size, localName) {
|
||||
let name = "bytes" + String(size);
|
||||
super(name, name, localName, false);
|
||||
this.size = size;
|
||||
}
|
||||
encode(writer, value) {
|
||||
let data = arrayify(value);
|
||||
if (data.length !== this.size) {
|
||||
this._throwError("incorrect data length", value);
|
||||
}
|
||||
return writer.writeBytes(data);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, hexlify(reader.readBytes(this.size)));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
import { Coder } from "./abstract-coder";
|
||||
export class NullCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("null", "", localName, false);
|
||||
}
|
||||
encode(writer, value) {
|
||||
if (value != null) {
|
||||
this._throwError("not null", value);
|
||||
}
|
||||
return writer.writeBytes([]);
|
||||
}
|
||||
decode(reader) {
|
||||
reader.readBytes(0);
|
||||
return reader.coerce(this.name, null);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { MaxUint256, NegativeOne, One, Zero } from "@ethersproject/constants";
|
||||
import { Coder } from "./abstract-coder";
|
||||
export class NumberCoder extends Coder {
|
||||
constructor(size, signed, localName) {
|
||||
const name = ((signed ? "int" : "uint") + (size * 8));
|
||||
super(name, name, localName, false);
|
||||
this.size = size;
|
||||
this.signed = signed;
|
||||
}
|
||||
encode(writer, value) {
|
||||
let v = BigNumber.from(value);
|
||||
// Check bounds are safe for encoding
|
||||
let maxUintValue = MaxUint256.mask(writer.wordSize * 8);
|
||||
if (this.signed) {
|
||||
let bounds = maxUintValue.mask(this.size * 8 - 1);
|
||||
if (v.gt(bounds) || v.lt(bounds.add(One).mul(NegativeOne))) {
|
||||
this._throwError("value out-of-bounds", value);
|
||||
}
|
||||
}
|
||||
else if (v.lt(Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
|
||||
this._throwError("value out-of-bounds", value);
|
||||
}
|
||||
v = v.toTwos(this.size * 8).mask(this.size * 8);
|
||||
if (this.signed) {
|
||||
v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
|
||||
}
|
||||
return writer.writeValue(v);
|
||||
}
|
||||
decode(reader) {
|
||||
let value = reader.readValue().mask(this.size * 8);
|
||||
if (this.signed) {
|
||||
value = value.fromTwos(this.size * 8);
|
||||
}
|
||||
return reader.coerce(this.name, value);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
||||
import { DynamicBytesCoder } from "./bytes";
|
||||
export class StringCoder extends DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("string", localName);
|
||||
}
|
||||
encode(writer, value) {
|
||||
return super.encode(writer, toUtf8Bytes(value));
|
||||
}
|
||||
decode(reader) {
|
||||
return toUtf8String(super.decode(reader));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
import { Coder } from "./abstract-coder";
|
||||
import { pack, unpack } from "./array";
|
||||
export class TupleCoder extends Coder {
|
||||
constructor(coders, localName) {
|
||||
let dynamic = false;
|
||||
const types = [];
|
||||
coders.forEach((coder) => {
|
||||
if (coder.dynamic) {
|
||||
dynamic = true;
|
||||
}
|
||||
types.push(coder.type);
|
||||
});
|
||||
const type = ("tuple(" + types.join(",") + ")");
|
||||
super("tuple", type, localName, dynamic);
|
||||
this.coders = coders;
|
||||
}
|
||||
encode(writer, value) {
|
||||
return pack(writer, this.coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, unpack(reader, this.coders));
|
||||
}
|
||||
}
|
||||
+780
@@ -0,0 +1,780 @@
|
||||
"use strict";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
;
|
||||
const _constructorGuard = {};
|
||||
let ModifiersBytes = { calldata: true, memory: true, storage: true };
|
||||
let ModifiersNest = { calldata: true, memory: true };
|
||||
function checkModifier(type, name) {
|
||||
if (type === "bytes" || type === "string") {
|
||||
if (ModifiersBytes[name]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type === "address") {
|
||||
if (name === "payable") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type.indexOf("[") >= 0 || type === "tuple") {
|
||||
if (ModifiersNest[name]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ModifiersBytes[name] || name === "payable") {
|
||||
logger.throwArgumentError("invalid modifier", "name", name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// @TODO: Make sure that children of an indexed tuple are marked with a null indexed
|
||||
function parseParamType(param, allowIndexed) {
|
||||
let originalParam = param;
|
||||
function throwError(i) {
|
||||
logger.throwArgumentError(`unexpected character at position ${i}`, "param", param);
|
||||
}
|
||||
param = param.replace(/\s/g, " ");
|
||||
function newNode(parent) {
|
||||
let node = { type: "", name: "", parent: parent, state: { allowType: true } };
|
||||
if (allowIndexed) {
|
||||
node.indexed = false;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
let parent = { type: "", name: "", state: { allowType: true } };
|
||||
let node = parent;
|
||||
for (let i = 0; i < param.length; i++) {
|
||||
let c = param[i];
|
||||
switch (c) {
|
||||
case "(":
|
||||
if (node.state.allowType && node.type === "") {
|
||||
node.type = "tuple";
|
||||
}
|
||||
else if (!node.state.allowParams) {
|
||||
throwError(i);
|
||||
}
|
||||
node.state.allowType = false;
|
||||
node.type = verifyType(node.type);
|
||||
node.components = [newNode(node)];
|
||||
node = node.components[0];
|
||||
break;
|
||||
case ")":
|
||||
delete node.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
node.type = verifyType(node.type);
|
||||
let child = node;
|
||||
node = node.parent;
|
||||
if (!node) {
|
||||
throwError(i);
|
||||
}
|
||||
delete child.parent;
|
||||
node.state.allowParams = false;
|
||||
node.state.allowName = true;
|
||||
node.state.allowArray = true;
|
||||
break;
|
||||
case ",":
|
||||
delete node.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
node.type = verifyType(node.type);
|
||||
let sibling = newNode(node.parent);
|
||||
//{ type: "", name: "", parent: node.parent, state: { allowType: true } };
|
||||
node.parent.components.push(sibling);
|
||||
delete node.parent;
|
||||
node = sibling;
|
||||
break;
|
||||
// Hit a space...
|
||||
case " ":
|
||||
// If reading type, the type is done and may read a param or name
|
||||
if (node.state.allowType) {
|
||||
if (node.type !== "") {
|
||||
node.type = verifyType(node.type);
|
||||
delete node.state.allowType;
|
||||
node.state.allowName = true;
|
||||
node.state.allowParams = true;
|
||||
}
|
||||
}
|
||||
// If reading name, the name is done
|
||||
if (node.state.allowName) {
|
||||
if (node.name !== "") {
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
if (node.indexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
else if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
else {
|
||||
node.state.allowName = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "[":
|
||||
if (!node.state.allowArray) {
|
||||
throwError(i);
|
||||
}
|
||||
node.type += c;
|
||||
node.state.allowArray = false;
|
||||
node.state.allowName = false;
|
||||
node.state.readArray = true;
|
||||
break;
|
||||
case "]":
|
||||
if (!node.state.readArray) {
|
||||
throwError(i);
|
||||
}
|
||||
node.type += c;
|
||||
node.state.readArray = false;
|
||||
node.state.allowArray = true;
|
||||
node.state.allowName = true;
|
||||
break;
|
||||
default:
|
||||
if (node.state.allowType) {
|
||||
node.type += c;
|
||||
node.state.allowParams = true;
|
||||
node.state.allowArray = true;
|
||||
}
|
||||
else if (node.state.allowName) {
|
||||
node.name += c;
|
||||
delete node.state.allowArray;
|
||||
}
|
||||
else if (node.state.readArray) {
|
||||
node.type += c;
|
||||
}
|
||||
else {
|
||||
throwError(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.parent) {
|
||||
logger.throwArgumentError("unexpected eof", "param", param);
|
||||
}
|
||||
delete parent.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(originalParam.length - 7);
|
||||
}
|
||||
if (node.indexed) {
|
||||
throwError(originalParam.length - 7);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
else if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
parent.type = verifyType(parent.type);
|
||||
return parent;
|
||||
}
|
||||
function populate(object, params) {
|
||||
for (let key in params) {
|
||||
defineReadOnly(object, key, params[key]);
|
||||
}
|
||||
}
|
||||
export const FormatTypes = Object.freeze({
|
||||
// Bare formatting, as is needed for computing a sighash of an event or function
|
||||
sighash: "sighash",
|
||||
// Human-Readable with Minimal spacing and without names (compact human-readable)
|
||||
minimal: "minimal",
|
||||
// Human-Readble with nice spacing, including all names
|
||||
full: "full",
|
||||
// JSON-format a la Solidity
|
||||
json: "json"
|
||||
});
|
||||
const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
|
||||
export class ParamType {
|
||||
constructor(constructorGuard, params) {
|
||||
if (constructorGuard !== _constructorGuard) {
|
||||
logger.throwError("use fromString", Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "new ParamType()"
|
||||
});
|
||||
}
|
||||
populate(this, params);
|
||||
let match = this.type.match(paramTypeArray);
|
||||
if (match) {
|
||||
populate(this, {
|
||||
arrayLength: parseInt(match[2] || "-1"),
|
||||
arrayChildren: ParamType.fromObject({
|
||||
type: match[1],
|
||||
components: this.components
|
||||
}),
|
||||
baseType: "array"
|
||||
});
|
||||
}
|
||||
else {
|
||||
populate(this, {
|
||||
arrayLength: null,
|
||||
arrayChildren: null,
|
||||
baseType: ((this.components != null) ? "tuple" : this.type)
|
||||
});
|
||||
}
|
||||
this._isParamType = true;
|
||||
Object.freeze(this);
|
||||
}
|
||||
// Format the parameter fragment
|
||||
// - sighash: "(uint256,address)"
|
||||
// - minimal: "tuple(uint256,address) indexed"
|
||||
// - full: "tuple(uint256 foo, addres bar) indexed baz"
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatTypes.sighash;
|
||||
}
|
||||
if (!FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatTypes.json) {
|
||||
let result = {
|
||||
type: ((this.baseType === "tuple") ? "tuple" : this.type),
|
||||
name: (this.name || undefined)
|
||||
};
|
||||
if (typeof (this.indexed) === "boolean") {
|
||||
result.indexed = this.indexed;
|
||||
}
|
||||
if (this.components) {
|
||||
result.components = this.components.map((comp) => JSON.parse(comp.format(format)));
|
||||
}
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
let result = "";
|
||||
// Array
|
||||
if (this.baseType === "array") {
|
||||
result += this.arrayChildren.format(format);
|
||||
result += "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
|
||||
}
|
||||
else {
|
||||
if (this.baseType === "tuple") {
|
||||
if (format !== FormatTypes.sighash) {
|
||||
result += this.type;
|
||||
}
|
||||
result += "(" + this.components.map((comp) => comp.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ")";
|
||||
}
|
||||
else {
|
||||
result += this.type;
|
||||
}
|
||||
}
|
||||
if (format !== FormatTypes.sighash) {
|
||||
if (this.indexed === true) {
|
||||
result += " indexed";
|
||||
}
|
||||
if (format === FormatTypes.full && this.name) {
|
||||
result += " " + this.name;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static from(value, allowIndexed) {
|
||||
if (typeof (value) === "string") {
|
||||
return ParamType.fromString(value, allowIndexed);
|
||||
}
|
||||
return ParamType.fromObject(value);
|
||||
}
|
||||
static fromObject(value) {
|
||||
if (ParamType.isParamType(value)) {
|
||||
return value;
|
||||
}
|
||||
return new ParamType(_constructorGuard, {
|
||||
name: (value.name || null),
|
||||
type: verifyType(value.type),
|
||||
indexed: ((value.indexed == null) ? null : !!value.indexed),
|
||||
components: (value.components ? value.components.map(ParamType.fromObject) : null)
|
||||
});
|
||||
}
|
||||
static fromString(value, allowIndexed) {
|
||||
function ParamTypify(node) {
|
||||
return ParamType.fromObject({
|
||||
name: node.name,
|
||||
type: node.type,
|
||||
indexed: node.indexed,
|
||||
components: node.components
|
||||
});
|
||||
}
|
||||
return ParamTypify(parseParamType(value, !!allowIndexed));
|
||||
}
|
||||
static isParamType(value) {
|
||||
return !!(value != null && value._isParamType);
|
||||
}
|
||||
}
|
||||
;
|
||||
function parseParams(value, allowIndex) {
|
||||
return splitNesting(value).map((param) => ParamType.fromString(param, allowIndex));
|
||||
}
|
||||
export class Fragment {
|
||||
constructor(constructorGuard, params) {
|
||||
if (constructorGuard !== _constructorGuard) {
|
||||
logger.throwError("use a static from method", Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "new Fragment()"
|
||||
});
|
||||
}
|
||||
populate(this, params);
|
||||
this._isFragment = true;
|
||||
Object.freeze(this);
|
||||
}
|
||||
static from(value) {
|
||||
if (Fragment.isFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof (value) === "string") {
|
||||
return Fragment.fromString(value);
|
||||
}
|
||||
return Fragment.fromObject(value);
|
||||
}
|
||||
static fromObject(value) {
|
||||
if (Fragment.isFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
switch (value.type) {
|
||||
case "function":
|
||||
return FunctionFragment.fromObject(value);
|
||||
case "event":
|
||||
return EventFragment.fromObject(value);
|
||||
case "constructor":
|
||||
return ConstructorFragment.fromObject(value);
|
||||
case "fallback":
|
||||
case "receive":
|
||||
// @TODO: Something? Maybe return a FunctionFragment? A custom DefaultFunctionFragment?
|
||||
return null;
|
||||
}
|
||||
return logger.throwArgumentError("invalid fragment object", "value", value);
|
||||
}
|
||||
static fromString(value) {
|
||||
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
||||
value = value.replace(/\s/g, " ");
|
||||
value = value.replace(/\(/g, " (").replace(/\)/g, ") ").replace(/\s+/g, " ");
|
||||
value = value.trim();
|
||||
if (value.split(" ")[0] === "event") {
|
||||
return EventFragment.fromString(value.substring(5).trim());
|
||||
}
|
||||
else if (value.split(" ")[0] === "function") {
|
||||
return FunctionFragment.fromString(value.substring(8).trim());
|
||||
}
|
||||
else if (value.split("(")[0].trim() === "constructor") {
|
||||
return ConstructorFragment.fromString(value.trim());
|
||||
}
|
||||
return logger.throwArgumentError("unsupported fragment", "value", value);
|
||||
}
|
||||
static isFragment(value) {
|
||||
return !!(value && value._isFragment);
|
||||
}
|
||||
}
|
||||
export class EventFragment extends Fragment {
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatTypes.sighash;
|
||||
}
|
||||
if (!FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "event",
|
||||
anonymous: this.anonymous,
|
||||
name: this.name,
|
||||
inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
|
||||
});
|
||||
}
|
||||
let result = "";
|
||||
if (format !== FormatTypes.sighash) {
|
||||
result += "event ";
|
||||
}
|
||||
result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (format !== FormatTypes.sighash) {
|
||||
if (this.anonymous) {
|
||||
result += "anonymous ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
static from(value) {
|
||||
if (typeof (value) === "string") {
|
||||
return EventFragment.fromString(value);
|
||||
}
|
||||
return EventFragment.fromObject(value);
|
||||
}
|
||||
static fromObject(value) {
|
||||
if (EventFragment.isEventFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "event") {
|
||||
logger.throwArgumentError("invalid event object", "value", value);
|
||||
}
|
||||
const params = {
|
||||
name: verifyIdentifier(value.name),
|
||||
anonymous: value.anonymous,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
type: "event"
|
||||
};
|
||||
return new EventFragment(_constructorGuard, params);
|
||||
}
|
||||
static fromString(value) {
|
||||
let match = value.match(regexParen);
|
||||
if (!match) {
|
||||
logger.throwArgumentError("invalid event string", "value", value);
|
||||
}
|
||||
let anonymous = false;
|
||||
match[3].split(" ").forEach((modifier) => {
|
||||
switch (modifier.trim()) {
|
||||
case "anonymous":
|
||||
anonymous = true;
|
||||
break;
|
||||
case "":
|
||||
break;
|
||||
default:
|
||||
logger.warn("unknown modifier: " + modifier);
|
||||
}
|
||||
});
|
||||
return EventFragment.fromObject({
|
||||
name: match[1].trim(),
|
||||
anonymous: anonymous,
|
||||
inputs: parseParams(match[2], true),
|
||||
type: "event"
|
||||
});
|
||||
}
|
||||
static isEventFragment(value) {
|
||||
return (value && value._isFragment && value.type === "event");
|
||||
}
|
||||
}
|
||||
function parseGas(value, params) {
|
||||
params.gas = null;
|
||||
let comps = value.split("@");
|
||||
if (comps.length !== 1) {
|
||||
if (comps.length > 2) {
|
||||
logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
|
||||
}
|
||||
if (!comps[1].match(/^[0-9]+$/)) {
|
||||
logger.throwArgumentError("invalid human-readable ABI signature gas", "value", value);
|
||||
}
|
||||
params.gas = BigNumber.from(comps[1]);
|
||||
return comps[0];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function parseModifiers(value, params) {
|
||||
params.constant = false;
|
||||
params.payable = false;
|
||||
params.stateMutability = "nonpayable";
|
||||
value.split(" ").forEach((modifier) => {
|
||||
switch (modifier.trim()) {
|
||||
case "constant":
|
||||
params.constant = true;
|
||||
break;
|
||||
case "payable":
|
||||
params.payable = true;
|
||||
params.stateMutability = "payable";
|
||||
break;
|
||||
case "pure":
|
||||
params.constant = true;
|
||||
params.stateMutability = "pure";
|
||||
break;
|
||||
case "view":
|
||||
params.constant = true;
|
||||
params.stateMutability = "view";
|
||||
break;
|
||||
case "external":
|
||||
case "public":
|
||||
case "":
|
||||
break;
|
||||
default:
|
||||
console.log("unknown modifier: " + modifier);
|
||||
}
|
||||
});
|
||||
}
|
||||
function verifyState(value) {
|
||||
let result = {
|
||||
constant: false,
|
||||
payable: true,
|
||||
stateMutability: "payable"
|
||||
};
|
||||
if (value.stateMutability != null) {
|
||||
result.stateMutability = value.stateMutability;
|
||||
// Set (and check things are consistent) the constant property
|
||||
result.constant = (result.stateMutability === "view" || result.stateMutability === "pure");
|
||||
if (value.constant != null) {
|
||||
if ((!!value.constant) !== result.constant) {
|
||||
logger.throwArgumentError("cannot have constant function with mutability " + result.stateMutability, "value", value);
|
||||
}
|
||||
}
|
||||
// Set (and check things are consistent) the payable property
|
||||
result.payable = (result.stateMutability === "payable");
|
||||
if (value.payable != null) {
|
||||
if ((!!value.payable) !== result.payable) {
|
||||
logger.throwArgumentError("cannot have payable function with mutability " + result.stateMutability, "value", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value.payable != null) {
|
||||
result.payable = !!value.payable;
|
||||
// If payable we can assume non-constant; otherwise we can't assume
|
||||
if (value.constant == null && !result.payable && value.type !== "constructor") {
|
||||
logger.throwArgumentError("unable to determine stateMutability", "value", value);
|
||||
}
|
||||
result.constant = !!value.constant;
|
||||
if (result.constant) {
|
||||
result.stateMutability = "view";
|
||||
}
|
||||
else {
|
||||
result.stateMutability = (result.payable ? "payable" : "nonpayable");
|
||||
}
|
||||
if (result.payable && result.constant) {
|
||||
logger.throwArgumentError("cannot have constant payable function", "value", value);
|
||||
}
|
||||
}
|
||||
else if (value.constant != null) {
|
||||
result.constant = !!value.constant;
|
||||
result.payable = !result.constant;
|
||||
result.stateMutability = (result.constant ? "view" : "payable");
|
||||
}
|
||||
else if (value.type !== "constructor") {
|
||||
logger.throwArgumentError("unable to determine stateMutability", "value", value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export class ConstructorFragment extends Fragment {
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatTypes.sighash;
|
||||
}
|
||||
if (!FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "constructor",
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payble: this.payable,
|
||||
gas: (this.gas ? this.gas.toNumber() : undefined),
|
||||
inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
|
||||
});
|
||||
}
|
||||
if (format === FormatTypes.sighash) {
|
||||
logger.throwError("cannot format a constructor for sighash", Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "format(sighash)"
|
||||
});
|
||||
}
|
||||
let result = "constructor(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (this.stateMutability && this.stateMutability !== "nonpayable") {
|
||||
result += this.stateMutability + " ";
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
static from(value) {
|
||||
if (typeof (value) === "string") {
|
||||
return ConstructorFragment.fromString(value);
|
||||
}
|
||||
return ConstructorFragment.fromObject(value);
|
||||
}
|
||||
static fromObject(value) {
|
||||
if (ConstructorFragment.isConstructorFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "constructor") {
|
||||
logger.throwArgumentError("invalid constructor object", "value", value);
|
||||
}
|
||||
let state = verifyState(value);
|
||||
if (state.constant) {
|
||||
logger.throwArgumentError("constructor cannot be constant", "value", value);
|
||||
}
|
||||
const params = {
|
||||
name: null,
|
||||
type: value.type,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
payable: state.payable,
|
||||
stateMutability: state.stateMutability,
|
||||
gas: (value.gas ? BigNumber.from(value.gas) : null)
|
||||
};
|
||||
return new ConstructorFragment(_constructorGuard, params);
|
||||
}
|
||||
static fromString(value) {
|
||||
let params = { type: "constructor" };
|
||||
value = parseGas(value, params);
|
||||
let parens = value.match(regexParen);
|
||||
if (!parens || parens[1].trim() !== "constructor") {
|
||||
logger.throwArgumentError("invalid constructor string", "value", value);
|
||||
}
|
||||
params.inputs = parseParams(parens[2].trim(), false);
|
||||
parseModifiers(parens[3].trim(), params);
|
||||
return ConstructorFragment.fromObject(params);
|
||||
}
|
||||
static isConstructorFragment(value) {
|
||||
return (value && value._isFragment && value.type === "constructor");
|
||||
}
|
||||
}
|
||||
export class FunctionFragment extends ConstructorFragment {
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatTypes.sighash;
|
||||
}
|
||||
if (!FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "function",
|
||||
name: this.name,
|
||||
constant: this.constant,
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payble: this.payable,
|
||||
gas: (this.gas ? this.gas.toNumber() : undefined),
|
||||
inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
|
||||
ouputs: this.outputs.map((output) => JSON.parse(output.format(format))),
|
||||
});
|
||||
}
|
||||
let result = "";
|
||||
if (format !== FormatTypes.sighash) {
|
||||
result += "function ";
|
||||
}
|
||||
result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (format !== FormatTypes.sighash) {
|
||||
if (this.stateMutability) {
|
||||
if (this.stateMutability !== "nonpayable") {
|
||||
result += (this.stateMutability + " ");
|
||||
}
|
||||
}
|
||||
else if (this.constant) {
|
||||
result += "view ";
|
||||
}
|
||||
if (this.outputs && this.outputs.length) {
|
||||
result += "returns (" + this.outputs.map((output) => output.format(format)).join(", ") + ") ";
|
||||
}
|
||||
if (this.gas != null) {
|
||||
result += "@" + this.gas.toString() + " ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
static from(value) {
|
||||
if (typeof (value) === "string") {
|
||||
return FunctionFragment.fromString(value);
|
||||
}
|
||||
return FunctionFragment.fromObject(value);
|
||||
}
|
||||
static fromObject(value) {
|
||||
if (FunctionFragment.isFunctionFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "function") {
|
||||
logger.throwArgumentError("invalid function object", "value", value);
|
||||
}
|
||||
let state = verifyState(value);
|
||||
const params = {
|
||||
type: value.type,
|
||||
name: verifyIdentifier(value.name),
|
||||
constant: state.constant,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
outputs: (value.outputs ? value.outputs.map(ParamType.fromObject) : []),
|
||||
payable: state.payable,
|
||||
stateMutability: state.stateMutability,
|
||||
gas: (value.gas ? BigNumber.from(value.gas) : null)
|
||||
};
|
||||
return new FunctionFragment(_constructorGuard, params);
|
||||
}
|
||||
static fromString(value) {
|
||||
let params = { type: "function" };
|
||||
value = parseGas(value, params);
|
||||
let comps = value.split(" returns ");
|
||||
if (comps.length > 2) {
|
||||
logger.throwArgumentError("invalid function string", "value", value);
|
||||
}
|
||||
let parens = comps[0].match(regexParen);
|
||||
if (!parens) {
|
||||
logger.throwArgumentError("invalid function signature", "value", value);
|
||||
}
|
||||
params.name = parens[1].trim();
|
||||
if (params.name) {
|
||||
verifyIdentifier(params.name);
|
||||
}
|
||||
params.inputs = parseParams(parens[2], false);
|
||||
parseModifiers(parens[3].trim(), params);
|
||||
// We have outputs
|
||||
if (comps.length > 1) {
|
||||
let returns = comps[1].match(regexParen);
|
||||
if (returns[1].trim() != "" || returns[3].trim() != "") {
|
||||
logger.throwArgumentError("unexpected tokens", "value", value);
|
||||
}
|
||||
params.outputs = parseParams(returns[2], false);
|
||||
}
|
||||
else {
|
||||
params.outputs = [];
|
||||
}
|
||||
return FunctionFragment.fromObject(params);
|
||||
}
|
||||
static isFunctionFragment(value) {
|
||||
return (value && value._isFragment && value.type === "function");
|
||||
}
|
||||
}
|
||||
//export class ErrorFragment extends Fragment {
|
||||
//}
|
||||
//export class StructFragment extends Fragment {
|
||||
//}
|
||||
function verifyType(type) {
|
||||
// These need to be transformed to their full description
|
||||
if (type.match(/^uint($|[^1-9])/)) {
|
||||
type = "uint256" + type.substring(4);
|
||||
}
|
||||
else if (type.match(/^int($|[^1-9])/)) {
|
||||
type = "int256" + type.substring(3);
|
||||
}
|
||||
// @TODO: more verification
|
||||
return type;
|
||||
}
|
||||
const regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
|
||||
function verifyIdentifier(value) {
|
||||
if (!value || !value.match(regexIdentifier)) {
|
||||
logger.throwArgumentError(`invalid identifier "${value}"`, "value", value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
|
||||
function splitNesting(value) {
|
||||
value = value.trim();
|
||||
let result = [];
|
||||
let accum = "";
|
||||
let depth = 0;
|
||||
for (let offset = 0; offset < value.length; offset++) {
|
||||
let c = value[offset];
|
||||
if (c === "," && depth === 0) {
|
||||
result.push(accum);
|
||||
accum = "";
|
||||
}
|
||||
else {
|
||||
accum += c;
|
||||
if (c === "(") {
|
||||
depth++;
|
||||
}
|
||||
else if (c === ")") {
|
||||
depth--;
|
||||
if (depth === -1) {
|
||||
logger.throwArgumentError("unbalanced parenthesis", "value", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accum) {
|
||||
result.push(accum);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
import { ConstructorFragment, EventFragment, FormatTypes, Fragment, FunctionFragment, ParamType } from "./fragments";
|
||||
import { AbiCoder, defaultAbiCoder } from "./abi-coder";
|
||||
import { checkResultErrors, Indexed, Interface, LogDescription, TransactionDescription } from "./interface";
|
||||
export { ConstructorFragment, EventFragment, Fragment, FunctionFragment, ParamType, FormatTypes, AbiCoder, defaultAbiCoder, Interface, Indexed, checkResultErrors, LogDescription, TransactionDescription };
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
"use strict";
|
||||
import { getAddress } from "@ethersproject/address";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { arrayify, concat, hexDataSlice, hexlify, hexZeroPad, isHexString } from "@ethersproject/bytes";
|
||||
import { id } from "@ethersproject/hash";
|
||||
import { keccak256 } from "@ethersproject/keccak256";
|
||||
import { defineReadOnly, Description, getStatic } from "@ethersproject/properties";
|
||||
import { defaultAbiCoder } from "./abi-coder";
|
||||
import { checkResultErrors } from "./coders/abstract-coder";
|
||||
import { ConstructorFragment, EventFragment, FormatTypes, Fragment, FunctionFragment, ParamType } from "./fragments";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
export { checkResultErrors };
|
||||
export class LogDescription extends Description {
|
||||
}
|
||||
export class TransactionDescription extends Description {
|
||||
}
|
||||
export class Indexed extends Description {
|
||||
static isIndexed(value) {
|
||||
return !!(value && value._isIndexed);
|
||||
}
|
||||
}
|
||||
function wrapAccessError(property, error) {
|
||||
const wrap = new Error(`deferred error during ABI decoding triggered accessing ${property}`);
|
||||
wrap.error = error;
|
||||
return wrap;
|
||||
}
|
||||
function checkNames(fragment, type, params) {
|
||||
params.reduce((accum, param) => {
|
||||
if (param.name) {
|
||||
if (accum[param.name]) {
|
||||
logger.throwArgumentError(`duplicate ${type} parameter ${JSON.stringify(param.name)} in ${fragment.format("full")}`, "fragment", fragment);
|
||||
}
|
||||
accum[param.name] = true;
|
||||
}
|
||||
return accum;
|
||||
}, {});
|
||||
}
|
||||
export class Interface {
|
||||
constructor(fragments) {
|
||||
logger.checkNew(new.target, Interface);
|
||||
let abi = [];
|
||||
if (typeof (fragments) === "string") {
|
||||
abi = JSON.parse(fragments);
|
||||
}
|
||||
else {
|
||||
abi = fragments;
|
||||
}
|
||||
defineReadOnly(this, "fragments", abi.map((fragment) => {
|
||||
return Fragment.from(fragment);
|
||||
}).filter((fragment) => (fragment != null)));
|
||||
defineReadOnly(this, "_abiCoder", getStatic((new.target), "getAbiCoder")());
|
||||
defineReadOnly(this, "functions", {});
|
||||
defineReadOnly(this, "errors", {});
|
||||
defineReadOnly(this, "events", {});
|
||||
defineReadOnly(this, "structs", {});
|
||||
// Add all fragments by their signature
|
||||
this.fragments.forEach((fragment) => {
|
||||
let bucket = null;
|
||||
switch (fragment.type) {
|
||||
case "constructor":
|
||||
if (this.deploy) {
|
||||
logger.warn("duplicate definition - constructor");
|
||||
return;
|
||||
}
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
defineReadOnly(this, "deploy", fragment);
|
||||
return;
|
||||
case "function":
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
checkNames(fragment, "output", fragment.outputs);
|
||||
bucket = this.functions;
|
||||
break;
|
||||
case "event":
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
bucket = this.events;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
let signature = fragment.format();
|
||||
if (bucket[signature]) {
|
||||
logger.warn("duplicate definition - " + signature);
|
||||
return;
|
||||
}
|
||||
bucket[signature] = fragment;
|
||||
});
|
||||
// If we do not have a constructor add a default
|
||||
if (!this.deploy) {
|
||||
defineReadOnly(this, "deploy", ConstructorFragment.from({
|
||||
payable: false,
|
||||
type: "constructor"
|
||||
}));
|
||||
}
|
||||
defineReadOnly(this, "_isInterface", true);
|
||||
}
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatTypes.full;
|
||||
}
|
||||
if (format === FormatTypes.sighash) {
|
||||
logger.throwArgumentError("interface does not support formatting sighash", "format", format);
|
||||
}
|
||||
const abi = this.fragments.map((fragment) => fragment.format(format));
|
||||
// We need to re-bundle the JSON fragments a bit
|
||||
if (format === FormatTypes.json) {
|
||||
return JSON.stringify(abi.map((j) => JSON.parse(j)));
|
||||
}
|
||||
return abi;
|
||||
}
|
||||
// Sub-classes can override these to handle other blockchains
|
||||
static getAbiCoder() {
|
||||
return defaultAbiCoder;
|
||||
}
|
||||
static getAddress(address) {
|
||||
return getAddress(address);
|
||||
}
|
||||
static getSighash(functionFragment) {
|
||||
return hexDataSlice(id(functionFragment.format()), 0, 4);
|
||||
}
|
||||
static getEventTopic(eventFragment) {
|
||||
return id(eventFragment.format());
|
||||
}
|
||||
// Find a function definition by any means necessary (unless it is ambiguous)
|
||||
getFunction(nameOrSignatureOrSighash) {
|
||||
if (isHexString(nameOrSignatureOrSighash)) {
|
||||
for (const name in this.functions) {
|
||||
if (nameOrSignatureOrSighash === this.getSighash(name)) {
|
||||
return this.functions[name];
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching function", "sighash", nameOrSignatureOrSighash);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (nameOrSignatureOrSighash.indexOf("(") === -1) {
|
||||
const name = nameOrSignatureOrSighash.trim();
|
||||
const matching = Object.keys(this.functions).filter((f) => (f.split("(" /* fix:) */)[0] === name));
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching function", "name", name);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
logger.throwArgumentError("multiple matching functions", "name", name);
|
||||
}
|
||||
return this.functions[matching[0]];
|
||||
}
|
||||
// Normlize the signature and lookup the function
|
||||
const result = this.functions[FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
|
||||
if (!result) {
|
||||
logger.throwArgumentError("no matching function", "signature", nameOrSignatureOrSighash);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Find an event definition by any means necessary (unless it is ambiguous)
|
||||
getEvent(nameOrSignatureOrTopic) {
|
||||
if (isHexString(nameOrSignatureOrTopic)) {
|
||||
const topichash = nameOrSignatureOrTopic.toLowerCase();
|
||||
for (const name in this.events) {
|
||||
if (topichash === this.getEventTopic(name)) {
|
||||
return this.events[name];
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching event", "topichash", topichash);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (nameOrSignatureOrTopic.indexOf("(") === -1) {
|
||||
const name = nameOrSignatureOrTopic.trim();
|
||||
const matching = Object.keys(this.events).filter((f) => (f.split("(" /* fix:) */)[0] === name));
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching event", "name", name);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
logger.throwArgumentError("multiple matching events", "name", name);
|
||||
}
|
||||
return this.events[matching[0]];
|
||||
}
|
||||
// Normlize the signature and lookup the function
|
||||
const result = this.events[EventFragment.fromString(nameOrSignatureOrTopic).format()];
|
||||
if (!result) {
|
||||
logger.throwArgumentError("no matching event", "signature", nameOrSignatureOrTopic);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Get the sighash (the bytes4 selector) used by Solidity to identify a function
|
||||
getSighash(functionFragment) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return getStatic(this.constructor, "getSighash")(functionFragment);
|
||||
}
|
||||
// Get the topic (the bytes32 hash) used by Solidity to identify an event
|
||||
getEventTopic(eventFragment) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
return getStatic(this.constructor, "getEventTopic")(eventFragment);
|
||||
}
|
||||
_decodeParams(params, data) {
|
||||
return this._abiCoder.decode(params, data);
|
||||
}
|
||||
_encodeParams(params, values) {
|
||||
return this._abiCoder.encode(params, values);
|
||||
}
|
||||
encodeDeploy(values) {
|
||||
return this._encodeParams(this.deploy.inputs, values || []);
|
||||
}
|
||||
// Decode the data for a function call (e.g. tx.data)
|
||||
decodeFunctionData(functionFragment, data) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
const bytes = arrayify(data);
|
||||
if (hexlify(bytes.slice(0, 4)) !== this.getSighash(functionFragment)) {
|
||||
logger.throwArgumentError(`data signature does not match function ${functionFragment.name}.`, "data", hexlify(bytes));
|
||||
}
|
||||
return this._decodeParams(functionFragment.inputs, bytes.slice(4));
|
||||
}
|
||||
// Encode the data for a function call (e.g. tx.data)
|
||||
encodeFunctionData(functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return hexlify(concat([
|
||||
this.getSighash(functionFragment),
|
||||
this._encodeParams(functionFragment.inputs, values || [])
|
||||
]));
|
||||
}
|
||||
// Decode the result from a function call (e.g. from eth_call)
|
||||
decodeFunctionResult(functionFragment, data) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
let bytes = arrayify(data);
|
||||
let reason = null;
|
||||
let errorSignature = null;
|
||||
switch (bytes.length % this._abiCoder._getWordSize()) {
|
||||
case 0:
|
||||
try {
|
||||
return this._abiCoder.decode(functionFragment.outputs, bytes);
|
||||
}
|
||||
catch (error) { }
|
||||
break;
|
||||
case 4:
|
||||
if (hexlify(bytes.slice(0, 4)) === "0x08c379a0") {
|
||||
errorSignature = "Error(string)";
|
||||
reason = this._abiCoder.decode(["string"], bytes.slice(4))[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
return logger.throwError("call revert exception", Logger.errors.CALL_EXCEPTION, {
|
||||
method: functionFragment.format(),
|
||||
errorSignature: errorSignature,
|
||||
errorArgs: [reason],
|
||||
reason: reason
|
||||
});
|
||||
}
|
||||
// Encode the result for a function call (e.g. for eth_call)
|
||||
encodeFunctionResult(functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return hexlify(this._abiCoder.encode(functionFragment.outputs, values || []));
|
||||
}
|
||||
// Create the filter for the event with search criteria (e.g. for eth_filterLog)
|
||||
encodeFilterTopics(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (values.length > eventFragment.inputs.length) {
|
||||
logger.throwError("too many arguments for " + eventFragment.format(), Logger.errors.UNEXPECTED_ARGUMENT, {
|
||||
argument: "values",
|
||||
value: values
|
||||
});
|
||||
}
|
||||
let topics = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
const encodeTopic = (param, value) => {
|
||||
if (param.type === "string") {
|
||||
return id(value);
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
return keccak256(hexlify(value));
|
||||
}
|
||||
// Check addresses are valid
|
||||
if (param.type === "address") {
|
||||
this._abiCoder.encode(["address"], [value]);
|
||||
}
|
||||
return hexZeroPad(hexlify(value), 32);
|
||||
};
|
||||
values.forEach((value, index) => {
|
||||
let param = eventFragment.inputs[index];
|
||||
if (!param.indexed) {
|
||||
if (value != null) {
|
||||
logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
topics.push(null);
|
||||
}
|
||||
else if (param.baseType === "array" || param.baseType === "tuple") {
|
||||
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
topics.push(value.map((value) => encodeTopic(param, value)));
|
||||
}
|
||||
else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
// Trim off trailing nulls
|
||||
while (topics.length && topics[topics.length - 1] === null) {
|
||||
topics.pop();
|
||||
}
|
||||
return topics;
|
||||
}
|
||||
encodeEventLog(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
const topics = [];
|
||||
const dataTypes = [];
|
||||
const dataValues = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
if (values.length !== eventFragment.inputs.length) {
|
||||
logger.throwArgumentError("event arguments/values mismatch", "values", values);
|
||||
}
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
const value = values[index];
|
||||
if (param.indexed) {
|
||||
if (param.type === "string") {
|
||||
topics.push(id(value));
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
topics.push(keccak256(value));
|
||||
}
|
||||
else if (param.baseType === "tuple" || param.baseType === "array") {
|
||||
// @TOOD
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
else {
|
||||
topics.push(this._abiCoder.encode([param.type], [value]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataTypes.push(param);
|
||||
dataValues.push(value);
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: this._abiCoder.encode(dataTypes, dataValues),
|
||||
topics: topics
|
||||
};
|
||||
}
|
||||
// Decode a filter for the event and the search criteria
|
||||
decodeEventLog(eventFragment, data, topics) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (topics != null && !eventFragment.anonymous) {
|
||||
let topicHash = this.getEventTopic(eventFragment);
|
||||
if (!isHexString(topics[0], 32) || topics[0].toLowerCase() !== topicHash) {
|
||||
logger.throwError("fragment/topic mismatch", Logger.errors.INVALID_ARGUMENT, { argument: "topics[0]", expected: topicHash, value: topics[0] });
|
||||
}
|
||||
topics = topics.slice(1);
|
||||
}
|
||||
let indexed = [];
|
||||
let nonIndexed = [];
|
||||
let dynamic = [];
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
if (param.indexed) {
|
||||
if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
|
||||
indexed.push(ParamType.fromObject({ type: "bytes32", name: param.name }));
|
||||
dynamic.push(true);
|
||||
}
|
||||
else {
|
||||
indexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nonIndexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
});
|
||||
let resultIndexed = (topics != null) ? this._abiCoder.decode(indexed, concat(topics)) : null;
|
||||
let resultNonIndexed = this._abiCoder.decode(nonIndexed, data);
|
||||
let result = [];
|
||||
let nonIndexedIndex = 0, indexedIndex = 0;
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
if (param.indexed) {
|
||||
if (resultIndexed == null) {
|
||||
result[index] = new Indexed({ _isIndexed: true, hash: null });
|
||||
}
|
||||
else if (dynamic[index]) {
|
||||
result[index] = new Indexed({ _isIndexed: true, hash: resultIndexed[indexedIndex++] });
|
||||
}
|
||||
else {
|
||||
try {
|
||||
result[index] = resultIndexed[indexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
result[index] = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
result[index] = resultNonIndexed[nonIndexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
result[index] = error;
|
||||
}
|
||||
}
|
||||
// Add the keyword argument if named and safe
|
||||
if (param.name && result[param.name] == null) {
|
||||
const value = result[index];
|
||||
// Make error named values throw on access
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(result, param.name, {
|
||||
get: () => { throw wrapAccessError(`property ${JSON.stringify(param.name)}`, value); }
|
||||
});
|
||||
}
|
||||
else {
|
||||
result[param.name] = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
// Make all error indexed values throw on access
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
const value = result[i];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(result, i, {
|
||||
get: () => { throw wrapAccessError(`index ${i}`, value); }
|
||||
});
|
||||
}
|
||||
}
|
||||
return Object.freeze(result);
|
||||
}
|
||||
// Given a transaction, find the matching function fragment (if any) and
|
||||
// determine all its properties and call parameters
|
||||
parseTransaction(tx) {
|
||||
let fragment = this.getFunction(tx.data.substring(0, 10).toLowerCase());
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
return new TransactionDescription({
|
||||
args: this._abiCoder.decode(fragment.inputs, "0x" + tx.data.substring(10)),
|
||||
functionFragment: fragment,
|
||||
name: fragment.name,
|
||||
signature: fragment.format(),
|
||||
sighash: this.getSighash(fragment),
|
||||
value: BigNumber.from(tx.value || "0"),
|
||||
});
|
||||
}
|
||||
// Given an event log, find the matching event fragment (if any) and
|
||||
// determine all its properties and values
|
||||
parseLog(log) {
|
||||
let fragment = this.getEvent(log.topics[0]);
|
||||
if (!fragment || fragment.anonymous) {
|
||||
return null;
|
||||
}
|
||||
// @TODO: If anonymous, and the only method, and the input count matches, should we parse?
|
||||
// Probably not, because just because it is the only event in the ABI does
|
||||
// not mean we have the full ABI; maybe jsut a fragment?
|
||||
return new LogDescription({
|
||||
eventFragment: fragment,
|
||||
name: fragment.name,
|
||||
signature: fragment.format(),
|
||||
topic: this.getEventTopic(fragment),
|
||||
args: this.decodeEventLog(fragment, log.data, log.topics)
|
||||
});
|
||||
}
|
||||
/*
|
||||
static from(value: Array<Fragment | string | JsonAbi> | string | Interface) {
|
||||
if (Interface.isInterface(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof(value) === "string") {
|
||||
return new Interface(JSON.parse(value));
|
||||
}
|
||||
return new Interface(value);
|
||||
}
|
||||
*/
|
||||
static isInterface(value) {
|
||||
return !!(value && value._isInterface);
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "abi/5.0.0-beta.153";
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var abstract_coder_1 = require("./coders/abstract-coder");
|
||||
var address_1 = require("./coders/address");
|
||||
var array_1 = require("./coders/array");
|
||||
var boolean_1 = require("./coders/boolean");
|
||||
var bytes_2 = require("./coders/bytes");
|
||||
var fixed_bytes_1 = require("./coders/fixed-bytes");
|
||||
var null_1 = require("./coders/null");
|
||||
var number_1 = require("./coders/number");
|
||||
var string_1 = require("./coders/string");
|
||||
var tuple_1 = require("./coders/tuple");
|
||||
var fragments_1 = require("./fragments");
|
||||
var paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
||||
var paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
||||
var AbiCoder = /** @class */ (function () {
|
||||
function AbiCoder(coerceFunc) {
|
||||
var _newTarget = this.constructor;
|
||||
logger.checkNew(_newTarget, AbiCoder);
|
||||
properties_1.defineReadOnly(this, "coerceFunc", coerceFunc || null);
|
||||
}
|
||||
AbiCoder.prototype._getCoder = function (param) {
|
||||
var _this = this;
|
||||
switch (param.baseType) {
|
||||
case "address":
|
||||
return new address_1.AddressCoder(param.name);
|
||||
case "bool":
|
||||
return new boolean_1.BooleanCoder(param.name);
|
||||
case "string":
|
||||
return new string_1.StringCoder(param.name);
|
||||
case "bytes":
|
||||
return new bytes_2.BytesCoder(param.name);
|
||||
case "array":
|
||||
return new array_1.ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
|
||||
case "tuple":
|
||||
return new tuple_1.TupleCoder((param.components || []).map(function (component) {
|
||||
return _this._getCoder(component);
|
||||
}), param.name);
|
||||
case "":
|
||||
return new null_1.NullCoder(param.name);
|
||||
}
|
||||
// u?int[0-9]*
|
||||
var match = param.type.match(paramTypeNumber);
|
||||
if (match) {
|
||||
var size = parseInt(match[2] || "256");
|
||||
if (size === 0 || size > 256 || (size % 8) !== 0) {
|
||||
logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
|
||||
}
|
||||
return new number_1.NumberCoder(size / 8, (match[1] === "int"), param.name);
|
||||
}
|
||||
// bytes[0-9]+
|
||||
match = param.type.match(paramTypeBytes);
|
||||
if (match) {
|
||||
var size = parseInt(match[1]);
|
||||
if (size === 0 || size > 32) {
|
||||
logger.throwArgumentError("invalid bytes length", "param", param);
|
||||
}
|
||||
return new fixed_bytes_1.FixedBytesCoder(size, param.name);
|
||||
}
|
||||
return logger.throwArgumentError("invalid type", "type", param.type);
|
||||
};
|
||||
AbiCoder.prototype._getWordSize = function () { return 32; };
|
||||
AbiCoder.prototype._getReader = function (data) {
|
||||
return new abstract_coder_1.Reader(data, this._getWordSize(), this.coerceFunc);
|
||||
};
|
||||
AbiCoder.prototype._getWriter = function () {
|
||||
return new abstract_coder_1.Writer(this._getWordSize());
|
||||
};
|
||||
AbiCoder.prototype.encode = function (types, values) {
|
||||
var _this = this;
|
||||
if (types.length !== values.length) {
|
||||
logger.throwError("types/values length mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, {
|
||||
count: { types: types.length, values: values.length },
|
||||
value: { types: types, values: values }
|
||||
});
|
||||
}
|
||||
var coders = types.map(function (type) { return _this._getCoder(fragments_1.ParamType.from(type)); });
|
||||
var coder = (new tuple_1.TupleCoder(coders, "_"));
|
||||
var writer = this._getWriter();
|
||||
coder.encode(writer, values);
|
||||
return writer.data;
|
||||
};
|
||||
AbiCoder.prototype.decode = function (types, data) {
|
||||
var _this = this;
|
||||
var coders = types.map(function (type) { return _this._getCoder(fragments_1.ParamType.from(type)); });
|
||||
var coder = new tuple_1.TupleCoder(coders, "_");
|
||||
return coder.decode(this._getReader(bytes_1.arrayify(data)));
|
||||
};
|
||||
return AbiCoder;
|
||||
}());
|
||||
exports.AbiCoder = AbiCoder;
|
||||
exports.defaultAbiCoder = new AbiCoder();
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("../_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
function checkResultErrors(result) {
|
||||
// Find the first error (if any)
|
||||
var errors = [];
|
||||
var checkErrors = function (path, object) {
|
||||
if (!Array.isArray(object)) {
|
||||
return;
|
||||
}
|
||||
for (var key in object) {
|
||||
var childPath = path.slice();
|
||||
childPath.push(key);
|
||||
try {
|
||||
checkErrors(childPath, object[key]);
|
||||
}
|
||||
catch (error) {
|
||||
errors.push({ path: childPath, error: error });
|
||||
}
|
||||
}
|
||||
};
|
||||
checkErrors([], result);
|
||||
return errors;
|
||||
}
|
||||
exports.checkResultErrors = checkResultErrors;
|
||||
var Coder = /** @class */ (function () {
|
||||
function Coder(name, type, localName, dynamic) {
|
||||
// @TODO: defineReadOnly these
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.localName = localName;
|
||||
this.dynamic = dynamic;
|
||||
}
|
||||
Coder.prototype._throwError = function (message, value) {
|
||||
logger.throwArgumentError(message, this.localName, value);
|
||||
};
|
||||
return Coder;
|
||||
}());
|
||||
exports.Coder = Coder;
|
||||
var Writer = /** @class */ (function () {
|
||||
function Writer(wordSize) {
|
||||
properties_1.defineReadOnly(this, "wordSize", wordSize || 32);
|
||||
this._data = bytes_1.arrayify([]);
|
||||
this._padding = new Uint8Array(wordSize);
|
||||
}
|
||||
Object.defineProperty(Writer.prototype, "data", {
|
||||
get: function () { return bytes_1.hexlify(this._data); },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Writer.prototype, "length", {
|
||||
get: function () { return this._data.length; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Writer.prototype._writeData = function (data) {
|
||||
this._data = bytes_1.concat([this._data, data]);
|
||||
return data.length;
|
||||
};
|
||||
// Arrayish items; padded on the right to wordSize
|
||||
Writer.prototype.writeBytes = function (value) {
|
||||
var bytes = bytes_1.arrayify(value);
|
||||
if (bytes.length % this.wordSize) {
|
||||
bytes = bytes_1.concat([bytes, this._padding.slice(bytes.length % this.wordSize)]);
|
||||
}
|
||||
return this._writeData(bytes);
|
||||
};
|
||||
Writer.prototype._getValue = function (value) {
|
||||
var bytes = bytes_1.arrayify(bignumber_1.BigNumber.from(value));
|
||||
if (bytes.length > this.wordSize) {
|
||||
logger.throwError("value out-of-bounds", logger_1.Logger.errors.BUFFER_OVERRUN, {
|
||||
length: this.wordSize,
|
||||
offset: bytes.length
|
||||
});
|
||||
}
|
||||
if (bytes.length % this.wordSize) {
|
||||
bytes = bytes_1.concat([this._padding.slice(bytes.length % this.wordSize), bytes]);
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
// BigNumberish items; padded on the left to wordSize
|
||||
Writer.prototype.writeValue = function (value) {
|
||||
return this._writeData(this._getValue(value));
|
||||
};
|
||||
Writer.prototype.writeUpdatableValue = function () {
|
||||
var _this = this;
|
||||
var offset = this.length;
|
||||
this.writeValue(0);
|
||||
return function (value) {
|
||||
_this._data.set(_this._getValue(value), offset);
|
||||
};
|
||||
};
|
||||
return Writer;
|
||||
}());
|
||||
exports.Writer = Writer;
|
||||
var Reader = /** @class */ (function () {
|
||||
function Reader(data, wordSize, coerceFunc) {
|
||||
properties_1.defineReadOnly(this, "_data", bytes_1.arrayify(data));
|
||||
properties_1.defineReadOnly(this, "wordSize", wordSize || 32);
|
||||
properties_1.defineReadOnly(this, "_coerceFunc", coerceFunc);
|
||||
this._offset = 0;
|
||||
}
|
||||
Object.defineProperty(Reader.prototype, "data", {
|
||||
get: function () { return bytes_1.hexlify(this._data); },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Reader.prototype, "consumed", {
|
||||
get: function () { return this._offset; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
// The default Coerce function
|
||||
Reader.coerce = function (name, value) {
|
||||
var match = name.match("^u?int([0-9]+)$");
|
||||
if (match && parseInt(match[1]) <= 48) {
|
||||
value = value.toNumber();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
Reader.prototype.coerce = function (name, value) {
|
||||
if (this._coerceFunc) {
|
||||
return this._coerceFunc(name, value);
|
||||
}
|
||||
return Reader.coerce(name, value);
|
||||
};
|
||||
Reader.prototype._peekBytes = function (offset, length) {
|
||||
var alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
|
||||
if (this._offset + alignedLength > this._data.length) {
|
||||
logger.throwError("data out-of-bounds", logger_1.Logger.errors.BUFFER_OVERRUN, {
|
||||
length: this._data.length,
|
||||
offset: this._offset + alignedLength
|
||||
});
|
||||
}
|
||||
return this._data.slice(this._offset, this._offset + alignedLength);
|
||||
};
|
||||
Reader.prototype.subReader = function (offset) {
|
||||
return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc);
|
||||
};
|
||||
Reader.prototype.readBytes = function (length) {
|
||||
var bytes = this._peekBytes(0, length);
|
||||
this._offset += bytes.length;
|
||||
// @TODO: Make sure the length..end bytes are all 0?
|
||||
return bytes.slice(0, length);
|
||||
};
|
||||
Reader.prototype.readValue = function () {
|
||||
return bignumber_1.BigNumber.from(this.readBytes(this.wordSize));
|
||||
};
|
||||
return Reader;
|
||||
}());
|
||||
exports.Reader = Reader;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var address_1 = require("@ethersproject/address");
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var AddressCoder = /** @class */ (function (_super) {
|
||||
__extends(AddressCoder, _super);
|
||||
function AddressCoder(localName) {
|
||||
return _super.call(this, "address", "address", localName, false) || this;
|
||||
}
|
||||
AddressCoder.prototype.encode = function (writer, value) {
|
||||
try {
|
||||
address_1.getAddress(value);
|
||||
}
|
||||
catch (error) {
|
||||
this._throwError(error.message, value);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
};
|
||||
AddressCoder.prototype.decode = function (reader) {
|
||||
return address_1.getAddress(bytes_1.hexZeroPad(reader.readValue().toHexString(), 20));
|
||||
};
|
||||
return AddressCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.AddressCoder = AddressCoder;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
// Clones the functionality of an existing Coder, but without a localName
|
||||
var AnonymousCoder = /** @class */ (function (_super) {
|
||||
__extends(AnonymousCoder, _super);
|
||||
function AnonymousCoder(coder) {
|
||||
var _this = _super.call(this, coder.name, coder.type, undefined, coder.dynamic) || this;
|
||||
_this.coder = coder;
|
||||
return _this;
|
||||
}
|
||||
AnonymousCoder.prototype.encode = function (writer, value) {
|
||||
return this.coder.encode(writer, value);
|
||||
};
|
||||
AnonymousCoder.prototype.decode = function (reader) {
|
||||
return this.coder.decode(reader);
|
||||
};
|
||||
return AnonymousCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.AnonymousCoder = AnonymousCoder;
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("../_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var anonymous_1 = require("./anonymous");
|
||||
function pack(writer, coders, values) {
|
||||
if (Array.isArray(values)) {
|
||||
// do nothing
|
||||
}
|
||||
else if (values && typeof (values) === "object") {
|
||||
var arrayValues_1 = [];
|
||||
coders.forEach(function (coder) {
|
||||
arrayValues_1.push(values[coder.localName]);
|
||||
});
|
||||
values = arrayValues_1;
|
||||
}
|
||||
else {
|
||||
logger.throwArgumentError("invalid tuple value", "tuple", values);
|
||||
}
|
||||
if (coders.length !== values.length) {
|
||||
logger.throwArgumentError("types/value length mismatch", "tuple", values);
|
||||
}
|
||||
var staticWriter = new abstract_coder_1.Writer(writer.wordSize);
|
||||
var dynamicWriter = new abstract_coder_1.Writer(writer.wordSize);
|
||||
var updateFuncs = [];
|
||||
coders.forEach(function (coder, index) {
|
||||
var value = values[index];
|
||||
if (coder.dynamic) {
|
||||
// Get current dynamic offset (for the future pointer)
|
||||
var dynamicOffset_1 = dynamicWriter.length;
|
||||
// Encode the dynamic value into the dynamicWriter
|
||||
coder.encode(dynamicWriter, value);
|
||||
// Prepare to populate the correct offset once we are done
|
||||
var updateFunc_1 = staticWriter.writeUpdatableValue();
|
||||
updateFuncs.push(function (baseOffset) {
|
||||
updateFunc_1(baseOffset + dynamicOffset_1);
|
||||
});
|
||||
}
|
||||
else {
|
||||
coder.encode(staticWriter, value);
|
||||
}
|
||||
});
|
||||
// Backfill all the dynamic offsets, now that we know the static length
|
||||
updateFuncs.forEach(function (func) { func(staticWriter.length); });
|
||||
var length = writer.writeBytes(staticWriter.data);
|
||||
length += writer.writeBytes(dynamicWriter.data);
|
||||
return length;
|
||||
}
|
||||
exports.pack = pack;
|
||||
function unpack(reader, coders) {
|
||||
var values = [];
|
||||
// A reader anchored to this base
|
||||
var baseReader = reader.subReader(0);
|
||||
// The amount of dynamic data read; to consume later to synchronize
|
||||
var dynamicLength = 0;
|
||||
coders.forEach(function (coder) {
|
||||
var value = null;
|
||||
if (coder.dynamic) {
|
||||
var offset = reader.readValue();
|
||||
var offsetReader = baseReader.subReader(offset.toNumber());
|
||||
try {
|
||||
value = coder.decode(offsetReader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (error.code === logger_1.Logger.errors.BUFFER_OVERRUN) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
dynamicLength += offsetReader.consumed;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = coder.decode(reader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (error.code === logger_1.Logger.errors.BUFFER_OVERRUN) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
if (value != undefined) {
|
||||
values.push(value);
|
||||
}
|
||||
});
|
||||
// @TODO: get rid of this an see if it still works?
|
||||
// Consume the dynamic components in the main reader
|
||||
reader.readBytes(dynamicLength);
|
||||
// Add any named parameters (i.e. tuples)
|
||||
coders.forEach(function (coder, index) {
|
||||
var name = coder.localName;
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
if (name === "length") {
|
||||
name = "_length";
|
||||
}
|
||||
if (values[name] != null) {
|
||||
return;
|
||||
}
|
||||
var value = values[index];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(values, name, {
|
||||
get: function () { throw value; }
|
||||
});
|
||||
}
|
||||
else {
|
||||
values[name] = value;
|
||||
}
|
||||
});
|
||||
var _loop_1 = function (i) {
|
||||
var value = values[i];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(values, i, {
|
||||
get: function () { throw value; }
|
||||
});
|
||||
}
|
||||
};
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return Object.freeze(values);
|
||||
}
|
||||
exports.unpack = unpack;
|
||||
var ArrayCoder = /** @class */ (function (_super) {
|
||||
__extends(ArrayCoder, _super);
|
||||
function ArrayCoder(coder, length, localName) {
|
||||
var _this = this;
|
||||
var type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
||||
var dynamic = (length === -1 || coder.dynamic);
|
||||
_this = _super.call(this, "array", type, localName, dynamic) || this;
|
||||
_this.coder = coder;
|
||||
_this.length = length;
|
||||
return _this;
|
||||
}
|
||||
ArrayCoder.prototype.encode = function (writer, value) {
|
||||
if (!Array.isArray(value)) {
|
||||
this._throwError("expected array value", value);
|
||||
}
|
||||
var count = this.length;
|
||||
if (count === -1) {
|
||||
count = value.length;
|
||||
writer.writeValue(value.length);
|
||||
}
|
||||
logger.checkArgumentCount(count, value.length, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
||||
var coders = [];
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
}
|
||||
return pack(writer, coders, value);
|
||||
};
|
||||
ArrayCoder.prototype.decode = function (reader) {
|
||||
var count = this.length;
|
||||
if (count === -1) {
|
||||
count = reader.readValue().toNumber();
|
||||
}
|
||||
var coders = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
coders.push(new anonymous_1.AnonymousCoder(this.coder));
|
||||
}
|
||||
return reader.coerce(this.name, unpack(reader, coders));
|
||||
};
|
||||
return ArrayCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.ArrayCoder = ArrayCoder;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var BooleanCoder = /** @class */ (function (_super) {
|
||||
__extends(BooleanCoder, _super);
|
||||
function BooleanCoder(localName) {
|
||||
return _super.call(this, "bool", "bool", localName, false) || this;
|
||||
}
|
||||
BooleanCoder.prototype.encode = function (writer, value) {
|
||||
return writer.writeValue(value ? 1 : 0);
|
||||
};
|
||||
BooleanCoder.prototype.decode = function (reader) {
|
||||
return reader.coerce(this.type, !reader.readValue().isZero());
|
||||
};
|
||||
return BooleanCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.BooleanCoder = BooleanCoder;
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var DynamicBytesCoder = /** @class */ (function (_super) {
|
||||
__extends(DynamicBytesCoder, _super);
|
||||
function DynamicBytesCoder(type, localName) {
|
||||
return _super.call(this, type, type, localName, true) || this;
|
||||
}
|
||||
DynamicBytesCoder.prototype.encode = function (writer, value) {
|
||||
value = bytes_1.arrayify(value);
|
||||
var length = writer.writeValue(value.length);
|
||||
length += writer.writeBytes(value);
|
||||
return length;
|
||||
};
|
||||
DynamicBytesCoder.prototype.decode = function (reader) {
|
||||
return reader.readBytes(reader.readValue().toNumber());
|
||||
};
|
||||
return DynamicBytesCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.DynamicBytesCoder = DynamicBytesCoder;
|
||||
var BytesCoder = /** @class */ (function (_super) {
|
||||
__extends(BytesCoder, _super);
|
||||
function BytesCoder(localName) {
|
||||
return _super.call(this, "bytes", localName) || this;
|
||||
}
|
||||
BytesCoder.prototype.decode = function (reader) {
|
||||
return reader.coerce(this.name, bytes_1.hexlify(_super.prototype.decode.call(this, reader)));
|
||||
};
|
||||
return BytesCoder;
|
||||
}(DynamicBytesCoder));
|
||||
exports.BytesCoder = BytesCoder;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
// @TODO: Merge this with bytes
|
||||
var FixedBytesCoder = /** @class */ (function (_super) {
|
||||
__extends(FixedBytesCoder, _super);
|
||||
function FixedBytesCoder(size, localName) {
|
||||
var _this = this;
|
||||
var name = "bytes" + String(size);
|
||||
_this = _super.call(this, name, name, localName, false) || this;
|
||||
_this.size = size;
|
||||
return _this;
|
||||
}
|
||||
FixedBytesCoder.prototype.encode = function (writer, value) {
|
||||
var data = bytes_1.arrayify(value);
|
||||
if (data.length !== this.size) {
|
||||
this._throwError("incorrect data length", value);
|
||||
}
|
||||
return writer.writeBytes(data);
|
||||
};
|
||||
FixedBytesCoder.prototype.decode = function (reader) {
|
||||
return reader.coerce(this.name, bytes_1.hexlify(reader.readBytes(this.size)));
|
||||
};
|
||||
return FixedBytesCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.FixedBytesCoder = FixedBytesCoder;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var NullCoder = /** @class */ (function (_super) {
|
||||
__extends(NullCoder, _super);
|
||||
function NullCoder(localName) {
|
||||
return _super.call(this, "null", "", localName, false) || this;
|
||||
}
|
||||
NullCoder.prototype.encode = function (writer, value) {
|
||||
if (value != null) {
|
||||
this._throwError("not null", value);
|
||||
}
|
||||
return writer.writeBytes([]);
|
||||
};
|
||||
NullCoder.prototype.decode = function (reader) {
|
||||
reader.readBytes(0);
|
||||
return reader.coerce(this.name, null);
|
||||
};
|
||||
return NullCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.NullCoder = NullCoder;
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var constants_1 = require("@ethersproject/constants");
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var NumberCoder = /** @class */ (function (_super) {
|
||||
__extends(NumberCoder, _super);
|
||||
function NumberCoder(size, signed, localName) {
|
||||
var _this = this;
|
||||
var name = ((signed ? "int" : "uint") + (size * 8));
|
||||
_this = _super.call(this, name, name, localName, false) || this;
|
||||
_this.size = size;
|
||||
_this.signed = signed;
|
||||
return _this;
|
||||
}
|
||||
NumberCoder.prototype.encode = function (writer, value) {
|
||||
var v = bignumber_1.BigNumber.from(value);
|
||||
// Check bounds are safe for encoding
|
||||
var maxUintValue = constants_1.MaxUint256.mask(writer.wordSize * 8);
|
||||
if (this.signed) {
|
||||
var bounds = maxUintValue.mask(this.size * 8 - 1);
|
||||
if (v.gt(bounds) || v.lt(bounds.add(constants_1.One).mul(constants_1.NegativeOne))) {
|
||||
this._throwError("value out-of-bounds", value);
|
||||
}
|
||||
}
|
||||
else if (v.lt(constants_1.Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
|
||||
this._throwError("value out-of-bounds", value);
|
||||
}
|
||||
v = v.toTwos(this.size * 8).mask(this.size * 8);
|
||||
if (this.signed) {
|
||||
v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
|
||||
}
|
||||
return writer.writeValue(v);
|
||||
};
|
||||
NumberCoder.prototype.decode = function (reader) {
|
||||
var value = reader.readValue().mask(this.size * 8);
|
||||
if (this.signed) {
|
||||
value = value.fromTwos(this.size * 8);
|
||||
}
|
||||
return reader.coerce(this.name, value);
|
||||
};
|
||||
return NumberCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.NumberCoder = NumberCoder;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var strings_1 = require("@ethersproject/strings");
|
||||
var bytes_1 = require("./bytes");
|
||||
var StringCoder = /** @class */ (function (_super) {
|
||||
__extends(StringCoder, _super);
|
||||
function StringCoder(localName) {
|
||||
return _super.call(this, "string", localName) || this;
|
||||
}
|
||||
StringCoder.prototype.encode = function (writer, value) {
|
||||
return _super.prototype.encode.call(this, writer, strings_1.toUtf8Bytes(value));
|
||||
};
|
||||
StringCoder.prototype.decode = function (reader) {
|
||||
return strings_1.toUtf8String(_super.prototype.decode.call(this, reader));
|
||||
};
|
||||
return StringCoder;
|
||||
}(bytes_1.DynamicBytesCoder));
|
||||
exports.StringCoder = StringCoder;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var abstract_coder_1 = require("./abstract-coder");
|
||||
var array_1 = require("./array");
|
||||
var TupleCoder = /** @class */ (function (_super) {
|
||||
__extends(TupleCoder, _super);
|
||||
function TupleCoder(coders, localName) {
|
||||
var _this = this;
|
||||
var dynamic = false;
|
||||
var types = [];
|
||||
coders.forEach(function (coder) {
|
||||
if (coder.dynamic) {
|
||||
dynamic = true;
|
||||
}
|
||||
types.push(coder.type);
|
||||
});
|
||||
var type = ("tuple(" + types.join(",") + ")");
|
||||
_this = _super.call(this, "tuple", type, localName, dynamic) || this;
|
||||
_this.coders = coders;
|
||||
return _this;
|
||||
}
|
||||
TupleCoder.prototype.encode = function (writer, value) {
|
||||
return array_1.pack(writer, this.coders, value);
|
||||
};
|
||||
TupleCoder.prototype.decode = function (reader) {
|
||||
return reader.coerce(this.name, array_1.unpack(reader, this.coders));
|
||||
};
|
||||
return TupleCoder;
|
||||
}(abstract_coder_1.Coder));
|
||||
exports.TupleCoder = TupleCoder;
|
||||
+816
@@ -0,0 +1,816 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
;
|
||||
var _constructorGuard = {};
|
||||
var ModifiersBytes = { calldata: true, memory: true, storage: true };
|
||||
var ModifiersNest = { calldata: true, memory: true };
|
||||
function checkModifier(type, name) {
|
||||
if (type === "bytes" || type === "string") {
|
||||
if (ModifiersBytes[name]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type === "address") {
|
||||
if (name === "payable") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type.indexOf("[") >= 0 || type === "tuple") {
|
||||
if (ModifiersNest[name]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ModifiersBytes[name] || name === "payable") {
|
||||
logger.throwArgumentError("invalid modifier", "name", name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// @TODO: Make sure that children of an indexed tuple are marked with a null indexed
|
||||
function parseParamType(param, allowIndexed) {
|
||||
var originalParam = param;
|
||||
function throwError(i) {
|
||||
logger.throwArgumentError("unexpected character at position " + i, "param", param);
|
||||
}
|
||||
param = param.replace(/\s/g, " ");
|
||||
function newNode(parent) {
|
||||
var node = { type: "", name: "", parent: parent, state: { allowType: true } };
|
||||
if (allowIndexed) {
|
||||
node.indexed = false;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
var parent = { type: "", name: "", state: { allowType: true } };
|
||||
var node = parent;
|
||||
for (var i = 0; i < param.length; i++) {
|
||||
var c = param[i];
|
||||
switch (c) {
|
||||
case "(":
|
||||
if (node.state.allowType && node.type === "") {
|
||||
node.type = "tuple";
|
||||
}
|
||||
else if (!node.state.allowParams) {
|
||||
throwError(i);
|
||||
}
|
||||
node.state.allowType = false;
|
||||
node.type = verifyType(node.type);
|
||||
node.components = [newNode(node)];
|
||||
node = node.components[0];
|
||||
break;
|
||||
case ")":
|
||||
delete node.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
node.type = verifyType(node.type);
|
||||
var child = node;
|
||||
node = node.parent;
|
||||
if (!node) {
|
||||
throwError(i);
|
||||
}
|
||||
delete child.parent;
|
||||
node.state.allowParams = false;
|
||||
node.state.allowName = true;
|
||||
node.state.allowArray = true;
|
||||
break;
|
||||
case ",":
|
||||
delete node.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
node.type = verifyType(node.type);
|
||||
var sibling = newNode(node.parent);
|
||||
//{ type: "", name: "", parent: node.parent, state: { allowType: true } };
|
||||
node.parent.components.push(sibling);
|
||||
delete node.parent;
|
||||
node = sibling;
|
||||
break;
|
||||
// Hit a space...
|
||||
case " ":
|
||||
// If reading type, the type is done and may read a param or name
|
||||
if (node.state.allowType) {
|
||||
if (node.type !== "") {
|
||||
node.type = verifyType(node.type);
|
||||
delete node.state.allowType;
|
||||
node.state.allowName = true;
|
||||
node.state.allowParams = true;
|
||||
}
|
||||
}
|
||||
// If reading name, the name is done
|
||||
if (node.state.allowName) {
|
||||
if (node.name !== "") {
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(i);
|
||||
}
|
||||
if (node.indexed) {
|
||||
throwError(i);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
else if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
else {
|
||||
node.state.allowName = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "[":
|
||||
if (!node.state.allowArray) {
|
||||
throwError(i);
|
||||
}
|
||||
node.type += c;
|
||||
node.state.allowArray = false;
|
||||
node.state.allowName = false;
|
||||
node.state.readArray = true;
|
||||
break;
|
||||
case "]":
|
||||
if (!node.state.readArray) {
|
||||
throwError(i);
|
||||
}
|
||||
node.type += c;
|
||||
node.state.readArray = false;
|
||||
node.state.allowArray = true;
|
||||
node.state.allowName = true;
|
||||
break;
|
||||
default:
|
||||
if (node.state.allowType) {
|
||||
node.type += c;
|
||||
node.state.allowParams = true;
|
||||
node.state.allowArray = true;
|
||||
}
|
||||
else if (node.state.allowName) {
|
||||
node.name += c;
|
||||
delete node.state.allowArray;
|
||||
}
|
||||
else if (node.state.readArray) {
|
||||
node.type += c;
|
||||
}
|
||||
else {
|
||||
throwError(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.parent) {
|
||||
logger.throwArgumentError("unexpected eof", "param", param);
|
||||
}
|
||||
delete parent.state;
|
||||
if (node.name === "indexed") {
|
||||
if (!allowIndexed) {
|
||||
throwError(originalParam.length - 7);
|
||||
}
|
||||
if (node.indexed) {
|
||||
throwError(originalParam.length - 7);
|
||||
}
|
||||
node.indexed = true;
|
||||
node.name = "";
|
||||
}
|
||||
else if (checkModifier(node.type, node.name)) {
|
||||
node.name = "";
|
||||
}
|
||||
parent.type = verifyType(parent.type);
|
||||
return parent;
|
||||
}
|
||||
function populate(object, params) {
|
||||
for (var key in params) {
|
||||
properties_1.defineReadOnly(object, key, params[key]);
|
||||
}
|
||||
}
|
||||
exports.FormatTypes = Object.freeze({
|
||||
// Bare formatting, as is needed for computing a sighash of an event or function
|
||||
sighash: "sighash",
|
||||
// Human-Readable with Minimal spacing and without names (compact human-readable)
|
||||
minimal: "minimal",
|
||||
// Human-Readble with nice spacing, including all names
|
||||
full: "full",
|
||||
// JSON-format a la Solidity
|
||||
json: "json"
|
||||
});
|
||||
var paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
|
||||
var ParamType = /** @class */ (function () {
|
||||
function ParamType(constructorGuard, params) {
|
||||
if (constructorGuard !== _constructorGuard) {
|
||||
logger.throwError("use fromString", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "new ParamType()"
|
||||
});
|
||||
}
|
||||
populate(this, params);
|
||||
var match = this.type.match(paramTypeArray);
|
||||
if (match) {
|
||||
populate(this, {
|
||||
arrayLength: parseInt(match[2] || "-1"),
|
||||
arrayChildren: ParamType.fromObject({
|
||||
type: match[1],
|
||||
components: this.components
|
||||
}),
|
||||
baseType: "array"
|
||||
});
|
||||
}
|
||||
else {
|
||||
populate(this, {
|
||||
arrayLength: null,
|
||||
arrayChildren: null,
|
||||
baseType: ((this.components != null) ? "tuple" : this.type)
|
||||
});
|
||||
}
|
||||
this._isParamType = true;
|
||||
Object.freeze(this);
|
||||
}
|
||||
// Format the parameter fragment
|
||||
// - sighash: "(uint256,address)"
|
||||
// - minimal: "tuple(uint256,address) indexed"
|
||||
// - full: "tuple(uint256 foo, addres bar) indexed baz"
|
||||
ParamType.prototype.format = function (format) {
|
||||
if (!format) {
|
||||
format = exports.FormatTypes.sighash;
|
||||
}
|
||||
if (!exports.FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === exports.FormatTypes.json) {
|
||||
var result_1 = {
|
||||
type: ((this.baseType === "tuple") ? "tuple" : this.type),
|
||||
name: (this.name || undefined)
|
||||
};
|
||||
if (typeof (this.indexed) === "boolean") {
|
||||
result_1.indexed = this.indexed;
|
||||
}
|
||||
if (this.components) {
|
||||
result_1.components = this.components.map(function (comp) { return JSON.parse(comp.format(format)); });
|
||||
}
|
||||
return JSON.stringify(result_1);
|
||||
}
|
||||
var result = "";
|
||||
// Array
|
||||
if (this.baseType === "array") {
|
||||
result += this.arrayChildren.format(format);
|
||||
result += "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
|
||||
}
|
||||
else {
|
||||
if (this.baseType === "tuple") {
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
result += this.type;
|
||||
}
|
||||
result += "(" + this.components.map(function (comp) { return comp.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ")";
|
||||
}
|
||||
else {
|
||||
result += this.type;
|
||||
}
|
||||
}
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
if (this.indexed === true) {
|
||||
result += " indexed";
|
||||
}
|
||||
if (format === exports.FormatTypes.full && this.name) {
|
||||
result += " " + this.name;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
ParamType.from = function (value, allowIndexed) {
|
||||
if (typeof (value) === "string") {
|
||||
return ParamType.fromString(value, allowIndexed);
|
||||
}
|
||||
return ParamType.fromObject(value);
|
||||
};
|
||||
ParamType.fromObject = function (value) {
|
||||
if (ParamType.isParamType(value)) {
|
||||
return value;
|
||||
}
|
||||
return new ParamType(_constructorGuard, {
|
||||
name: (value.name || null),
|
||||
type: verifyType(value.type),
|
||||
indexed: ((value.indexed == null) ? null : !!value.indexed),
|
||||
components: (value.components ? value.components.map(ParamType.fromObject) : null)
|
||||
});
|
||||
};
|
||||
ParamType.fromString = function (value, allowIndexed) {
|
||||
function ParamTypify(node) {
|
||||
return ParamType.fromObject({
|
||||
name: node.name,
|
||||
type: node.type,
|
||||
indexed: node.indexed,
|
||||
components: node.components
|
||||
});
|
||||
}
|
||||
return ParamTypify(parseParamType(value, !!allowIndexed));
|
||||
};
|
||||
ParamType.isParamType = function (value) {
|
||||
return !!(value != null && value._isParamType);
|
||||
};
|
||||
return ParamType;
|
||||
}());
|
||||
exports.ParamType = ParamType;
|
||||
;
|
||||
function parseParams(value, allowIndex) {
|
||||
return splitNesting(value).map(function (param) { return ParamType.fromString(param, allowIndex); });
|
||||
}
|
||||
var Fragment = /** @class */ (function () {
|
||||
function Fragment(constructorGuard, params) {
|
||||
if (constructorGuard !== _constructorGuard) {
|
||||
logger.throwError("use a static from method", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "new Fragment()"
|
||||
});
|
||||
}
|
||||
populate(this, params);
|
||||
this._isFragment = true;
|
||||
Object.freeze(this);
|
||||
}
|
||||
Fragment.from = function (value) {
|
||||
if (Fragment.isFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof (value) === "string") {
|
||||
return Fragment.fromString(value);
|
||||
}
|
||||
return Fragment.fromObject(value);
|
||||
};
|
||||
Fragment.fromObject = function (value) {
|
||||
if (Fragment.isFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
switch (value.type) {
|
||||
case "function":
|
||||
return FunctionFragment.fromObject(value);
|
||||
case "event":
|
||||
return EventFragment.fromObject(value);
|
||||
case "constructor":
|
||||
return ConstructorFragment.fromObject(value);
|
||||
case "fallback":
|
||||
case "receive":
|
||||
// @TODO: Something? Maybe return a FunctionFragment? A custom DefaultFunctionFragment?
|
||||
return null;
|
||||
}
|
||||
return logger.throwArgumentError("invalid fragment object", "value", value);
|
||||
};
|
||||
Fragment.fromString = function (value) {
|
||||
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
||||
value = value.replace(/\s/g, " ");
|
||||
value = value.replace(/\(/g, " (").replace(/\)/g, ") ").replace(/\s+/g, " ");
|
||||
value = value.trim();
|
||||
if (value.split(" ")[0] === "event") {
|
||||
return EventFragment.fromString(value.substring(5).trim());
|
||||
}
|
||||
else if (value.split(" ")[0] === "function") {
|
||||
return FunctionFragment.fromString(value.substring(8).trim());
|
||||
}
|
||||
else if (value.split("(")[0].trim() === "constructor") {
|
||||
return ConstructorFragment.fromString(value.trim());
|
||||
}
|
||||
return logger.throwArgumentError("unsupported fragment", "value", value);
|
||||
};
|
||||
Fragment.isFragment = function (value) {
|
||||
return !!(value && value._isFragment);
|
||||
};
|
||||
return Fragment;
|
||||
}());
|
||||
exports.Fragment = Fragment;
|
||||
var EventFragment = /** @class */ (function (_super) {
|
||||
__extends(EventFragment, _super);
|
||||
function EventFragment() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
EventFragment.prototype.format = function (format) {
|
||||
if (!format) {
|
||||
format = exports.FormatTypes.sighash;
|
||||
}
|
||||
if (!exports.FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === exports.FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "event",
|
||||
anonymous: this.anonymous,
|
||||
name: this.name,
|
||||
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); })
|
||||
});
|
||||
}
|
||||
var result = "";
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
result += "event ";
|
||||
}
|
||||
result += this.name + "(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
if (this.anonymous) {
|
||||
result += "anonymous ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
};
|
||||
EventFragment.from = function (value) {
|
||||
if (typeof (value) === "string") {
|
||||
return EventFragment.fromString(value);
|
||||
}
|
||||
return EventFragment.fromObject(value);
|
||||
};
|
||||
EventFragment.fromObject = function (value) {
|
||||
if (EventFragment.isEventFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "event") {
|
||||
logger.throwArgumentError("invalid event object", "value", value);
|
||||
}
|
||||
var params = {
|
||||
name: verifyIdentifier(value.name),
|
||||
anonymous: value.anonymous,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
type: "event"
|
||||
};
|
||||
return new EventFragment(_constructorGuard, params);
|
||||
};
|
||||
EventFragment.fromString = function (value) {
|
||||
var match = value.match(regexParen);
|
||||
if (!match) {
|
||||
logger.throwArgumentError("invalid event string", "value", value);
|
||||
}
|
||||
var anonymous = false;
|
||||
match[3].split(" ").forEach(function (modifier) {
|
||||
switch (modifier.trim()) {
|
||||
case "anonymous":
|
||||
anonymous = true;
|
||||
break;
|
||||
case "":
|
||||
break;
|
||||
default:
|
||||
logger.warn("unknown modifier: " + modifier);
|
||||
}
|
||||
});
|
||||
return EventFragment.fromObject({
|
||||
name: match[1].trim(),
|
||||
anonymous: anonymous,
|
||||
inputs: parseParams(match[2], true),
|
||||
type: "event"
|
||||
});
|
||||
};
|
||||
EventFragment.isEventFragment = function (value) {
|
||||
return (value && value._isFragment && value.type === "event");
|
||||
};
|
||||
return EventFragment;
|
||||
}(Fragment));
|
||||
exports.EventFragment = EventFragment;
|
||||
function parseGas(value, params) {
|
||||
params.gas = null;
|
||||
var comps = value.split("@");
|
||||
if (comps.length !== 1) {
|
||||
if (comps.length > 2) {
|
||||
logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
|
||||
}
|
||||
if (!comps[1].match(/^[0-9]+$/)) {
|
||||
logger.throwArgumentError("invalid human-readable ABI signature gas", "value", value);
|
||||
}
|
||||
params.gas = bignumber_1.BigNumber.from(comps[1]);
|
||||
return comps[0];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function parseModifiers(value, params) {
|
||||
params.constant = false;
|
||||
params.payable = false;
|
||||
params.stateMutability = "nonpayable";
|
||||
value.split(" ").forEach(function (modifier) {
|
||||
switch (modifier.trim()) {
|
||||
case "constant":
|
||||
params.constant = true;
|
||||
break;
|
||||
case "payable":
|
||||
params.payable = true;
|
||||
params.stateMutability = "payable";
|
||||
break;
|
||||
case "pure":
|
||||
params.constant = true;
|
||||
params.stateMutability = "pure";
|
||||
break;
|
||||
case "view":
|
||||
params.constant = true;
|
||||
params.stateMutability = "view";
|
||||
break;
|
||||
case "external":
|
||||
case "public":
|
||||
case "":
|
||||
break;
|
||||
default:
|
||||
console.log("unknown modifier: " + modifier);
|
||||
}
|
||||
});
|
||||
}
|
||||
function verifyState(value) {
|
||||
var result = {
|
||||
constant: false,
|
||||
payable: true,
|
||||
stateMutability: "payable"
|
||||
};
|
||||
if (value.stateMutability != null) {
|
||||
result.stateMutability = value.stateMutability;
|
||||
// Set (and check things are consistent) the constant property
|
||||
result.constant = (result.stateMutability === "view" || result.stateMutability === "pure");
|
||||
if (value.constant != null) {
|
||||
if ((!!value.constant) !== result.constant) {
|
||||
logger.throwArgumentError("cannot have constant function with mutability " + result.stateMutability, "value", value);
|
||||
}
|
||||
}
|
||||
// Set (and check things are consistent) the payable property
|
||||
result.payable = (result.stateMutability === "payable");
|
||||
if (value.payable != null) {
|
||||
if ((!!value.payable) !== result.payable) {
|
||||
logger.throwArgumentError("cannot have payable function with mutability " + result.stateMutability, "value", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value.payable != null) {
|
||||
result.payable = !!value.payable;
|
||||
// If payable we can assume non-constant; otherwise we can't assume
|
||||
if (value.constant == null && !result.payable && value.type !== "constructor") {
|
||||
logger.throwArgumentError("unable to determine stateMutability", "value", value);
|
||||
}
|
||||
result.constant = !!value.constant;
|
||||
if (result.constant) {
|
||||
result.stateMutability = "view";
|
||||
}
|
||||
else {
|
||||
result.stateMutability = (result.payable ? "payable" : "nonpayable");
|
||||
}
|
||||
if (result.payable && result.constant) {
|
||||
logger.throwArgumentError("cannot have constant payable function", "value", value);
|
||||
}
|
||||
}
|
||||
else if (value.constant != null) {
|
||||
result.constant = !!value.constant;
|
||||
result.payable = !result.constant;
|
||||
result.stateMutability = (result.constant ? "view" : "payable");
|
||||
}
|
||||
else if (value.type !== "constructor") {
|
||||
logger.throwArgumentError("unable to determine stateMutability", "value", value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
var ConstructorFragment = /** @class */ (function (_super) {
|
||||
__extends(ConstructorFragment, _super);
|
||||
function ConstructorFragment() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
ConstructorFragment.prototype.format = function (format) {
|
||||
if (!format) {
|
||||
format = exports.FormatTypes.sighash;
|
||||
}
|
||||
if (!exports.FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === exports.FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "constructor",
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payble: this.payable,
|
||||
gas: (this.gas ? this.gas.toNumber() : undefined),
|
||||
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); })
|
||||
});
|
||||
}
|
||||
if (format === exports.FormatTypes.sighash) {
|
||||
logger.throwError("cannot format a constructor for sighash", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
||||
operation: "format(sighash)"
|
||||
});
|
||||
}
|
||||
var result = "constructor(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (this.stateMutability && this.stateMutability !== "nonpayable") {
|
||||
result += this.stateMutability + " ";
|
||||
}
|
||||
return result.trim();
|
||||
};
|
||||
ConstructorFragment.from = function (value) {
|
||||
if (typeof (value) === "string") {
|
||||
return ConstructorFragment.fromString(value);
|
||||
}
|
||||
return ConstructorFragment.fromObject(value);
|
||||
};
|
||||
ConstructorFragment.fromObject = function (value) {
|
||||
if (ConstructorFragment.isConstructorFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "constructor") {
|
||||
logger.throwArgumentError("invalid constructor object", "value", value);
|
||||
}
|
||||
var state = verifyState(value);
|
||||
if (state.constant) {
|
||||
logger.throwArgumentError("constructor cannot be constant", "value", value);
|
||||
}
|
||||
var params = {
|
||||
name: null,
|
||||
type: value.type,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
payable: state.payable,
|
||||
stateMutability: state.stateMutability,
|
||||
gas: (value.gas ? bignumber_1.BigNumber.from(value.gas) : null)
|
||||
};
|
||||
return new ConstructorFragment(_constructorGuard, params);
|
||||
};
|
||||
ConstructorFragment.fromString = function (value) {
|
||||
var params = { type: "constructor" };
|
||||
value = parseGas(value, params);
|
||||
var parens = value.match(regexParen);
|
||||
if (!parens || parens[1].trim() !== "constructor") {
|
||||
logger.throwArgumentError("invalid constructor string", "value", value);
|
||||
}
|
||||
params.inputs = parseParams(parens[2].trim(), false);
|
||||
parseModifiers(parens[3].trim(), params);
|
||||
return ConstructorFragment.fromObject(params);
|
||||
};
|
||||
ConstructorFragment.isConstructorFragment = function (value) {
|
||||
return (value && value._isFragment && value.type === "constructor");
|
||||
};
|
||||
return ConstructorFragment;
|
||||
}(Fragment));
|
||||
exports.ConstructorFragment = ConstructorFragment;
|
||||
var FunctionFragment = /** @class */ (function (_super) {
|
||||
__extends(FunctionFragment, _super);
|
||||
function FunctionFragment() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
FunctionFragment.prototype.format = function (format) {
|
||||
if (!format) {
|
||||
format = exports.FormatTypes.sighash;
|
||||
}
|
||||
if (!exports.FormatTypes[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === exports.FormatTypes.json) {
|
||||
return JSON.stringify({
|
||||
type: "function",
|
||||
name: this.name,
|
||||
constant: this.constant,
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payble: this.payable,
|
||||
gas: (this.gas ? this.gas.toNumber() : undefined),
|
||||
inputs: this.inputs.map(function (input) { return JSON.parse(input.format(format)); }),
|
||||
ouputs: this.outputs.map(function (output) { return JSON.parse(output.format(format)); }),
|
||||
});
|
||||
}
|
||||
var result = "";
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
result += "function ";
|
||||
}
|
||||
result += this.name + "(" + this.inputs.map(function (input) { return input.format(format); }).join((format === exports.FormatTypes.full) ? ", " : ",") + ") ";
|
||||
if (format !== exports.FormatTypes.sighash) {
|
||||
if (this.stateMutability) {
|
||||
if (this.stateMutability !== "nonpayable") {
|
||||
result += (this.stateMutability + " ");
|
||||
}
|
||||
}
|
||||
else if (this.constant) {
|
||||
result += "view ";
|
||||
}
|
||||
if (this.outputs && this.outputs.length) {
|
||||
result += "returns (" + this.outputs.map(function (output) { return output.format(format); }).join(", ") + ") ";
|
||||
}
|
||||
if (this.gas != null) {
|
||||
result += "@" + this.gas.toString() + " ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
};
|
||||
FunctionFragment.from = function (value) {
|
||||
if (typeof (value) === "string") {
|
||||
return FunctionFragment.fromString(value);
|
||||
}
|
||||
return FunctionFragment.fromObject(value);
|
||||
};
|
||||
FunctionFragment.fromObject = function (value) {
|
||||
if (FunctionFragment.isFunctionFragment(value)) {
|
||||
return value;
|
||||
}
|
||||
if (value.type !== "function") {
|
||||
logger.throwArgumentError("invalid function object", "value", value);
|
||||
}
|
||||
var state = verifyState(value);
|
||||
var params = {
|
||||
type: value.type,
|
||||
name: verifyIdentifier(value.name),
|
||||
constant: state.constant,
|
||||
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
|
||||
outputs: (value.outputs ? value.outputs.map(ParamType.fromObject) : []),
|
||||
payable: state.payable,
|
||||
stateMutability: state.stateMutability,
|
||||
gas: (value.gas ? bignumber_1.BigNumber.from(value.gas) : null)
|
||||
};
|
||||
return new FunctionFragment(_constructorGuard, params);
|
||||
};
|
||||
FunctionFragment.fromString = function (value) {
|
||||
var params = { type: "function" };
|
||||
value = parseGas(value, params);
|
||||
var comps = value.split(" returns ");
|
||||
if (comps.length > 2) {
|
||||
logger.throwArgumentError("invalid function string", "value", value);
|
||||
}
|
||||
var parens = comps[0].match(regexParen);
|
||||
if (!parens) {
|
||||
logger.throwArgumentError("invalid function signature", "value", value);
|
||||
}
|
||||
params.name = parens[1].trim();
|
||||
if (params.name) {
|
||||
verifyIdentifier(params.name);
|
||||
}
|
||||
params.inputs = parseParams(parens[2], false);
|
||||
parseModifiers(parens[3].trim(), params);
|
||||
// We have outputs
|
||||
if (comps.length > 1) {
|
||||
var returns = comps[1].match(regexParen);
|
||||
if (returns[1].trim() != "" || returns[3].trim() != "") {
|
||||
logger.throwArgumentError("unexpected tokens", "value", value);
|
||||
}
|
||||
params.outputs = parseParams(returns[2], false);
|
||||
}
|
||||
else {
|
||||
params.outputs = [];
|
||||
}
|
||||
return FunctionFragment.fromObject(params);
|
||||
};
|
||||
FunctionFragment.isFunctionFragment = function (value) {
|
||||
return (value && value._isFragment && value.type === "function");
|
||||
};
|
||||
return FunctionFragment;
|
||||
}(ConstructorFragment));
|
||||
exports.FunctionFragment = FunctionFragment;
|
||||
//export class ErrorFragment extends Fragment {
|
||||
//}
|
||||
//export class StructFragment extends Fragment {
|
||||
//}
|
||||
function verifyType(type) {
|
||||
// These need to be transformed to their full description
|
||||
if (type.match(/^uint($|[^1-9])/)) {
|
||||
type = "uint256" + type.substring(4);
|
||||
}
|
||||
else if (type.match(/^int($|[^1-9])/)) {
|
||||
type = "int256" + type.substring(3);
|
||||
}
|
||||
// @TODO: more verification
|
||||
return type;
|
||||
}
|
||||
var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
|
||||
function verifyIdentifier(value) {
|
||||
if (!value || !value.match(regexIdentifier)) {
|
||||
logger.throwArgumentError("invalid identifier \"" + value + "\"", "value", value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
var regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
|
||||
function splitNesting(value) {
|
||||
value = value.trim();
|
||||
var result = [];
|
||||
var accum = "";
|
||||
var depth = 0;
|
||||
for (var offset = 0; offset < value.length; offset++) {
|
||||
var c = value[offset];
|
||||
if (c === "," && depth === 0) {
|
||||
result.push(accum);
|
||||
accum = "";
|
||||
}
|
||||
else {
|
||||
accum += c;
|
||||
if (c === "(") {
|
||||
depth++;
|
||||
}
|
||||
else if (c === ")") {
|
||||
depth--;
|
||||
if (depth === -1) {
|
||||
logger.throwArgumentError("unbalanced parenthesis", "value", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accum) {
|
||||
result.push(accum);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fragments_1 = require("./fragments");
|
||||
exports.ConstructorFragment = fragments_1.ConstructorFragment;
|
||||
exports.EventFragment = fragments_1.EventFragment;
|
||||
exports.FormatTypes = fragments_1.FormatTypes;
|
||||
exports.Fragment = fragments_1.Fragment;
|
||||
exports.FunctionFragment = fragments_1.FunctionFragment;
|
||||
exports.ParamType = fragments_1.ParamType;
|
||||
var abi_coder_1 = require("./abi-coder");
|
||||
exports.AbiCoder = abi_coder_1.AbiCoder;
|
||||
exports.defaultAbiCoder = abi_coder_1.defaultAbiCoder;
|
||||
var interface_1 = require("./interface");
|
||||
exports.checkResultErrors = interface_1.checkResultErrors;
|
||||
exports.Indexed = interface_1.Indexed;
|
||||
exports.Interface = interface_1.Interface;
|
||||
exports.LogDescription = interface_1.LogDescription;
|
||||
exports.TransactionDescription = interface_1.TransactionDescription;
|
||||
+533
@@ -0,0 +1,533 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var address_1 = require("@ethersproject/address");
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var hash_1 = require("@ethersproject/hash");
|
||||
var keccak256_1 = require("@ethersproject/keccak256");
|
||||
var properties_1 = require("@ethersproject/properties");
|
||||
var abi_coder_1 = require("./abi-coder");
|
||||
var abstract_coder_1 = require("./coders/abstract-coder");
|
||||
exports.checkResultErrors = abstract_coder_1.checkResultErrors;
|
||||
var fragments_1 = require("./fragments");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
var LogDescription = /** @class */ (function (_super) {
|
||||
__extends(LogDescription, _super);
|
||||
function LogDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return LogDescription;
|
||||
}(properties_1.Description));
|
||||
exports.LogDescription = LogDescription;
|
||||
var TransactionDescription = /** @class */ (function (_super) {
|
||||
__extends(TransactionDescription, _super);
|
||||
function TransactionDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return TransactionDescription;
|
||||
}(properties_1.Description));
|
||||
exports.TransactionDescription = TransactionDescription;
|
||||
var Indexed = /** @class */ (function (_super) {
|
||||
__extends(Indexed, _super);
|
||||
function Indexed() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
Indexed.isIndexed = function (value) {
|
||||
return !!(value && value._isIndexed);
|
||||
};
|
||||
return Indexed;
|
||||
}(properties_1.Description));
|
||||
exports.Indexed = Indexed;
|
||||
function wrapAccessError(property, error) {
|
||||
var wrap = new Error("deferred error during ABI decoding triggered accessing " + property);
|
||||
wrap.error = error;
|
||||
return wrap;
|
||||
}
|
||||
function checkNames(fragment, type, params) {
|
||||
params.reduce(function (accum, param) {
|
||||
if (param.name) {
|
||||
if (accum[param.name]) {
|
||||
logger.throwArgumentError("duplicate " + type + " parameter " + JSON.stringify(param.name) + " in " + fragment.format("full"), "fragment", fragment);
|
||||
}
|
||||
accum[param.name] = true;
|
||||
}
|
||||
return accum;
|
||||
}, {});
|
||||
}
|
||||
var Interface = /** @class */ (function () {
|
||||
function Interface(fragments) {
|
||||
var _newTarget = this.constructor;
|
||||
var _this = this;
|
||||
logger.checkNew(_newTarget, Interface);
|
||||
var abi = [];
|
||||
if (typeof (fragments) === "string") {
|
||||
abi = JSON.parse(fragments);
|
||||
}
|
||||
else {
|
||||
abi = fragments;
|
||||
}
|
||||
properties_1.defineReadOnly(this, "fragments", abi.map(function (fragment) {
|
||||
return fragments_1.Fragment.from(fragment);
|
||||
}).filter(function (fragment) { return (fragment != null); }));
|
||||
properties_1.defineReadOnly(this, "_abiCoder", properties_1.getStatic((_newTarget), "getAbiCoder")());
|
||||
properties_1.defineReadOnly(this, "functions", {});
|
||||
properties_1.defineReadOnly(this, "errors", {});
|
||||
properties_1.defineReadOnly(this, "events", {});
|
||||
properties_1.defineReadOnly(this, "structs", {});
|
||||
// Add all fragments by their signature
|
||||
this.fragments.forEach(function (fragment) {
|
||||
var bucket = null;
|
||||
switch (fragment.type) {
|
||||
case "constructor":
|
||||
if (_this.deploy) {
|
||||
logger.warn("duplicate definition - constructor");
|
||||
return;
|
||||
}
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
properties_1.defineReadOnly(_this, "deploy", fragment);
|
||||
return;
|
||||
case "function":
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
checkNames(fragment, "output", fragment.outputs);
|
||||
bucket = _this.functions;
|
||||
break;
|
||||
case "event":
|
||||
checkNames(fragment, "input", fragment.inputs);
|
||||
bucket = _this.events;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
var signature = fragment.format();
|
||||
if (bucket[signature]) {
|
||||
logger.warn("duplicate definition - " + signature);
|
||||
return;
|
||||
}
|
||||
bucket[signature] = fragment;
|
||||
});
|
||||
// If we do not have a constructor add a default
|
||||
if (!this.deploy) {
|
||||
properties_1.defineReadOnly(this, "deploy", fragments_1.ConstructorFragment.from({
|
||||
payable: false,
|
||||
type: "constructor"
|
||||
}));
|
||||
}
|
||||
properties_1.defineReadOnly(this, "_isInterface", true);
|
||||
}
|
||||
Interface.prototype.format = function (format) {
|
||||
if (!format) {
|
||||
format = fragments_1.FormatTypes.full;
|
||||
}
|
||||
if (format === fragments_1.FormatTypes.sighash) {
|
||||
logger.throwArgumentError("interface does not support formatting sighash", "format", format);
|
||||
}
|
||||
var abi = this.fragments.map(function (fragment) { return fragment.format(format); });
|
||||
// We need to re-bundle the JSON fragments a bit
|
||||
if (format === fragments_1.FormatTypes.json) {
|
||||
return JSON.stringify(abi.map(function (j) { return JSON.parse(j); }));
|
||||
}
|
||||
return abi;
|
||||
};
|
||||
// Sub-classes can override these to handle other blockchains
|
||||
Interface.getAbiCoder = function () {
|
||||
return abi_coder_1.defaultAbiCoder;
|
||||
};
|
||||
Interface.getAddress = function (address) {
|
||||
return address_1.getAddress(address);
|
||||
};
|
||||
Interface.getSighash = function (functionFragment) {
|
||||
return bytes_1.hexDataSlice(hash_1.id(functionFragment.format()), 0, 4);
|
||||
};
|
||||
Interface.getEventTopic = function (eventFragment) {
|
||||
return hash_1.id(eventFragment.format());
|
||||
};
|
||||
// Find a function definition by any means necessary (unless it is ambiguous)
|
||||
Interface.prototype.getFunction = function (nameOrSignatureOrSighash) {
|
||||
if (bytes_1.isHexString(nameOrSignatureOrSighash)) {
|
||||
for (var name_1 in this.functions) {
|
||||
if (nameOrSignatureOrSighash === this.getSighash(name_1)) {
|
||||
return this.functions[name_1];
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching function", "sighash", nameOrSignatureOrSighash);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (nameOrSignatureOrSighash.indexOf("(") === -1) {
|
||||
var name_2 = nameOrSignatureOrSighash.trim();
|
||||
var matching = Object.keys(this.functions).filter(function (f) { return (f.split("(" /* fix:) */)[0] === name_2); });
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching function", "name", name_2);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
logger.throwArgumentError("multiple matching functions", "name", name_2);
|
||||
}
|
||||
return this.functions[matching[0]];
|
||||
}
|
||||
// Normlize the signature and lookup the function
|
||||
var result = this.functions[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
|
||||
if (!result) {
|
||||
logger.throwArgumentError("no matching function", "signature", nameOrSignatureOrSighash);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Find an event definition by any means necessary (unless it is ambiguous)
|
||||
Interface.prototype.getEvent = function (nameOrSignatureOrTopic) {
|
||||
if (bytes_1.isHexString(nameOrSignatureOrTopic)) {
|
||||
var topichash = nameOrSignatureOrTopic.toLowerCase();
|
||||
for (var name_3 in this.events) {
|
||||
if (topichash === this.getEventTopic(name_3)) {
|
||||
return this.events[name_3];
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching event", "topichash", topichash);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (nameOrSignatureOrTopic.indexOf("(") === -1) {
|
||||
var name_4 = nameOrSignatureOrTopic.trim();
|
||||
var matching = Object.keys(this.events).filter(function (f) { return (f.split("(" /* fix:) */)[0] === name_4); });
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching event", "name", name_4);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
logger.throwArgumentError("multiple matching events", "name", name_4);
|
||||
}
|
||||
return this.events[matching[0]];
|
||||
}
|
||||
// Normlize the signature and lookup the function
|
||||
var result = this.events[fragments_1.EventFragment.fromString(nameOrSignatureOrTopic).format()];
|
||||
if (!result) {
|
||||
logger.throwArgumentError("no matching event", "signature", nameOrSignatureOrTopic);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Get the sighash (the bytes4 selector) used by Solidity to identify a function
|
||||
Interface.prototype.getSighash = function (functionFragment) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return properties_1.getStatic(this.constructor, "getSighash")(functionFragment);
|
||||
};
|
||||
// Get the topic (the bytes32 hash) used by Solidity to identify an event
|
||||
Interface.prototype.getEventTopic = function (eventFragment) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
return properties_1.getStatic(this.constructor, "getEventTopic")(eventFragment);
|
||||
};
|
||||
Interface.prototype._decodeParams = function (params, data) {
|
||||
return this._abiCoder.decode(params, data);
|
||||
};
|
||||
Interface.prototype._encodeParams = function (params, values) {
|
||||
return this._abiCoder.encode(params, values);
|
||||
};
|
||||
Interface.prototype.encodeDeploy = function (values) {
|
||||
return this._encodeParams(this.deploy.inputs, values || []);
|
||||
};
|
||||
// Decode the data for a function call (e.g. tx.data)
|
||||
Interface.prototype.decodeFunctionData = function (functionFragment, data) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
var bytes = bytes_1.arrayify(data);
|
||||
if (bytes_1.hexlify(bytes.slice(0, 4)) !== this.getSighash(functionFragment)) {
|
||||
logger.throwArgumentError("data signature does not match function " + functionFragment.name + ".", "data", bytes_1.hexlify(bytes));
|
||||
}
|
||||
return this._decodeParams(functionFragment.inputs, bytes.slice(4));
|
||||
};
|
||||
// Encode the data for a function call (e.g. tx.data)
|
||||
Interface.prototype.encodeFunctionData = function (functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return bytes_1.hexlify(bytes_1.concat([
|
||||
this.getSighash(functionFragment),
|
||||
this._encodeParams(functionFragment.inputs, values || [])
|
||||
]));
|
||||
};
|
||||
// Decode the result from a function call (e.g. from eth_call)
|
||||
Interface.prototype.decodeFunctionResult = function (functionFragment, data) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
var bytes = bytes_1.arrayify(data);
|
||||
var reason = null;
|
||||
var errorSignature = null;
|
||||
switch (bytes.length % this._abiCoder._getWordSize()) {
|
||||
case 0:
|
||||
try {
|
||||
return this._abiCoder.decode(functionFragment.outputs, bytes);
|
||||
}
|
||||
catch (error) { }
|
||||
break;
|
||||
case 4:
|
||||
if (bytes_1.hexlify(bytes.slice(0, 4)) === "0x08c379a0") {
|
||||
errorSignature = "Error(string)";
|
||||
reason = this._abiCoder.decode(["string"], bytes.slice(4))[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
return logger.throwError("call revert exception", logger_1.Logger.errors.CALL_EXCEPTION, {
|
||||
method: functionFragment.format(),
|
||||
errorSignature: errorSignature,
|
||||
errorArgs: [reason],
|
||||
reason: reason
|
||||
});
|
||||
};
|
||||
// Encode the result for a function call (e.g. for eth_call)
|
||||
Interface.prototype.encodeFunctionResult = function (functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return bytes_1.hexlify(this._abiCoder.encode(functionFragment.outputs, values || []));
|
||||
};
|
||||
// Create the filter for the event with search criteria (e.g. for eth_filterLog)
|
||||
Interface.prototype.encodeFilterTopics = function (eventFragment, values) {
|
||||
var _this = this;
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (values.length > eventFragment.inputs.length) {
|
||||
logger.throwError("too many arguments for " + eventFragment.format(), logger_1.Logger.errors.UNEXPECTED_ARGUMENT, {
|
||||
argument: "values",
|
||||
value: values
|
||||
});
|
||||
}
|
||||
var topics = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
var encodeTopic = function (param, value) {
|
||||
if (param.type === "string") {
|
||||
return hash_1.id(value);
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
return keccak256_1.keccak256(bytes_1.hexlify(value));
|
||||
}
|
||||
// Check addresses are valid
|
||||
if (param.type === "address") {
|
||||
_this._abiCoder.encode(["address"], [value]);
|
||||
}
|
||||
return bytes_1.hexZeroPad(bytes_1.hexlify(value), 32);
|
||||
};
|
||||
values.forEach(function (value, index) {
|
||||
var param = eventFragment.inputs[index];
|
||||
if (!param.indexed) {
|
||||
if (value != null) {
|
||||
logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
topics.push(null);
|
||||
}
|
||||
else if (param.baseType === "array" || param.baseType === "tuple") {
|
||||
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
topics.push(value.map(function (value) { return encodeTopic(param, value); }));
|
||||
}
|
||||
else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
// Trim off trailing nulls
|
||||
while (topics.length && topics[topics.length - 1] === null) {
|
||||
topics.pop();
|
||||
}
|
||||
return topics;
|
||||
};
|
||||
Interface.prototype.encodeEventLog = function (eventFragment, values) {
|
||||
var _this = this;
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
var topics = [];
|
||||
var dataTypes = [];
|
||||
var dataValues = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
if (values.length !== eventFragment.inputs.length) {
|
||||
logger.throwArgumentError("event arguments/values mismatch", "values", values);
|
||||
}
|
||||
eventFragment.inputs.forEach(function (param, index) {
|
||||
var value = values[index];
|
||||
if (param.indexed) {
|
||||
if (param.type === "string") {
|
||||
topics.push(hash_1.id(value));
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
topics.push(keccak256_1.keccak256(value));
|
||||
}
|
||||
else if (param.baseType === "tuple" || param.baseType === "array") {
|
||||
// @TOOD
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
else {
|
||||
topics.push(_this._abiCoder.encode([param.type], [value]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataTypes.push(param);
|
||||
dataValues.push(value);
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: this._abiCoder.encode(dataTypes, dataValues),
|
||||
topics: topics
|
||||
};
|
||||
};
|
||||
// Decode a filter for the event and the search criteria
|
||||
Interface.prototype.decodeEventLog = function (eventFragment, data, topics) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (topics != null && !eventFragment.anonymous) {
|
||||
var topicHash = this.getEventTopic(eventFragment);
|
||||
if (!bytes_1.isHexString(topics[0], 32) || topics[0].toLowerCase() !== topicHash) {
|
||||
logger.throwError("fragment/topic mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "topics[0]", expected: topicHash, value: topics[0] });
|
||||
}
|
||||
topics = topics.slice(1);
|
||||
}
|
||||
var indexed = [];
|
||||
var nonIndexed = [];
|
||||
var dynamic = [];
|
||||
eventFragment.inputs.forEach(function (param, index) {
|
||||
if (param.indexed) {
|
||||
if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
|
||||
indexed.push(fragments_1.ParamType.fromObject({ type: "bytes32", name: param.name }));
|
||||
dynamic.push(true);
|
||||
}
|
||||
else {
|
||||
indexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nonIndexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
});
|
||||
var resultIndexed = (topics != null) ? this._abiCoder.decode(indexed, bytes_1.concat(topics)) : null;
|
||||
var resultNonIndexed = this._abiCoder.decode(nonIndexed, data);
|
||||
var result = [];
|
||||
var nonIndexedIndex = 0, indexedIndex = 0;
|
||||
eventFragment.inputs.forEach(function (param, index) {
|
||||
if (param.indexed) {
|
||||
if (resultIndexed == null) {
|
||||
result[index] = new Indexed({ _isIndexed: true, hash: null });
|
||||
}
|
||||
else if (dynamic[index]) {
|
||||
result[index] = new Indexed({ _isIndexed: true, hash: resultIndexed[indexedIndex++] });
|
||||
}
|
||||
else {
|
||||
try {
|
||||
result[index] = resultIndexed[indexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
result[index] = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
result[index] = resultNonIndexed[nonIndexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
result[index] = error;
|
||||
}
|
||||
}
|
||||
// Add the keyword argument if named and safe
|
||||
if (param.name && result[param.name] == null) {
|
||||
var value_1 = result[index];
|
||||
// Make error named values throw on access
|
||||
if (value_1 instanceof Error) {
|
||||
Object.defineProperty(result, param.name, {
|
||||
get: function () { throw wrapAccessError("property " + JSON.stringify(param.name), value_1); }
|
||||
});
|
||||
}
|
||||
else {
|
||||
result[param.name] = value_1;
|
||||
}
|
||||
}
|
||||
});
|
||||
var _loop_1 = function (i) {
|
||||
var value = result[i];
|
||||
if (value instanceof Error) {
|
||||
Object.defineProperty(result, i, {
|
||||
get: function () { throw wrapAccessError("index " + i, value); }
|
||||
});
|
||||
}
|
||||
};
|
||||
// Make all error indexed values throw on access
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return Object.freeze(result);
|
||||
};
|
||||
// Given a transaction, find the matching function fragment (if any) and
|
||||
// determine all its properties and call parameters
|
||||
Interface.prototype.parseTransaction = function (tx) {
|
||||
var fragment = this.getFunction(tx.data.substring(0, 10).toLowerCase());
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
return new TransactionDescription({
|
||||
args: this._abiCoder.decode(fragment.inputs, "0x" + tx.data.substring(10)),
|
||||
functionFragment: fragment,
|
||||
name: fragment.name,
|
||||
signature: fragment.format(),
|
||||
sighash: this.getSighash(fragment),
|
||||
value: bignumber_1.BigNumber.from(tx.value || "0"),
|
||||
});
|
||||
};
|
||||
// Given an event log, find the matching event fragment (if any) and
|
||||
// determine all its properties and values
|
||||
Interface.prototype.parseLog = function (log) {
|
||||
var fragment = this.getEvent(log.topics[0]);
|
||||
if (!fragment || fragment.anonymous) {
|
||||
return null;
|
||||
}
|
||||
// @TODO: If anonymous, and the only method, and the input count matches, should we parse?
|
||||
// Probably not, because just because it is the only event in the ABI does
|
||||
// not mean we have the full ABI; maybe jsut a fragment?
|
||||
return new LogDescription({
|
||||
eventFragment: fragment,
|
||||
name: fragment.name,
|
||||
signature: fragment.format(),
|
||||
topic: this.getEventTopic(fragment),
|
||||
args: this.decodeEventLog(fragment, log.data, log.topics)
|
||||
});
|
||||
};
|
||||
/*
|
||||
static from(value: Array<Fragment | string | JsonAbi> | string | Interface) {
|
||||
if (Interface.isInterface(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof(value) === "string") {
|
||||
return new Interface(JSON.parse(value));
|
||||
}
|
||||
return new Interface(value);
|
||||
}
|
||||
*/
|
||||
Interface.isInterface = function (value) {
|
||||
return !!(value && value._isInterface);
|
||||
};
|
||||
return Interface;
|
||||
}());
|
||||
exports.Interface = Interface;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"author": "Richard Moore <me@ricmoo.com>",
|
||||
"dependencies": {
|
||||
"@ethersproject/address": ">=5.0.0-beta.128",
|
||||
"@ethersproject/bignumber": ">=5.0.0-beta.130",
|
||||
"@ethersproject/bytes": ">=5.0.0-beta.129",
|
||||
"@ethersproject/constants": ">=5.0.0-beta.128",
|
||||
"@ethersproject/hash": ">=5.0.0-beta.128",
|
||||
"@ethersproject/keccak256": ">=5.0.0-beta.127",
|
||||
"@ethersproject/logger": ">=5.0.0-beta.129",
|
||||
"@ethersproject/properties": ">=5.0.0-beta.131",
|
||||
"@ethersproject/strings": ">=5.0.0-beta.130"
|
||||
},
|
||||
"description": "Utilities and Classes for parsing, formatting and managing Ethereum ABIs.",
|
||||
"ethereum": "donations.ethers.eth",
|
||||
"keywords": [
|
||||
"Ethereum",
|
||||
"ethers"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib.esm/index.js",
|
||||
"name": "@ethersproject/abi",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ethers-io/ethers.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0x7f866470aabd8bbe47af1ff527fedbd86445cbfcd3bbf340d34c96b38b8e8606",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.0-beta.153"
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.0-beta.153.tgz"
|
||||
,"_integrity": "sha512-aXweZ1Z7vMNzJdLpR1CZUAIgnwjrZeUSvN9syCwlBaEBUFJmFY+HHnfuTI5vIhVs/mRkfJVrbEyl51JZQqyjAg=="
|
||||
,"_from": "@ethersproject/abi@5.0.0-beta.153"
|
||||
}
|
||||
Reference in new issue
Block a user