2015-06-09 12:22:18 +00:00
|
|
|
var readYaml = require('read-yaml');
|
|
|
|
var shelljs = require('shelljs');
|
|
|
|
var shelljs_global = require('shelljs/global');
|
|
|
|
var web3 = require('web3');
|
|
|
|
var commander = require('commander');
|
|
|
|
var wrench = require('wrench');
|
2015-10-12 16:25:43 +00:00
|
|
|
var grunt = require('grunt');
|
2015-06-15 10:07:40 +00:00
|
|
|
|
2015-10-08 19:30:47 +00:00
|
|
|
//var Tests = require('./test.js');
|
2015-07-03 11:59:35 +00:00
|
|
|
var Blockchain = require('./blockchain.js');
|
|
|
|
var Deploy = require('./deploy.js');
|
|
|
|
var Release = require('./ipfs.js');
|
|
|
|
var Config = require('./config/config.js');
|
2015-07-04 20:52:05 +00:00
|
|
|
var Compiler = require('./compiler.js');
|
2015-08-04 12:18:04 +00:00
|
|
|
var ChainManager = require('./chain_manager.js');
|
2015-10-09 14:57:30 +00:00
|
|
|
var Test = require('./test.js');
|
2015-06-13 13:02:19 +00:00
|
|
|
|
2015-07-03 11:59:35 +00:00
|
|
|
Embark = {
|
2015-10-09 14:18:18 +00:00
|
|
|
init: function(_web3) {
|
2015-07-04 02:27:17 +00:00
|
|
|
this.blockchainConfig = (new Config.Blockchain());
|
2015-07-04 20:52:05 +00:00
|
|
|
this.compiler = (new Compiler(this.blockchainConfig));
|
2015-07-04 03:23:21 +00:00
|
|
|
this.contractsConfig = (new Config.Contracts(this.blockchainConfig, this.compiler));
|
2015-10-09 14:18:18 +00:00
|
|
|
if (_web3 !== undefined) {
|
|
|
|
this.web3 = _web3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.web3 = web3;
|
|
|
|
}
|
2015-10-09 17:20:35 +00:00
|
|
|
this.chainManager = (new ChainManager());
|
2015-07-04 02:27:17 +00:00
|
|
|
},
|
|
|
|
|
2015-07-13 01:33:36 +00:00
|
|
|
startBlockchain: function(env, use_tmp) {
|
2015-07-04 02:27:17 +00:00
|
|
|
var chain = new Blockchain(this.blockchainConfig.config(env));
|
2015-07-13 01:33:36 +00:00
|
|
|
chain.startChain(use_tmp);
|
2015-07-04 02:27:17 +00:00
|
|
|
},
|
|
|
|
|
2015-09-03 10:36:25 +00:00
|
|
|
copyMinerJavascriptToTemp: function(){
|
|
|
|
//TODO: better with --exec, but need to fix console bug first
|
|
|
|
wrench.copyDirSyncRecursive(__dirname + "/../js", "/tmp/js", {forceDelete: true});
|
|
|
|
},
|
|
|
|
|
2015-08-30 16:48:38 +00:00
|
|
|
getStartBlockchainCommand: function(env, use_tmp) {
|
|
|
|
var chain = new Blockchain(this.blockchainConfig.config(env));
|
|
|
|
return chain.getStartChainCommand(use_tmp);
|
|
|
|
},
|
|
|
|
|
2015-10-09 17:20:35 +00:00
|
|
|
deployContracts: function(env, contractFiles, destFile, chainFile, withProvider, withChain, cb) {
|
2015-08-01 15:19:21 +00:00
|
|
|
this.contractsConfig.init(contractFiles, env);
|
2015-08-04 01:54:39 +00:00
|
|
|
|
|
|
|
this.chainManager.loadConfigFile(chainFile)
|
2015-10-09 17:20:35 +00:00
|
|
|
var deploy = new Deploy(env, contractFiles, this.blockchainConfig.config(env), this.contractsConfig, this.chainManager, withProvider, withChain, this.web3);
|
2015-10-08 19:30:47 +00:00
|
|
|
deploy.deploy_contracts(env, function() {
|
|
|
|
console.log("contracts deployed; generating abi file");
|
2015-10-09 14:18:18 +00:00
|
|
|
var result = ""
|
|
|
|
if (withProvider) {
|
|
|
|
result += deploy.generate_provider_file();
|
|
|
|
}
|
|
|
|
result += deploy.generate_abi_file();
|
2015-10-08 19:30:47 +00:00
|
|
|
cb(result);
|
|
|
|
});
|
2015-07-04 02:27:17 +00:00
|
|
|
},
|
|
|
|
|
2015-08-18 10:05:20 +00:00
|
|
|
geth: function(env, args) {
|
|
|
|
var chain = new Blockchain(this.blockchainConfig.config(env));
|
|
|
|
chain.execGeth(args);
|
|
|
|
},
|
|
|
|
|
2015-10-09 14:57:30 +00:00
|
|
|
release: Release,
|
|
|
|
|
2015-10-12 14:50:52 +00:00
|
|
|
initTests: function() {
|
2015-10-12 16:25:43 +00:00
|
|
|
var embarkConfig = readYaml.sync("./embark.yml");
|
|
|
|
var fileExpression = embarkConfig.contracts || ["app/contracts/**/*.sol", "app/contracts/**/*.se"];
|
|
|
|
var contractFiles = grunt.file.expand(fileExpression);
|
|
|
|
var tests = new Test(contractFiles, 'development');
|
2015-10-12 14:50:52 +00:00
|
|
|
|
|
|
|
return tests;
|
2015-10-09 14:57:30 +00:00
|
|
|
}
|
2015-07-03 11:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Embark;
|