truffle
Version:
Truffle - Simple development framework for Ethereum
812 lines (675 loc) • 22.6 kB
JavaScript
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 99706:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = {
run: __webpack_require__(13018),
meta: __webpack_require__(41873)
};
/***/ }),
/***/ 41873:
/***/ ((module) => {
module.exports = {
command: "networks",
description: "Show addresses for deployed contracts on each network",
builder: {
clean: {
describe:
"Remove network artifacts that don't belong to any configuration",
type: "boolean",
default: false
}
},
help: {
usage: "truffle networks [--clean]",
options: [
{
option: "--clean",
description:
"Remove all network artifacts that aren't associated with a named network."
}
],
allowedGlobalOptions: []
}
};
/***/ }),
/***/ 13018:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = async function (options) {
const Config = __webpack_require__(20553);
const Networks = __webpack_require__(78979);
const config = Config.detect(options);
if (options.clean) {
return await Networks.clean(config);
}
return await Networks.display(config);
};
/***/ }),
/***/ 78979:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
const fs = __webpack_require__(57147);
const path = __webpack_require__(71017);
const OS = __webpack_require__(22037);
const BlockchainUtils = __webpack_require__(86317);
const Provider = __webpack_require__(509);
const { createInterfaceAdapter } = __webpack_require__(36339);
const Networks = {
deployed: async function(options) {
let files;
try {
// Only read JSON files in directory
files = fs
.readdirSync(options.contracts_build_directory)
.filter(fn => fn.endsWith(".json"));
} catch (error) {
// We can't read the directory. Act like we found nothing.
files = [];
}
const binaries = files.map(file => {
const filePath = path.join(options.contracts_build_directory, file);
const fileContents = fs.readFileSync(filePath, "utf8");
return JSON.parse(fileContents);
});
const idsToNames = {};
const networks = {};
for (let networkName in options.networks) {
const network = options.networks[networkName];
const networkId = network.network_id;
if (networkId == null) return;
idsToNames[networkId] = networkName;
networks[networkName] = {};
}
for (let json of binaries) {
for (let networkId in json.networks) {
const networkName = idsToNames[networkId] || networkId;
if (networks[networkName] == null) networks[networkName] = {};
const address = json.networks[networkId].address;
if (address == null) return;
networks[networkName][json.contractName] = address;
}
}
return networks;
},
display: async function(config) {
const networks = await this.deployed(config);
const { networkNames, starNetworks } = Object.keys(networks)
.sort()
.reduce(
(acc, networkName) => {
if (
config.networks[networkName] &&
config.networks[networkName].network_id === "*"
) {
acc.starNetworks.push(networkName);
} else {
acc.networkNames.push(networkName);
}
return acc;
},
{ networkNames: [], starNetworks: [] }
);
const unknownNetworks = networkNames.filter(networkName => {
const configuredNetworks = Object.keys(config.networks);
let found = false;
for (let i = 0; i < configuredNetworks.length; i++) {
const configuredNetworkName = configuredNetworks[i];
if (networkName === configuredNetworkName) {
found = true;
break;
}
}
return !found;
});
// Only display this warning if:
//
// At least one network is configured with the wildcard ('*') network id
// There's a least one network deployed to
// And one of those networks deployed to is unknown (i.e., unconfigured).
if (
starNetworks.length > 0 &&
networkNames.length > 0 &&
unknownNetworks.length > 0
) {
config.logger.log(
OS.EOL +
"The following networks are configured to match any network id ('*'):" +
OS.EOL
);
starNetworks.forEach(networkName => {
config.logger.log(" " + networkName);
});
config.logger.log(
OS.EOL +
"Closely inspect the deployed networks below, and use `truffle networks --clean` to remove any networks that don't match your configuration. You should not use the wildcard configuration ('*') for staging and production networks for which you intend to deploy your application."
);
}
networkNames.forEach(networkName => {
config.logger.log("");
let output = Object.keys(networks[networkName])
.sort()
.map(contract_name => {
const address = networks[networkName][contract_name];
return contract_name + ": " + address;
});
if (output.length === 0) output = ["No contracts deployed."];
let message = "Network: ";
const is_id = config.networks[networkName] == null;
if (is_id) {
message += "UNKNOWN (id: " + networkName + ")";
} else {
message +=
networkName +
" (id: " +
config.networks[networkName].network_id +
")";
}
config.logger.log(message);
config.logger.log(" " + output.join("\n "));
});
if (networkNames.length === 0) {
config.logger.log(
OS.EOL + "Contracts have not been deployed to any network."
);
}
config.logger.log("");
},
clean: async function(config) {
// Only read JSON files in directory
let files = fs
.readdirSync(config.contracts_build_directory)
.filter(fn => fn.endsWith(".json"));
const configuredNetworks = Object.keys(config.networks);
const results = [];
files.forEach(file => {
const filePath = path.join(config.contracts_build_directory, file);
const fileContents = fs.readFileSync(filePath, "utf8");
const body = JSON.parse(fileContents);
for (let installedNetworkId of Object.keys(body.networks)) {
let found = false;
for (let i = 0; i < configuredNetworks.length; i++) {
const configuredNetwork = configuredNetworks[i];
// If an installed network id matches a configured id, then we can ignore this one.
let parsedNetworkId;
try {
// Account for an integer or string in the config
parsedNetworkId = parseInt(installedNetworkId);
} catch (_error) {
// If it can't be parsed into an int like * then don't worry about it
}
if (
installedNetworkId ===
config.networks[configuredNetwork].network_id ||
parsedNetworkId === config.networks[configuredNetwork].network_id
) {
found = true;
break;
}
}
// If we didn't find a suitable configuration, delete this network.
if (found === false) delete body.networks[installedNetworkId];
}
// Our work is done here. Save the file.
fs.writeFileSync(filePath, JSON.stringify(body, null, 2), "utf8");
results.push(body);
});
// TODO: Display what's removed?
return results;
},
// Try to connect to every named network except for "test" and "development"
asURIs: async function(options, networks) {
const result = {
uris: {},
failed: []
};
for (const networkName of networks) {
const provider = Provider.create(options.networks[networkName]);
try {
const uri = await BlockchainUtils.asURI(provider);
result.uris[networkName] = uri;
} catch (error) {
result.failed.push(networkName);
}
}
return result;
},
matchesNetwork: async function(network_id, network_options) {
const provider = Provider.create(network_options);
const first = network_id + "";
const second = network_options.network_id + "";
if (first === second) return true;
const isFirstANumber = isNaN(parseInt(network_id)) === false;
const isSecondANumber =
isNaN(parseInt(network_options.network_id)) === false;
// If both network ids are numbers, then they don't match, and we should quit.
if (isFirstANumber && isSecondANumber) return false;
const interfaceAdapter = createInterfaceAdapter({
provider,
networkType: network_options.type
});
const currentNetworkID = await interfaceAdapter.getNetworkId();
if (first === currentNetworkID) return true;
if (isFirstANumber === false)
await BlockchainUtils.matches(first, provider);
else {
// Nothing else to compare.
return false;
}
}
};
module.exports = Networks;
/***/ }),
/***/ 86317:
/***/ ((module) => {
;
const Blockchain = {
getBlockByNumber(blockNumber, provider, callback) {
const params = [blockNumber, true];
provider.send({
jsonrpc: "2.0",
method: "eth_getBlockByNumber",
params,
id: Date.now()
}, callback);
},
getBlockByHash(blockHash, provider, callback) {
const params = [blockHash, true];
provider.send({
jsonrpc: "2.0",
method: "eth_getBlockByHash",
params,
id: Date.now()
}, callback);
},
parse(uri) {
const parsed = {};
if (uri.indexOf("blockchain://") !== 0)
return parsed;
const cleanUri = uri.replace("blockchain://", "");
const pieces = cleanUri.split("/block/");
parsed.genesis_hash = `0x${pieces[0]}`;
parsed.block_hash = `0x${pieces[1]}`;
return parsed;
},
asURI(provider) {
return new Promise((resolve, reject) => {
let genesis, latest;
this.getBlockByNumber("0x0", provider, (err, { result }) => {
if (err)
return reject(err);
genesis = result;
this.getBlockByNumber("latest", provider, (err, { result }) => {
if (err)
return reject(err);
latest = result;
const url = `blockchain://${genesis.hash.replace("0x", "")}/block/${latest.hash.replace("0x", "")}`;
resolve(url);
});
});
});
},
matches(uri, provider) {
return new Promise((resolve, reject) => {
const parsedUri = this.parse(uri);
const expectedGenesis = parsedUri.genesis_hash;
const expectedBlock = parsedUri.block_hash;
this.getBlockByNumber("0x0", provider, (err, { result }) => {
if (err)
return reject(err);
const block = result;
if (block.hash !== expectedGenesis)
return resolve(false);
this.getBlockByHash(expectedBlock, provider, (err, { result }) => {
// Treat an error as if the block didn't exist. This is because
// some clients respond differently.
const block = result;
if (err || block == null) {
return resolve(false);
}
resolve(true);
});
});
});
}
};
module.exports = Blockchain;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 44516:
/***/ ((module) => {
;
module.exports = require("original-require");
/***/ }),
/***/ 39491:
/***/ ((module) => {
;
module.exports = require("assert");
/***/ }),
/***/ 50852:
/***/ ((module) => {
;
module.exports = require("async_hooks");
/***/ }),
/***/ 14300:
/***/ ((module) => {
;
module.exports = require("buffer");
/***/ }),
/***/ 32081:
/***/ ((module) => {
;
module.exports = require("child_process");
/***/ }),
/***/ 22057:
/***/ ((module) => {
;
module.exports = require("constants");
/***/ }),
/***/ 6113:
/***/ ((module) => {
;
module.exports = require("crypto");
/***/ }),
/***/ 82361:
/***/ ((module) => {
;
module.exports = require("events");
/***/ }),
/***/ 57147:
/***/ ((module) => {
;
module.exports = require("fs");
/***/ }),
/***/ 13685:
/***/ ((module) => {
;
module.exports = require("http");
/***/ }),
/***/ 95687:
/***/ ((module) => {
;
module.exports = require("https");
/***/ }),
/***/ 41808:
/***/ ((module) => {
;
module.exports = require("net");
/***/ }),
/***/ 22037:
/***/ ((module) => {
;
module.exports = require("os");
/***/ }),
/***/ 71017:
/***/ ((module) => {
;
module.exports = require("path");
/***/ }),
/***/ 85477:
/***/ ((module) => {
;
module.exports = require("punycode");
/***/ }),
/***/ 63477:
/***/ ((module) => {
;
module.exports = require("querystring");
/***/ }),
/***/ 14521:
/***/ ((module) => {
;
module.exports = require("readline");
/***/ }),
/***/ 12781:
/***/ ((module) => {
;
module.exports = require("stream");
/***/ }),
/***/ 71576:
/***/ ((module) => {
;
module.exports = require("string_decoder");
/***/ }),
/***/ 24404:
/***/ ((module) => {
;
module.exports = require("tls");
/***/ }),
/***/ 76224:
/***/ ((module) => {
;
module.exports = require("tty");
/***/ }),
/***/ 57310:
/***/ ((module) => {
;
module.exports = require("url");
/***/ }),
/***/ 73837:
/***/ ((module) => {
;
module.exports = require("util");
/***/ }),
/***/ 59796:
/***/ ((module) => {
;
module.exports = require("zlib");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
/******/ loaded: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = __webpack_modules__;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = __webpack_module_cache__;
/******/
/******/ // the startup function
/******/ __webpack_require__.x = () => {
/******/ // Load entry module and return exports
/******/ var __webpack_exports__ = __webpack_require__.O(undefined, [5158,9129,4957,553], () => (__webpack_require__(99706)))
/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
/******/ return __webpack_exports__;
/******/ };
/******/
/************************************************************************/
/******/ /* webpack/runtime/amd options */
/******/ (() => {
/******/ __webpack_require__.amdO = {};
/******/ })();
/******/
/******/ /* webpack/runtime/chunk loaded */
/******/ (() => {
/******/ var deferred = [];
/******/ __webpack_require__.O = (result, chunkIds, fn, priority) => {
/******/ if(chunkIds) {
/******/ priority = priority || 0;
/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
/******/ deferred[i] = [chunkIds, fn, priority];
/******/ return;
/******/ }
/******/ var notFulfilled = Infinity;
/******/ for (var i = 0; i < deferred.length; i++) {
/******/ var [chunkIds, fn, priority] = deferred[i];
/******/ var fulfilled = true;
/******/ for (var j = 0; j < chunkIds.length; j++) {
/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
/******/ chunkIds.splice(j--, 1);
/******/ } else {
/******/ fulfilled = false;
/******/ if(priority < notFulfilled) notFulfilled = priority;
/******/ }
/******/ }
/******/ if(fulfilled) {
/******/ deferred.splice(i--, 1)
/******/ var r = fn();
/******/ if (r !== undefined) result = r;
/******/ }
/******/ }
/******/ return result;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/ensure chunk */
/******/ (() => {
/******/ __webpack_require__.f = {};
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = (chunkId) => {
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
/******/ __webpack_require__.f[key](chunkId, promises);
/******/ return promises;
/******/ }, []));
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/get javascript chunk filename */
/******/ (() => {
/******/ // This function allow to reference async chunks and sibling chunks for the entrypoint
/******/ __webpack_require__.u = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".bundled.js";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/node module decorator */
/******/ (() => {
/******/ __webpack_require__.nmd = (module) => {
/******/ module.paths = [];
/******/ if (!module.children) module.children = [];
/******/ return module;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/require chunk loading */
/******/ (() => {
/******/ // no baseURI
/******/
/******/ // object to store loaded chunks
/******/ // "1" means "loaded", otherwise not loaded yet
/******/ var installedChunks = {
/******/ 6666: 1
/******/ };
/******/
/******/ __webpack_require__.O.require = (chunkId) => (installedChunks[chunkId]);
/******/
/******/ var installChunk = (chunk) => {
/******/ var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
/******/ for(var moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) runtime(__webpack_require__);
/******/ for(var i = 0; i < chunkIds.length; i++)
/******/ installedChunks[chunkIds[i]] = 1;
/******/ __webpack_require__.O();
/******/ };
/******/
/******/ // require() chunk loading for javascript
/******/ __webpack_require__.f.require = (chunkId, promises) => {
/******/ // "1" is the signal for "already loaded"
/******/ if(!installedChunks[chunkId]) {
/******/ if(true) { // all chunks have JS
/******/ installChunk(require("./" + __webpack_require__.u(chunkId)));
/******/ } else installedChunks[chunkId] = 1;
/******/ }
/******/ };
/******/
/******/ // no external install chunk
/******/
/******/ // no HMR
/******/
/******/ // no HMR manifest
/******/ })();
/******/
/******/ /* webpack/runtime/startup chunk dependencies */
/******/ (() => {
/******/ var next = __webpack_require__.x;
/******/ __webpack_require__.x = () => {
/******/ __webpack_require__.e(5158);
/******/ __webpack_require__.e(9129);
/******/ __webpack_require__.e(4957);
/******/ __webpack_require__.e(553);
/******/ return next();
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // module cache are used so entry inlining is disabled
/******/ // run startup
/******/ var __webpack_exports__ = __webpack_require__.x();
/******/ var __webpack_export_target__ = exports;
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/
/******/ })()
;
//# sourceMappingURL=networks.bundled.js.map