Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"contracts_build_directory",
"migrations_directory",
"networks",
"network",
"network_id",
"provider",
"resolver",
"build_directory"
]);
this.options = options;
this.repl = options.repl || new ReplManager(options);
this.command = new Command(tasks);
this.interfaceAdapter = new InterfaceAdapter();
this.web3 = new Web3Shim({
provider: options.provider,
networkType: options.networks[options.network].type
});
// Bubble the ReplManager's exit event
this.repl.on("exit", () => this.emit("exit"));
}
matchesNetwork: async function(network_id, network_options, callback) {
const provider = Provider.create(network_options);
const first = network_id + "";
const second = network_options.network_id + "";
if (first === second) return callback(null, 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 callback(null, false);
const interfaceAdapter = new InterfaceAdapter();
const web3 = new Web3Shim({
provider,
networkType: network_options.type
});
web3.eth.net
.getId(current_network_id => {
if (first === current_network_id) return callback(null, true);
if (isFirstANumber === false) {
BlockchainUtils.matches(first, provider, callback);
} else {
// Nothing else to compare.
return callback(null, false);
}
})
.catch(callback);
if (typeof json !== "object") {
network_id = json;
json = this._json;
}
json = utils.merge({}, this._json || {}, json);
temp._constructorMethods = this._constructorMethods;
temp._properties = this._properties;
temp._property_values = {};
temp._json = json;
bootstrap(temp);
temp.interfaceAdapter = new InterfaceAdapter();
temp.web3 = new Web3Shim({
networkType: temp.networkType
});
temp.class_defaults = temp.prototype.defaults || {};
if (network_id) {
temp.setNetwork(network_id);
}
// Copy over custom key/values to the contract class
Object.keys(json).forEach(key => {
if (key.indexOf("x-") !== 0) return;
temp[key] = json[key];
});
return temp;
testConnection: function(options) {
let networkCheckTimeout, networkType;
const { networks, network } = options;
if (networks && networks[network]) {
networkCheckTimeout =
networks[network].networkCheckTimeout || DEFAULT_NETWORK_CHECK_TIMEOUT;
networkType = networks[network].type;
} else {
networkCheckTimeout = DEFAULT_NETWORK_CHECK_TIMEOUT;
}
const provider = this.getProvider(options);
const web3 = new Web3Shim({ provider, networkType });
const interfaceAdapter = new InterfaceAdapter({ provider, networkType });
return new Promise((resolve, reject) => {
const noResponseFromNetworkCall = setTimeout(() => {
const errorMessage =
"There was a timeout while attempting to connect to the network." +
"\n Check to see that your provider is valid.\n If you " +
"have a slow internet connection, try configuring a longer " +
"timeout in your Truffle config. Use the " +
"networks[networkName].networkCheckTimeout property to do this.";
throw new Error(errorMessage);
}, networkCheckTimeout);
web3.eth
.getBlockNumber()
.then(() => {
clearTimeout(noResponseFromNetworkCall);
resolve(true);
})
detect: async function(config) {
expect.options(config, ["networks"]);
helpers.setUpConfig(config);
helpers.validateNetworkConfig(config);
const interfaceAdapter = new InterfaceAdapter({
provider: config.provider,
networkType: config.networks[config.network].type
});
const web3 = new Web3Shim({
provider: config.provider,
networkType: config.networks[config.network].type
});
await Provider.testConnection(config);
await helpers.detectAndSetNetworkId(config, web3, interfaceAdapter);
await helpers.setFromOnConfig(config, web3, interfaceAdapter);
},
fork: async function(config) {
expect.options(config, ["from", "provider", "networks", "network"]);
const interfaceAdapter = new InterfaceAdapter({
provider: config.provider,
networkType: config.networks[config.network].type
});
const web3 = new Web3Shim({
provider: config.provider,
networkType: config.networks[config.network].type
});
const accounts = await web3.eth.getAccounts();
const block = await interfaceAdapter.getBlock("latest");
const upstreamNetwork = config.network;
const upstreamConfig = config.networks[upstreamNetwork];
const forkedNetwork = config.network + "-fork";
const ganacheOptions = {
fork: config.provider,
if (!ropsten) {
return callback(
new TruffleError(
"You need to have a `ropsten` network configured in order to publish to the Ethereum Package Registry. See the following link for an example configuration:" +
OS.EOL +
OS.EOL +
" http://truffleframework.com/tutorials/using-infura-custom-provider" +
OS.EOL
)
);
}
options.network = "ropsten";
var provider = options.provider;
const interfaceAdapter = new InterfaceAdapter({
provider: options.provider,
networkType: "ethereum"
});
var web3 = new Web3Shim({
provider: options.provider,
networkType: "ethereum"
});
var host = options.ethpm.ipfs_host;
if (host instanceof EthPM.hosts.IPFS === false) {
host = new EthPM.hosts.IPFS(
options.ethpm.ipfs_host,
options.ethpm.ipfs_port,
options.ethpm.ipfs_protocol
);
}