pass isDev to engine so that it can show a warning

This commit is contained in:
Jonathan Rainville 2018-05-14 14:32:19 -04:00
parent 3f09d5d3f0
commit 7b1a219b51
5 changed files with 29 additions and 13 deletions

View File

@ -9,6 +9,7 @@ var Blockchain = function(options) {
this.blockchainConfig = options.blockchainConfig;
this.env = options.env || 'development';
this.client = options.client;
this.isDev = options.isDev;
if ((this.blockchainConfig === {} || JSON.stringify(this.blockchainConfig) === '{"enabled":true}') && this.env !== 'development') {
console.log("===> " + __("warning: running default config on a non-development environment"));
@ -50,21 +51,13 @@ var Blockchain = function(options) {
this.config.datadir = fs.embarkPath(".embark/development/datadir");
}
if (this.blockchainConfig.isDev) {
this.isDev = true;
} else if (this.blockchainConfig.isDev === false) {
this.isDev = false;
} else {
this.isDev = this.env === 'development';
}
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
};
Blockchain.prototype.runCommand = function(cmd, options) {
console.log(__("running: %s", cmd.underline).green);
return shelljs.exec(cmd, options, (err, stdout, _stderr) => {
if (err && this.env === 'development' && stdout.indexOf('Failed to unlock developer account') > 0) {
if (err && this.env === 'development' && stdout.indexOf('Failed to unlock') > 0) {
console.warn('\n' + __('Development blockchain has changed to use the --dev option.').yellow);
console.warn(__('You can reset your workspace to fix the problem with').yellow + ' embark reset'.cyan);
console.warn(__('Otherwise, you can change your data directory in blockchain.json (datadir)').yellow);
@ -131,9 +124,9 @@ Blockchain.prototype.initChainAndGetAddress = function() {
return address;
};
var BlockchainClient = function(blockchainConfig, client, env) {
var BlockchainClient = function(blockchainConfig, client, env, isDev) {
if (client === 'geth') {
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env, isDev});
} else {
throw new Error('unknown client');
}

View File

@ -15,6 +15,7 @@ const Provider = require('./provider');
class Engine {
constructor(options) {
this.env = options.env;
this.isDev = options.isDev;
this.embarkConfig = options.embarkConfig;
this.interceptLogs = options.interceptLogs;
this.version = options.version;
@ -277,6 +278,7 @@ class Engine {
web3: this.web3,
accountsConfig: this.config.contractsConfig.deployment.accounts,
logger: this.logger,
isDev: this.isDev,
web3Endpoint
};
this.web3.setProvider(new Provider(providerOptions));

View File

@ -10,6 +10,7 @@ class Provider {
this.web3 = options.web3;
this.accountsConfig = options.accountsConfig;
this.logger = options.logger;
this.isDev = options.isDev;
this.engine = new ProviderEngine();
this.asyncMethods = {};
@ -43,6 +44,9 @@ class Provider {
this.asyncMethods = {
eth_accounts: self.eth_accounts.bind(this)
};
if (this.isDev) {
this.logger.warn('You are using your own account in the develop environment. It might not be funded.');
}
}
}

View File

@ -88,5 +88,9 @@
"deployed at": "deployed at",
"executing onDeploy commands": "executing onDeploy commands",
"executing: ": "executing: ",
"no config file found at %s using default config": "no config file found at %s using default config"
"no config file found at %s using default config": "no config file found at %s using default config",
"Development blockchain has changed to use the --dev option.": "Development blockchain has changed to use the --dev option.",
"You can reset your workspace to fix the problem with": "You can reset your workspace to fix the problem with",
"Otherwise, you can change your data directory in blockchain.json (datadir)": "Otherwise, you can change your data directory in blockchain.json (datadir)",
"tip: you can resize the terminal or disable the dashboard with": "tip: you can resize the terminal or disable the dashboard with"
}

View File

@ -38,6 +38,15 @@ class Embark {
this.plugins = this.config.plugins;
}
isDev(env) {
if (this.config && this.config.blockchainConfig && this.config.blockchainConfig.isDev) {
return true;
} else if (this.config && this.config.blockchainConfig && this.config.blockchainConfig.isDev === false) {
return false;
}
return (env === 'development');
}
blockchain(env, client) {
this.context = [constants.contexts.blockchain];
let blockchainConfig = this.config.blockchainConfig;
@ -52,7 +61,7 @@ class Embark {
if(webServerConfig) blockchainConfig.wsOrigins = `http://${webServerConfig.host}:${webServerConfig.port}`;
if(storageConfig) blockchainConfig.wsOrigins += `${blockchainConfig.wsOrigins.length ? ',' : ''}${storageConfig.protocol}://${storageConfig.host}:${storageConfig.port}`;
}
return require('./cmds/blockchain/blockchain.js')(blockchainConfig, client, env).run();
return require('./cmds/blockchain/blockchain.js')(blockchainConfig, client, env, this.isDev(env)).run();
}
simulator(options) {
@ -77,6 +86,7 @@ class Embark {
let engine = new Engine({
env: options.env,
isDev: this.isDev(options.env),
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logFile: options.logFile,
@ -169,6 +179,7 @@ class Embark {
let engine = new Engine({
env: options.env,
isDev: this.isDev(options.env),
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false,
@ -228,6 +239,7 @@ class Embark {
let engine = new Engine({
env: options.env,
isDev: this.isDev(options.env),
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logFile: options.logFile,
@ -282,6 +294,7 @@ class Embark {
let engine = new Engine({
env: options.env,
isDev: this.isDev(options.env),
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false,