Changed state handling on template and engine initialization
This commit is contained in:
parent
d3961783b4
commit
deb9c9a838
|
@ -431,80 +431,51 @@ class EmbarkController {
|
||||||
}
|
}
|
||||||
|
|
||||||
scaffold(options) {
|
scaffold(options) {
|
||||||
this.context = options.context || [constants.contexts.build];
|
|
||||||
|
this.context = options.context || [constants.contexts.scaffold];
|
||||||
|
options.onlyCompile = true;
|
||||||
|
|
||||||
const Scaffolding = require('../lib/cmds/scaffolding.js');
|
const Scaffolding = require('../lib/cmds/scaffolding.js');
|
||||||
|
|
||||||
const Engine = require('../lib/core/engine.js');
|
const Engine = require('../lib/core/engine.js');
|
||||||
|
|
||||||
const engine = new Engine({
|
const engine = new Engine({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
client: options.client,
|
|
||||||
locale: options.locale,
|
|
||||||
version: this.version,
|
version: this.version,
|
||||||
embarkConfig: 'embark.json',
|
embarkConfig: options.embarkConfig || 'embark.json',
|
||||||
interceptLogs: false,
|
|
||||||
logFile: options.logFile,
|
logFile: options.logFile,
|
||||||
logLevel: options.logLevel,
|
context: this.context
|
||||||
events: options.events,
|
|
||||||
logger: options.logger,
|
|
||||||
config: options.config,
|
|
||||||
plugins: options.plugins,
|
|
||||||
context: this.context,
|
|
||||||
webpackConfigName: options.webpackConfigName
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function initEngine(callback) {
|
function (callback) {
|
||||||
engine.init({}, callback);
|
engine.init({}, callback);
|
||||||
},
|
},
|
||||||
function startServices(callback) {
|
function (callback) {
|
||||||
let pluginList = engine.plugins.listPlugins();
|
let pluginList = engine.plugins.listPlugins();
|
||||||
if (pluginList.length > 0) {
|
if (pluginList.length > 0) {
|
||||||
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
|
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.startService("processManager");
|
engine.startService("processManager");
|
||||||
|
engine.startService("serviceMonitor");
|
||||||
engine.startService("libraryManager");
|
engine.startService("libraryManager");
|
||||||
engine.startService("codeRunner");
|
|
||||||
engine.startService("web3");
|
|
||||||
if (!options.onlyCompile) {
|
|
||||||
engine.startService("pipeline");
|
engine.startService("pipeline");
|
||||||
}
|
engine.startService("deployment", {onlyCompile: true});
|
||||||
engine.startService("deployment", {onlyCompile: options.onlyCompile});
|
engine.startService("web3");
|
||||||
if (!options.onlyCompile) {
|
|
||||||
engine.startService("storage");
|
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
|
|
||||||
|
engine.events.request('deploy:contracts', callback);
|
||||||
}
|
}
|
||||||
|
], (err) => {
|
||||||
callback();
|
if (err) {
|
||||||
},
|
engine.logger.error(err.message);
|
||||||
function deploy(callback) {
|
engine.logger.info(err.stack);
|
||||||
engine.events.request('deploy:contracts', function (err) {
|
} else {
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function waitForWriteFinish(callback) {
|
|
||||||
if (options.onlyCompile) {
|
|
||||||
engine.logger.info("Finished compiling".underline);
|
|
||||||
return callback(null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
engine.events.on('outputDone', (err) => {
|
|
||||||
|
|
||||||
|
|
||||||
let scaffold = new Scaffolding(engine, options);
|
let scaffold = new Scaffolding(engine, options);
|
||||||
scaffold.generate(options.contract, options.overwrite);
|
scaffold.generate(options.contract, options.overwrite);
|
||||||
callback(err, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function (_err, canExit) {
|
|
||||||
// TODO: this should be moved out and determined somewhere else
|
|
||||||
if (canExit || !engine.config.contractsConfig.afterDeploy || !engine.config.contractsConfig.afterDeploy.length) {
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
engine.logger.info(__('Waiting for after deploy to finish...'));
|
|
||||||
engine.logger.info(__('You can exit with CTRL+C when after deploy completes'));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,22 +30,27 @@ class {{capitalize name}}Form{{@index}} extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e, name){
|
handleChange(e, name){
|
||||||
this.state.input[name] = e.target.value;
|
const {input} = this.state;
|
||||||
this.setState(this.state);
|
input[name] = e.target.value;
|
||||||
|
this.setState({input});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCheckbox(e, name){
|
handleCheckbox(e, name){
|
||||||
this.state.input[name] = e.target.checked;
|
const {input} = this.state;
|
||||||
this.setState(this.state);
|
input[name] = e.target.checked;
|
||||||
|
this.setState({input});
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleClick(e){
|
async handleClick(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
const {input, value} = this.state;
|
||||||
|
|
||||||
this.setState({output: null, error: null, receipt: null});
|
this.setState({output: null, error: null, receipt: null});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
{{#ifview stateMutability}}
|
{{#ifview stateMutability}}
|
||||||
const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call()
|
const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call()
|
||||||
{{#iflengthgt outputs 1}}
|
{{#iflengthgt outputs 1}}
|
||||||
this.setState({output: {
|
this.setState({output: {
|
||||||
{{#each outputs}}
|
{{#each outputs}}
|
||||||
|
@ -56,13 +61,13 @@ class {{capitalize name}}Form{{@index}} extends Component {
|
||||||
this.setState({output: result});
|
this.setState({output: result});
|
||||||
{{/iflengthgt}}
|
{{/iflengthgt}}
|
||||||
{{else}}
|
{{else}}
|
||||||
const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}});
|
const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}});
|
||||||
|
|
||||||
const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
|
const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
|
||||||
|
|
||||||
const receipt = await toSend.send({
|
const receipt = await toSend.send({
|
||||||
{{#if payable}}
|
{{#if payable}}
|
||||||
value: this.state.value,
|
value: value,
|
||||||
{{/if}}
|
{{/if}}
|
||||||
from: web3.eth.defaultAccount,
|
from: web3.eth.defaultAccount,
|
||||||
gasLimit: estimatedGas
|
gasLimit: estimatedGas
|
||||||
|
|
Loading…
Reference in New Issue