truffle
Version:
Truffle - Simple development framework for Ethereum
1,263 lines (1,217 loc) • 139 kB
JavaScript
#!/usr/bin/env node
"use strict";
exports.id = 4957;
exports.ids = [4957];
exports.modules = {
/***/ 51708:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ R: () => (/* binding */ AbiCoder)
/* harmony export */ });
/* unused harmony export defaultAbiCoder */
/* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(46366);
/* harmony import */ var _ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33654);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(95851);
/* harmony import */ var _coders_abstract_coder__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(61184);
/* harmony import */ var _coders_address__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(33424);
/* harmony import */ var _coders_array__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(69019);
/* harmony import */ var _coders_boolean__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(90179);
/* harmony import */ var _coders_bytes__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(68271);
/* harmony import */ var _coders_fixed_bytes__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(89393);
/* harmony import */ var _coders_null__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(12645);
/* harmony import */ var _coders_number__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(80356);
/* harmony import */ var _coders_string__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(47856);
/* harmony import */ var _coders_tuple__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(18984);
/* harmony import */ var _fragments__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(11388);
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
class AbiCoder {
constructor(coerceFunc) {
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "coerceFunc", coerceFunc || null);
}
_getCoder(param) {
switch (param.baseType) {
case "address":
return new _coders_address__WEBPACK_IMPORTED_MODULE_3__/* .AddressCoder */ .w(param.name);
case "bool":
return new _coders_boolean__WEBPACK_IMPORTED_MODULE_4__/* .BooleanCoder */ .Y(param.name);
case "string":
return new _coders_string__WEBPACK_IMPORTED_MODULE_5__/* .StringCoder */ .i(param.name);
case "bytes":
return new _coders_bytes__WEBPACK_IMPORTED_MODULE_6__/* .BytesCoder */ .d(param.name);
case "array":
return new _coders_array__WEBPACK_IMPORTED_MODULE_7__/* .ArrayCoder */ .$b(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
case "tuple":
return new _coders_tuple__WEBPACK_IMPORTED_MODULE_8__/* .TupleCoder */ .a((param.components || []).map((component) => {
return this._getCoder(component);
}), param.name);
case "":
return new _coders_null__WEBPACK_IMPORTED_MODULE_9__/* .NullCoder */ .Q(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 _coders_number__WEBPACK_IMPORTED_MODULE_10__/* .NumberCoder */ .e(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 _coders_fixed_bytes__WEBPACK_IMPORTED_MODULE_11__/* .FixedBytesCoder */ .Y(size, param.name);
}
return logger.throwArgumentError("invalid type", "type", param.type);
}
_getWordSize() { return 32; }
_getReader(data, allowLoose) {
return new _coders_abstract_coder__WEBPACK_IMPORTED_MODULE_12__/* .Reader */ .Ej(data, this._getWordSize(), this.coerceFunc, allowLoose);
}
_getWriter() {
return new _coders_abstract_coder__WEBPACK_IMPORTED_MODULE_12__/* .Writer */ .QV(this._getWordSize());
}
getDefaultValue(types) {
const coders = types.map((type) => this._getCoder(_fragments__WEBPACK_IMPORTED_MODULE_13__/* .ParamType */ ._R.from(type)));
const coder = new _coders_tuple__WEBPACK_IMPORTED_MODULE_8__/* .TupleCoder */ .a(coders, "_");
return coder.defaultValue();
}
encode(types, values) {
if (types.length !== values.length) {
logger.throwError("types/values length mismatch", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.INVALID_ARGUMENT, {
count: { types: types.length, values: values.length },
value: { types: types, values: values }
});
}
const coders = types.map((type) => this._getCoder(_fragments__WEBPACK_IMPORTED_MODULE_13__/* .ParamType */ ._R.from(type)));
const coder = (new _coders_tuple__WEBPACK_IMPORTED_MODULE_8__/* .TupleCoder */ .a(coders, "_"));
const writer = this._getWriter();
coder.encode(writer, values);
return writer.data;
}
decode(types, data, loose) {
const coders = types.map((type) => this._getCoder(_fragments__WEBPACK_IMPORTED_MODULE_13__/* .ParamType */ ._R.from(type)));
const coder = new _coders_tuple__WEBPACK_IMPORTED_MODULE_8__/* .TupleCoder */ .a(coders, "_");
return coder.decode(this._getReader((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_14__/* .arrayify */ .lE)(data), loose));
}
}
const defaultAbiCoder = new AbiCoder();
//# sourceMappingURL=abi-coder.js.map
/***/ }),
/***/ 61184:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Ej: () => (/* binding */ Reader),
/* harmony export */ QV: () => (/* binding */ Writer),
/* harmony export */ XI: () => (/* binding */ Coder)
/* harmony export */ });
/* unused harmony export checkResultErrors */
/* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(46366);
/* harmony import */ var _ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2593);
/* harmony import */ var _ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33654);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(95851);
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
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;
}
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);
}
}
class Writer {
constructor(wordSize) {
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "wordSize", wordSize || 32);
this._data = [];
this._dataLength = 0;
this._padding = new Uint8Array(wordSize);
}
get data() {
return (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexConcat */ .xs)(this._data);
}
get length() { return this._dataLength; }
_writeData(data) {
this._data.push(data);
this._dataLength += data.length;
return data.length;
}
appendWriter(writer) {
return this._writeData((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .concat */ .zo)(writer._data));
}
// Arrayish items; padded on the right to wordSize
writeBytes(value) {
let bytes = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(value);
const paddingOffset = bytes.length % this.wordSize;
if (paddingOffset) {
bytes = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .concat */ .zo)([bytes, this._padding.slice(paddingOffset)]);
}
return this._writeData(bytes);
}
_getValue(value) {
let bytes = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* .BigNumber */ .O$.from(value));
if (bytes.length > this.wordSize) {
logger.throwError("value out-of-bounds", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.BUFFER_OVERRUN, {
length: this.wordSize,
offset: bytes.length
});
}
if (bytes.length % this.wordSize) {
bytes = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .concat */ .zo)([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() {
const offset = this._data.length;
this._data.push(this._padding);
this._dataLength += this.wordSize;
return (value) => {
this._data[offset] = this._getValue(value);
};
}
}
class Reader {
constructor(data, wordSize, coerceFunc, allowLoose) {
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "_data", (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(data));
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "wordSize", wordSize || 32);
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "_coerceFunc", coerceFunc);
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(this, "allowLoose", allowLoose);
this._offset = 0;
}
get data() { return (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexlify */ .Dv)(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, loose) {
let alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
if (this._offset + alignedLength > this._data.length) {
if (this.allowLoose && loose && this._offset + length <= this._data.length) {
alignedLength = length;
}
else {
logger.throwError("data out-of-bounds", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.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, this.allowLoose);
}
readBytes(length, loose) {
let bytes = this._peekBytes(0, length, !!loose);
this._offset += bytes.length;
// @TODO: Make sure the length..end bytes are all 0?
return bytes.slice(0, length);
}
readValue() {
return _ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* .BigNumber */ .O$.from(this.readBytes(this.wordSize));
}
}
//# sourceMappingURL=abstract-coder.js.map
/***/ }),
/***/ 11388:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ _R: () => (/* binding */ ParamType)
/* harmony export */ });
/* unused harmony exports FormatTypes, Fragment, EventFragment, ConstructorFragment, FunctionFragment, ErrorFragment */
/* harmony import */ var _ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33654);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(95851);
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
;
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) {
(0,_ethersproject_properties__WEBPACK_IMPORTED_MODULE_2__/* .defineReadOnly */ .zG)(object, key, params[key]);
}
}
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-Readable with nice spacing, including all names
full: "full",
// JSON-format a la Solidity
json: "json"
});
const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
class ParamType {
constructor(constructorGuard, params) {
if (constructorGuard !== _constructorGuard) {
logger.throwError("use fromString", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.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, address 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));
}
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 "error":
return ErrorFragment.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());
}
else if (value.split(" ")[0] === "error") {
return ErrorFragment.fromString(value.substring(5).trim());
}
return logger.throwArgumentError("unsupported fragment", "value", value);
}
static isFragment(value) {
return !!(value && value._isFragment);
}
}
class EventFragment extends (/* unused pure expression or super */ null && (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 "nonpayable":
params.payable = false;
params.stateMutability = "nonpayable";
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;
}
class ConstructorFragment extends (/* unused pure expression or super */ null && (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),
payable: 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");
}
}
class FunctionFragment extends (/* unused pure expression or super */ null && (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),
payable: this.payable,
gas: (this.gas ? this.gas.toNumber() : undefined),
inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
outputs: 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 StructFragment extends Fragment {
//}
function checkForbidden(fragment) {
const sig = fragment.format();
if (sig === "Error(string)" || sig === "Panic(uint256)") {
logger.throwArgumentError(`cannot specify user defined ${sig} error`, "fragment", fragment);
}
return fragment;
}
class ErrorFragment extends (/* unused pure expression or super */ null && (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: "error",
name: this.name,
inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
});
}
let result = "";
if (format !== FormatTypes.sighash) {
result += "error ";
}
result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
return result.trim();
}
static from(value) {
if (typeof (value) === "string") {
return ErrorFragment.fromString(value);
}
return ErrorFragment.fromObject(value);
}
static fromObject(value) {
if (ErrorFragment.isErrorFragment(value)) {
return value;
}
if (value.type !== "error") {
logger.throwArgumentError("invalid error object", "value", value);
}
const params = {
type: value.type,
name: verifyIdentifier(value.name),
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : [])
};
return checkForbidden(new ErrorFragment(_constructorGuard, params));
}
static fromString(value) {
let params = { type: "error" };
let parens = value.match(regexParen);
if (!parens) {
logger.throwArgumentError("invalid error signature", "value", value);
}
params.name = parens[1].trim();
if (params.name) {
verifyIdentifier(params.name);
}
params.inputs = parseParams(parens[2], false);
return checkForbidden(ErrorFragment.fromObject(params));
}
static isErrorFragment(value) {
return (value && value._isFragment && value.type === "error");
}
}
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;
}
// See: https://github.com/ethereum/solidity/blob/1f8f1a3db93a548d0555e3e14cfc55a10e25b60e/docs/grammar/SolidityLexer.g4#L234
const regexIdentifier = (/* unused pure expression or super */ null && (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 = (/* unused pure expression or super */ null && (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;
}
//# sourceMappingURL=fragments.js.map
/***/ }),
/***/ 92936:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ getAddress: () => (/* binding */ getAddress)
/* harmony export */ });
/* unused harmony exports isAddress, getIcapAddress, getContractAddress, getCreate2Address */
/* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(46366);
/* harmony import */ var _ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2593);
/* harmony import */ var _ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(38197);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6915);
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
function getChecksumAddress(address) {
if (!(0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .isHexString */ .A7)(address, 20)) {
logger.throwArgumentError("invalid address", "address", address);
}
address = address.toLowerCase();
const chars = address.substring(2).split("");
const expanded = new Uint8Array(40);
for (let i = 0; i < 40; i++) {
expanded[i] = chars[i].charCodeAt(0);
}
const hashed = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)(expanded));
for (let i = 0; i < 40; i += 2) {
if ((hashed[i >> 1] >> 4) >= 8) {
chars[i] = chars[i].toUpperCase();
}
if ((hashed[i >> 1] & 0x0f) >= 8) {
chars[i + 1] = chars[i + 1].toUpperCase();
}
}
return "0x" + chars.join("");
}
// Shims for environments that are missing some required constants and functions
const MAX_SAFE_INTEGER = 0x1fffffffffffff;
function log10(x) {
if (Math.log10) {
return Math.log10(x);
}
return Math.log(x) / Math.LN10;
}
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
// Create lookup table
const ibanLookup = {};
for (let i = 0; i < 10; i++) {
ibanLookup[String(i)] = String(i);
}
for (let i = 0; i < 26; i++) {
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
}
// How many decimal digits can we process? (for 64-bit float, this is 15)
const safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
function ibanChecksum(address) {
address = address.toUpperCase();
address = address.substring(4) + address.substring(0, 2) + "00";
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
// Javascript can handle integers safely up to 15 (decimal) digits
while (expanded.length >= safeDigits) {
let block = expanded.substring(0, safeDigits);
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
}
let checksum = String(98 - (parseInt(expanded, 10) % 97));
while (checksum.length < 2) {
checksum = "0" + checksum;
}
return checksum;
}
;
function getAddress(address) {
let result = null;
if (typeof (address) !== "string") {
logger.throwArgumentError("invalid address", "address", address);
}
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
// Missing the 0x prefix
if (address.substring(0, 2) !== "0x") {
address = "0x" + address;
}
result = getChecksumAddress(address);
// It is a checksummed address with a bad checksum
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
logger.throwArgumentError("bad address checksum", "address", address);
}
// Maybe ICAP? (we only support direct mode)
}
else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
// It is an ICAP address with a bad checksum
if (address.substring(2, 4) !== ibanChecksum(address)) {
logger.throwArgumentError("bad icap checksum", "address", address);
}
result = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base36To16 */ .g$)(address.substring(4));
while (result.length < 40) {
result = "0" + result;
}
result = getChecksumAddress("0x" + resul