UNPKG

truffle

Version:

Truffle - Simple development framework for Ethereum

641 lines (600 loc) 24.5 kB
#!/usr/bin/env node exports.id = 3736; exports.ids = [3736]; exports.modules = { /***/ 92936: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ getAddress: () => (/* binding */ getAddress), /* harmony export */ getContractAddress: () => (/* binding */ getContractAddress), /* harmony export */ getCreate2Address: () => (/* binding */ getCreate2Address), /* harmony export */ getIcapAddress: () => (/* binding */ getIcapAddress), /* harmony export */ isAddress: () => (/* binding */ isAddress) /* harmony export */ }); /* 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_rlp__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(50284); /* 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" + result); } else { logger.throwArgumentError("invalid address", "address", address); } return result; } function isAddress(address) { try { getAddress(address); return true; } catch (error) { } return false; } function getIcapAddress(address) { let base36 = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base16To36 */ .t2)(getAddress(address).substring(2)).toUpperCase(); while (base36.length < 30) { base36 = "0" + base36; } return "XE" + ibanChecksum("XE00" + base36) + base36; } // http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed function getContractAddress(transaction) { let from = null; try { from = getAddress(transaction.from); } catch (error) { logger.throwArgumentError("missing from address", "transaction", transaction); } const nonce = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .stripZeros */ .G1)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)(_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* .BigNumber */ .O$.from(transaction.nonce).toHexString())); return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_rlp__WEBPACK_IMPORTED_MODULE_5__.encode)([from, nonce])), 12)); } function getCreate2Address(from, salt, initCodeHash) { if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(salt) !== 32) { logger.throwArgumentError("salt must be 32 bytes", "salt", salt); } if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(initCodeHash) !== 32) { logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash); } return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .concat */ .zo)(["0xff", getAddress(from), salt, initCodeHash])), 12)); } //# sourceMappingURL=index.js.map /***/ }), /***/ 20335: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Ox: () => (/* binding */ parseFixed), /* harmony export */ S5: () => (/* binding */ formatFixed), /* harmony export */ xs: () => (/* binding */ FixedNumber) /* harmony export */ }); /* unused harmony export FixedFormat */ /* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(46366); /* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167); /* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48794); /* harmony import */ var _bignumber__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2593); const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i); const _constructorGuard = {}; const Zero = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(0); const NegativeOne = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(-1); function throwFault(message, fault, operation, value) { const params = { fault: fault, operation: operation }; if (value !== undefined) { params.value = value; } return logger.throwError(message, _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.NUMERIC_FAULT, params); } // Constant to pull zeros from for multipliers let zeros = "0"; while (zeros.length < 256) { zeros += zeros; } // Returns a string "1" followed by decimal "0"s function getMultiplier(decimals) { if (typeof (decimals) !== "number") { try { decimals = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(decimals).toNumber(); } catch (e) { } } if (typeof (decimals) === "number" && decimals >= 0 && decimals <= 256 && !(decimals % 1)) { return ("1" + zeros.substring(0, decimals)); } return logger.throwArgumentError("invalid decimal size", "decimals", decimals); } function formatFixed(value, decimals) { if (decimals == null) { decimals = 0; } const multiplier = getMultiplier(decimals); // Make sure wei is a big number (convert as necessary) value = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value); const negative = value.lt(Zero); if (negative) { value = value.mul(NegativeOne); } let fraction = value.mod(multiplier).toString(); while (fraction.length < multiplier.length - 1) { fraction = "0" + fraction; } // Strip training 0 fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1]; const whole = value.div(multiplier).toString(); if (multiplier.length === 1) { value = whole; } else { value = whole + "." + fraction; } if (negative) { value = "-" + value; } return value; } function parseFixed(value, decimals) { if (decimals == null) { decimals = 0; } const multiplier = getMultiplier(decimals); if (typeof (value) !== "string" || !value.match(/^-?[0-9.]+$/)) { logger.throwArgumentError("invalid decimal value", "value", value); } // Is it negative? const negative = (value.substring(0, 1) === "-"); if (negative) { value = value.substring(1); } if (value === ".") { logger.throwArgumentError("missing value", "value", value); } // Split it into a whole and fractional part const comps = value.split("."); if (comps.length > 2) { logger.throwArgumentError("too many decimal points", "value", value); } let whole = comps[0], fraction = comps[1]; if (!whole) { whole = "0"; } if (!fraction) { fraction = "0"; } // Trim trailing zeros while (fraction[fraction.length - 1] === "0") { fraction = fraction.substring(0, fraction.length - 1); } // Check the fraction doesn't exceed our decimals size if (fraction.length > multiplier.length - 1) { throwFault("fractional component exceeds decimals", "underflow", "parseFixed"); } // If decimals is 0, we have an empty string for fraction if (fraction === "") { fraction = "0"; } // Fully pad the string with zeros to get to wei while (fraction.length < multiplier.length - 1) { fraction += "0"; } const wholeValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(whole); const fractionValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(fraction); let wei = (wholeValue.mul(multiplier)).add(fractionValue); if (negative) { wei = wei.mul(NegativeOne); } return wei; } class FixedFormat { constructor(constructorGuard, signed, width, decimals) { if (constructorGuard !== _constructorGuard) { logger.throwError("cannot use FixedFormat constructor; use FixedFormat.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, { operation: "new FixedFormat" }); } this.signed = signed; this.width = width; this.decimals = decimals; this.name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals); this._multiplier = getMultiplier(decimals); Object.freeze(this); } static from(value) { if (value instanceof FixedFormat) { return value; } if (typeof (value) === "number") { value = `fixed128x${value}`; } let signed = true; let width = 128; let decimals = 18; if (typeof (value) === "string") { if (value === "fixed") { // defaults... } else if (value === "ufixed") { signed = false; } else { const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/); if (!match) { logger.throwArgumentError("invalid fixed format", "format", value); } signed = (match[1] !== "u"); width = parseInt(match[2]); decimals = parseInt(match[3]); } } else if (value) { const check = (key, type, defaultValue) => { if (value[key] == null) { return defaultValue; } if (typeof (value[key]) !== type) { logger.throwArgumentError("invalid fixed format (" + key + " not " + type + ")", "format." + key, value[key]); } return value[key]; }; signed = check("signed", "boolean", signed); width = check("width", "number", width); decimals = check("decimals", "number", decimals); } if (width % 8) { logger.throwArgumentError("invalid fixed format width (not byte aligned)", "format.width", width); } if (decimals > 80) { logger.throwArgumentError("invalid fixed format (decimals too large)", "format.decimals", decimals); } return new FixedFormat(_constructorGuard, signed, width, decimals); } } class FixedNumber { constructor(constructorGuard, hex, value, format) { if (constructorGuard !== _constructorGuard) { logger.throwError("cannot use FixedNumber constructor; use FixedNumber.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, { operation: "new FixedFormat" }); } this.format = format; this._hex = hex; this._value = value; this._isFixedNumber = true; Object.freeze(this); } _checkFormat(other) { if (this.format.name !== other.format.name) { logger.throwArgumentError("incompatible format; use fixedNumber.toFormat", "other", other); } } addUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.add(b), this.format.decimals, this.format); } subUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.sub(b), this.format.decimals, this.format); } mulUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.mul(b).div(this.format._multiplier), this.format.decimals, this.format); } divUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.mul(this.format._multiplier).div(b), this.format.decimals, this.format); } floor() { const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } let result = FixedNumber.from(comps[0], this.format); const hasFraction = !comps[1].match(/^(0*)$/); if (this.isNegative() && hasFraction) { result = result.subUnsafe(ONE.toFormat(result.format)); } return result; } ceiling() { const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } let result = FixedNumber.from(comps[0], this.format); const hasFraction = !comps[1].match(/^(0*)$/); if (!this.isNegative() && hasFraction) { result = result.addUnsafe(ONE.toFormat(result.format)); } return result; } // @TODO: Support other rounding algorithms round(decimals) { if (decimals == null) { decimals = 0; } // If we are already in range, we're done const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } if (decimals < 0 || decimals > 80 || (decimals % 1)) { logger.throwArgumentError("invalid decimal count", "decimals", decimals); } if (comps[1].length <= decimals) { return this; } const factor = FixedNumber.from("1" + zeros.substring(0, decimals), this.format); const bump = BUMP.toFormat(this.format); return this.mulUnsafe(factor).addUnsafe(bump).floor().divUnsafe(factor); } isZero() { return (this._value === "0.0" || this._value === "0"); } isNegative() { return (this._value[0] === "-"); } toString() { return this._value; } toHexString(width) { if (width == null) { return this._hex; } if (width % 8) { logger.throwArgumentError("invalid byte width", "width", width); } const hex = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(this._hex).fromTwos(this.format.width).toTwos(width).toHexString(); return (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, width / 8); } toUnsafeFloat() { return parseFloat(this.toString()); } toFormat(format) { return FixedNumber.fromString(this._value, format); } static fromValue(value, decimals, format) { // If decimals looks more like a format, and there is no format, shift the parameters if (format == null && decimals != null && !(0,_bignumber__WEBPACK_IMPORTED_MODULE_2__/* .isBigNumberish */ .Zm)(decimals)) { format = decimals; decimals = null; } if (decimals == null) { decimals = 0; } if (format == null) { format = "fixed"; } return FixedNumber.fromString(formatFixed(value, decimals), FixedFormat.from(format)); } static fromString(value, format) { if (format == null) { format = "fixed"; } const fixedFormat = FixedFormat.from(format); const numeric = parseFixed(value, fixedFormat.decimals); if (!fixedFormat.signed && numeric.lt(Zero)) { throwFault("unsigned value cannot be negative", "overflow", "value", value); } let hex = null; if (fixedFormat.signed) { hex = numeric.toTwos(fixedFormat.width).toHexString(); } else { hex = numeric.toHexString(); hex = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, fixedFormat.width / 8); } const decimal = formatFixed(numeric, fixedFormat.decimals); return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat); } static fromBytes(value, format) { if (format == null) { format = "fixed"; } const fixedFormat = FixedFormat.from(format); if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(value).length > fixedFormat.width / 8) { throw new Error("overflow"); } let numeric = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value); if (fixedFormat.signed) { numeric = numeric.fromTwos(fixedFormat.width); } const hex = numeric.toTwos((fixedFormat.signed ? 0 : 1) + fixedFormat.width).toHexString(); const decimal = formatFixed(numeric, fixedFormat.decimals); return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat); } static from(value, format) { if (typeof (value) === "string") { return FixedNumber.fromString(value, format); } if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .isBytes */ ._t)(value)) { return FixedNumber.fromBytes(value, format); } try { return FixedNumber.fromValue(value, 0, format); } catch (error) { // Allow NUMERIC_FAULT to bubble up if (error.code !== _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.INVALID_ARGUMENT) { throw error; } } return logger.throwArgumentError("invalid FixedNumber value", "value", value); } static isFixedNumber(value) { return !!(value && value._isFixedNumber); } } const ONE = FixedNumber.from(1); const BUMP = FixedNumber.from("0.5"); //# sourceMappingURL=fixednumber.js.map /***/ }), /***/ 61642: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var window = __webpack_require__(58908); var nodeCrypto = __webpack_require__(6113); function getRandomValues(buf) { if (window.crypto && window.crypto.getRandomValues) { return window.crypto.getRandomValues(buf); } if (typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') { return window.msCrypto.getRandomValues(buf); } if (nodeCrypto.randomBytes) { if (!(buf instanceof Uint8Array)) { throw new TypeError('expected Uint8Array'); } if (buf.length > 65536) { var e = new Error(); e.code = 22; e.message = 'Failed to execute \'getRandomValues\' on \'Crypto\': The ' + 'ArrayBufferView\'s byte length (' + buf.length + ') exceeds the ' + 'number of bytes of entropy available via this API (65536).'; e.name = 'QuotaExceededError'; throw e; } var bytes = nodeCrypto.randomBytes(buf.length); buf.set(bytes); return buf; } else { throw new Error('No secure random number generator available.'); } } module.exports = getRandomValues; /***/ }), /***/ 58908: /***/ ((module) => { var win; if (typeof window !== "undefined") { win = window; } else if (typeof global !== "undefined") { win = global; } else if (typeof self !== "undefined"){ win = self; } else { win = {}; } module.exports = win; /***/ }), /***/ 94806: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; // classic singleton yargs API, to use yargs // without running as a singleton do: // require('yargs/yargs')(process.argv.slice(2)) const yargs = __webpack_require__(64968) Argv(process.argv.slice(2)) module.exports = Argv function Argv (processArgs, cwd) { const argv = yargs(processArgs, cwd, __webpack_require__(26503)) singletonify(argv) return argv } /* Hack an instance of Argv with process.argv into Argv so people can do require('yargs')(['--beeble=1','-z','zizzle']).argv to parse a list of args and require('yargs').argv to get a parsed version of process.argv. */ function singletonify (inst) { Object.keys(inst).forEach((key) => { if (key === 'argv') { Argv.__defineGetter__(key, inst.__lookupGetter__(key)) } else { Argv[key] = typeof inst[key] === 'function' ? inst[key].bind(inst) : inst[key] } }) } /***/ }) }; ; //# sourceMappingURL=3736.bundled.js.map