implement onDeploy

This commit is contained in:
Iuri Matias 2016-10-02 17:57:33 -04:00
parent fcc808b9f4
commit 9d6e7b79bd
4 changed files with 35 additions and 11 deletions

View File

@ -7,7 +7,7 @@
"name": "token" "name": "token"
}, },
"577bcb0c85129a6ff9e4dcde08f04e6f094e94c74a4423fc90e5947df9a21b82": { "577bcb0c85129a6ff9e4dcde08f04e6f094e94c74a4423fc90e5947df9a21b82": {
"address": "0xf88f536ed745bb1242a10c085feb5aca8701711d", "address": "0xb81f1e90ac9e4eb49271c8bbf574dde2b8380078",
"name": "SimpleStorage" "name": "SimpleStorage"
}, },
"708fa6b699f419627ab3c4c2d9c82f8f1a6fab03c122d0a9ee55d2d0d0ad1e4b": { "708fa6b699f419627ab3c4c2d9c82f8f1a6fab03c122d0a9ee55d2d0d0ad1e4b": {
@ -15,7 +15,7 @@
"name": "token" "name": "token"
}, },
"e0d35d6564373021d9749a7a8815cf58cc5ca7b7edaf4740c1913898561531c3": { "e0d35d6564373021d9749a7a8815cf58cc5ca7b7edaf4740c1913898561531c3": {
"address": "0x7d4d2c27d1ed2d40df055bbc1586c12ce97f19f8", "address": "0x5f6dc5474cd23ff54f37cfa12c78726c2fa1bce6",
"name": "SimpleStorage2" "name": "SimpleStorage2"
}, },
"f3765f8b702ccb44eb19f1adecbf5a216175713fbd41d9fae100d8e3dfc5e74f": { "f3765f8b702ccb44eb19f1adecbf5a216175713fbd41d9fae100d8e3dfc5e74f": {

View File

@ -12,6 +12,9 @@
"args": [ "args": [
100, 100,
"$token" "$token"
],
"onDeploy": [
"SimpleStorage.set(150)"
] ]
}, },
"SimpleStorage2": { "SimpleStorage2": {

View File

@ -1,6 +1,8 @@
var async = require('async'); var async = require('async');
var Compiler = require('./compiler.js'); var Compiler = require('./compiler.js');
var DeployTracker = require('./deploy_tracker.js'); var DeployTracker = require('./deploy_tracker.js');
var ABIGenerator = require('./abi.js');
var web3;
var Deploy = function(options) { var Deploy = function(options) {
this.web3 = options.web3; 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.trackContract(contract.className, contract.code, realArgs, address);
self.deployTracker.save(); self.deployTracker.save();
self.logger.contractsState(self.contractsManager.contractsState()); 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(); callback();
}); });
} }

View File

@ -212,16 +212,21 @@ var Embark = {
exit(); exit();
} }
var deploy = new Deploy({ web3.eth.getAccounts(function(err, accounts) {
web3: web3, web3.eth.defaultAccount = accounts[0];
contractsManager: contractsManager,
logger: Embark.logger, var deploy = new Deploy({
chainConfig: self.config.chainTracker, web3: web3,
env: self.config.env contractsManager: contractsManager,
}); logger: Embark.logger,
deploy.deployAll(function() { chainConfig: self.config.chainTracker,
callback(null, contractsManager); env: self.config.env
});
deploy.deployAll(function() {
callback(null, contractsManager);
});
}); });
} }
], function(err, result) { ], function(err, result) {
done(result); done(result);