implement onDeploy
This commit is contained in:
parent
fcc808b9f4
commit
9d6e7b79bd
|
@ -7,7 +7,7 @@
|
|||
"name": "token"
|
||||
},
|
||||
"577bcb0c85129a6ff9e4dcde08f04e6f094e94c74a4423fc90e5947df9a21b82": {
|
||||
"address": "0xf88f536ed745bb1242a10c085feb5aca8701711d",
|
||||
"address": "0xb81f1e90ac9e4eb49271c8bbf574dde2b8380078",
|
||||
"name": "SimpleStorage"
|
||||
},
|
||||
"708fa6b699f419627ab3c4c2d9c82f8f1a6fab03c122d0a9ee55d2d0d0ad1e4b": {
|
||||
|
@ -15,7 +15,7 @@
|
|||
"name": "token"
|
||||
},
|
||||
"e0d35d6564373021d9749a7a8815cf58cc5ca7b7edaf4740c1913898561531c3": {
|
||||
"address": "0x7d4d2c27d1ed2d40df055bbc1586c12ce97f19f8",
|
||||
"address": "0x5f6dc5474cd23ff54f37cfa12c78726c2fa1bce6",
|
||||
"name": "SimpleStorage2"
|
||||
},
|
||||
"f3765f8b702ccb44eb19f1adecbf5a216175713fbd41d9fae100d8e3dfc5e74f": {
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
"args": [
|
||||
100,
|
||||
"$token"
|
||||
],
|
||||
"onDeploy": [
|
||||
"SimpleStorage.set(150)"
|
||||
]
|
||||
},
|
||||
"SimpleStorage2": {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
var async = require('async');
|
||||
var Compiler = require('./compiler.js');
|
||||
var DeployTracker = require('./deploy_tracker.js');
|
||||
var ABIGenerator = require('./abi.js');
|
||||
var web3;
|
||||
|
||||
var Deploy = function(options) {
|
||||
this.web3 = options.web3;
|
||||
|
@ -68,6 +70,20 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
|
|||
self.deployTracker.trackContract(contract.className, contract.code, realArgs, address);
|
||||
self.deployTracker.save();
|
||||
self.logger.contractsState(self.contractsManager.contractsState());
|
||||
|
||||
// TODO: replace with separate process so it's isolated and with
|
||||
// a callback
|
||||
if (contract.onDeploy !== undefined) {
|
||||
self.logger.info('executing onDeploy commands');
|
||||
var abiGenerator = new ABIGenerator({}, self.contractsManager);
|
||||
web3 = self.web3;
|
||||
var abi = abiGenerator.generateContracts(false);
|
||||
eval(abi);
|
||||
|
||||
var cmds = contract.onDeploy.join(';\n');
|
||||
eval(cmds);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
|
23
lib/index.js
23
lib/index.js
|
@ -212,16 +212,21 @@ var Embark = {
|
|||
exit();
|
||||
}
|
||||
|
||||
var deploy = new Deploy({
|
||||
web3: web3,
|
||||
contractsManager: contractsManager,
|
||||
logger: Embark.logger,
|
||||
chainConfig: self.config.chainTracker,
|
||||
env: self.config.env
|
||||
});
|
||||
deploy.deployAll(function() {
|
||||
callback(null, contractsManager);
|
||||
web3.eth.getAccounts(function(err, accounts) {
|
||||
web3.eth.defaultAccount = accounts[0];
|
||||
|
||||
var deploy = new Deploy({
|
||||
web3: web3,
|
||||
contractsManager: contractsManager,
|
||||
logger: Embark.logger,
|
||||
chainConfig: self.config.chainTracker,
|
||||
env: self.config.env
|
||||
});
|
||||
deploy.deployAll(function() {
|
||||
callback(null, contractsManager);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
], function(err, result) {
|
||||
done(result);
|
||||
|
|
Loading…
Reference in New Issue