remove old files

This commit is contained in:
Iuri Matias 2016-10-02 16:58:52 -04:00
parent ed6b1fd5c2
commit fb41ce8a66
11 changed files with 1 additions and 1094 deletions

View File

@ -31,3 +31,4 @@ Release = {
module.exports = Release

View File

@ -1,190 +0,0 @@
var mkdirp = require('mkdirp');
Blockchain = function(blockchainConfig) {
this.config = blockchainConfig;
}
Blockchain.prototype.generate_genesis_init_command = function() {
var config = this.config;
var address = config.account.address;
var cmd = "geth ";
if (config.datadir !== "default") {
cmd += "--datadir=\"" + config.datadir + "\" ";
}
cmd += "init \"" + config.genesisBlock + "\" ";
return cmd;
}
Blockchain.prototype.generate_init_command = function() {
var config = this.config;
var address = config.account.address;
var cmd = "geth ";
if (config.datadir !== "default") {
cmd += "--datadir=\"" + config.datadir + "\" ";
}
if (config.account.password !== void 0) {
cmd += "--password " + config.account.password + " ";
}
return cmd;
}
Blockchain.prototype.generate_basic_command = function() {
var config = this.config;
var address = config.account.address;
var cmd = "geth ";
var rpc_api = ['eth', 'web3'];
if (config.datadir !== "default") {
cmd += "--datadir=\"" + config.datadir + "\" ";
}
if (config.testnet) {
cmd += "--testnet ";
}
if (config.account.password !== void 0) {
cmd += "--password " + config.account.password + " ";
}
if (config.geth_extra_opts) {
cmd += config.geth_extra_opts + " ";
}
cmd += "--port " + config.port + " ";
cmd += "--rpc ";
cmd += "--rpcport " + config.rpcPort + " ";
cmd += "--rpcaddr " + config.rpcHost + " ";
cmd += "--networkid " + config.networkId + " ";
cmd += "--rpccorsdomain=\"" + config.rpcWhitelist + "\" ";
if(config.testnet){
cmd += "--testnet "
}
if (config.minerthreads !== void 0) {
cmd += "--minerthreads \"" + config.minerthreads + "\" ";
}
if(config.mine_when_needed || config.mine)
cmd += "--mine ";
if (config.whisper) {
cmd += "--shh ";
rpc_api.push('shh')
}
cmd += '--rpcapi "' + rpc_api.join(',') + '" ';
//TODO: this should be configurable
cmd += "--maxpeers " + config.maxPeers + " ";
return cmd;
}
Blockchain.prototype.list_command = function() {
return this.generate_init_command() + "account list ";
}
Blockchain.prototype.init_command = function() {
return this.generate_init_command() + "account new ";
}
Blockchain.prototype.geth_command = function(geth_args) {
return this.generate_basic_command() + geth_args;
}
Blockchain.prototype.run_command = function(address, use_tmp) {
var cmd = this.generate_basic_command();
var config = this.config;
if (address !== void 0) {
cmd += "--unlock=" + address + " ";
}
if (config.bootNodes !== undefined && config.bootNodes.boot == true) {
cmd += "--bootnodes \"";
for (var i = 0; i < config.bootNodes.enodes.length; i++){
cmd += config.bootNodes.enodes[i];
if (i != config.bootNodes.enodes.length - 1) cmd += " ";
}
cmd += "\"";
}
if (config.mine_when_needed) {
if (use_tmp) {
cmd += "js /tmp/js/mine.js";
}
else {
cmd += "js node_modules/embark-framework/js/mine.js";
}
}
return cmd;
}
Blockchain.prototype.get_address = function() {
var config = this.config;
if(config.account.address)
return config.account.address;
var address = null;
if (config.account.init) {
// ensure datadir exists, bypassing the interactive liabilities prompt.
var newDir = mkdirp.sync(config.datadir);
if (newDir) {
console.log("=== datadir created");
} else {
console.log("=== datadir already exists");
}
console.log("running: " + this.list_command());
result = exec(this.list_command());
if (result.output === undefined || result.output === '' || result.output.indexOf("Fatal") >= 0) {
if (config.genesisBlock !== void 0) {
console.log("initializing genesis block")
console.log("running: " + this.generate_genesis_init_command());
result = exec(this.generate_genesis_init_command());
}
console.log("running: " + this.init_command());
result = exec(this.init_command());
address = result.output.match(/{(\w+)}/)[1];
} else {
console.log("=== already initialized");
address = result.output.match(/{(\w+)}/)[1];
}
}
return address;
}
Blockchain.prototype.startChain = function(use_tmp) {
var address = this.get_address();
console.log("running: " + this.run_command(address, use_tmp));
exec(this.run_command(address, use_tmp));
}
Blockchain.prototype.execGeth = function(args) {
var cmd = this.geth_command(args);
console.log("executing: " + cmd);
exec(cmd);
}
Blockchain.prototype.getStartChainCommand = function(use_tmp) {
var address = this.get_address();
return this.run_command(address, use_tmp);
}
module.exports = Blockchain

View File

@ -1,55 +0,0 @@
var fs = require('fs');
var sha3_256 = require('js-sha3').sha3_256;
ChainManager = function() {
this.chainManagerConfig = {};
this.currentChain = {};
this.file = "";
}
ChainManager.prototype.loadConfigFile = function(filename) {
this.file = filename;
try {
var obj = JSON.parse(fs.readFileSync(filename));
this.chainManagerConfig = obj;
} catch (e) {
console.warn("error reading " + filename + "; defaulting to empty set");
}
return this;
};
ChainManager.prototype.loadConfig = function(config) {
this.chainManagerConfig = config;
return this;
};
ChainManager.prototype.init = function(env, config, web3) {
var block = web3.eth.getBlock(0);
if(!block){
throw new Error("Cannot get the genesis block, is embark blockchain running ?");
}
var chainId = block.hash;
if (this.chainManagerConfig[chainId] === undefined) {
this.chainManagerConfig[chainId] = {contracts: {}};
}
this.currentChain = this.chainManagerConfig[chainId];
}
ChainManager.prototype.addContract = function(contractName, code, args, address) {
this.currentChain.contracts[sha3_256(code + contractName + args.join(','))] = {
name: contractName,
address: address
}
}
ChainManager.prototype.getContract = function(contractName, code, args) {
return this.currentChain.contracts[sha3_256(code + contractName + args.join(','))];
}
ChainManager.prototype.save = function() {
fs.writeFileSync(this.file, JSON.stringify(this.chainManagerConfig));
}
module.exports = ChainManager;

View File

@ -1,110 +0,0 @@
var shelljs = require('shelljs');
var shelljs_global = require('shelljs/global');
var web3 = require('web3');
var fs = require('fs');
var solc = require('solc');
Compiler = function(blockchainConfig) {
this.blockchainConfig = blockchainConfig;
};
Compiler.prototype.init = function(env) {
var config = this.blockchainConfig.config(env);
};
Compiler.prototype.compile_solidity = function(contractFiles) {
var input = {}
for (var i = 0; i < contractFiles.length; i++){
var filename = contractFiles[i].replace('app/contracts/','');
input[filename] = fs.readFileSync(contractFiles[i]).toString();
}
var output = solc.compile({sources: input}, 1);
if (output.errors)
throw new Error ("Solidity errors: " + output.errors)
var json = output.contracts;
compiled_object = {}
for (var className in json) {
var contract = json[className];
compiled_object[className] = {};
compiled_object[className].code = contract.bytecode;
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
compiled_object[className].info = {};
compiled_object[className].info.abiDefinition = JSON.parse(contract.interface);
}
return compiled_object;
};
Compiler.prototype.compile_serpent = function(contractFiles) {
var cmd, result, output, json, compiled_object;
//TODO: figure out how to compile multiple files and get the correct json
var contractFile = contractFiles[0];
cmd = "serpent compile " + contractFile;
result = exec(cmd, {silent: true});
code = result.output;
if (result.code === 1) {
throw new Error(result.output);
}
cmd = "serpent mk_full_signature " + contractFile;
result = exec(cmd, {silent: true});
if (result.code === 1) {
throw new Error(result.output);
}
json = JSON.parse(result.output.trim());
className = contractFile.split('.')[0].split("/").pop();
for (var i=0; i < json.length; i++) {
var elem = json[i];
if (elem.outputs.length > 0) {
elem.constant = true;
}
}
compiled_object = {}
compiled_object[className] = {};
compiled_object[className].code = code.trim();
compiled_object[className].info = {};
compiled_object[className].info.abiDefinition = json;
return compiled_object;
}
Compiler.prototype.compile = function(contractFiles) {
var solidity = [], serpent = [];
for (var i = 0; i < contractFiles.length; i++) {
var contractParts = contractFiles[i].split('.'),
extension = contractParts[contractParts.length-1]
if (extension === 'sol') {
solidity.push(contractFiles[i]);
}
else if (extension === 'se') {
serpent.push(contractFiles[i]);
}
else {
throw new Error("extension not known, got " + extension);
}
}
//TODO: Get these compiling and returning together...problem might come with the JSON objects
if (solidity.length > 0) return this.compile_solidity(solidity);
if (serpent.length > 0) return this.compile_serpent(serpent);
};
module.exports = Compiler;

View File

@ -1,65 +0,0 @@
var readYaml = require('read-yaml');
BlockchainConfig = function() {};
BlockchainConfig.prototype.loadConfigFile = function(filename) {
try {
this.blockchainConfig = readYaml.sync(filename);
} catch (e) {
throw new Error("error reading " + filename);
}
return this;
};
BlockchainConfig.prototype.loadConfig = function(config) {
this.blockchainConfig = config;
return this;
};
BlockchainConfig.prototype.config = function(env) {
if (this.blockchainConfig === null) {
throw new Error("no blockchain config found");
}
var config = this.blockchainConfig[env || "development"];
var networkId;
if (config.network_id === undefined) {
networkId = Math.floor((Math.random() * 100000) + 1000);
}
else {
networkId = config.network_id;
}
config = {
testnet: false,
rpcHost: config.rpc_host,
rpcPort: config.rpc_port,
gasLimit: config.gas_limit || 500000,
gasPrice: config.gas_price || 10000000000000,
rpcWhitelist: config.rpc_whitelist,
nat: config.nat || [],
minerthreads: config.minerthreads,
genesisBlock: config.genesis_block,
datadir: config.datadir,
chains: config.chains,
bootNodes: config.bootnodes || [],
deployTimeout: config.deploy_timeout || 20,
networkId: networkId,
maxPeers: config.max_peers || 4,
mine: config.mine || false,
port: config.port || "30303",
console_toggle: config.console || false,
mine_when_needed: config.mine_when_needed || false,
whisper: config.whisper || false,
account: config.account,
geth_extra_opts: config.geth_extra_opts || [],
testnet: config.testnet || false,
deploy_synchronously: config.deploy_synchronously || false
}
return config;
};
module.exports = BlockchainConfig;

View File

@ -1,12 +0,0 @@
var readYaml = require('read-yaml');
BlockchainConfig = require('./blockchain.js');
ContractsConfig = require('./contracts.js');
config = {
Blockchain: BlockchainConfig,
Contracts: ContractsConfig
}
module.exports = config

View File

@ -1,164 +0,0 @@
var readYaml = require('read-yaml');
var fs = require('fs');
var toposort = require('toposort');
ContractsConfig = function(blockchainConfig, compiler) {
this.blockchainConfig = blockchainConfig;
this.compiler = compiler;
this.contractFiles = [];
}
ContractsConfig.prototype.init = function(files, env) {
this.all_contracts = [];
this.contractDB = {};
this.contractFiles = files;
this.contractDependencies = {};
this.contractStubs = {};
//TODO: have to specify environment otherwise wouldn't work with staging
if (this.blockchainConfig.config != undefined) {
//this.blockchainConfig = this.blockchainConfig.config('development');
this.blockchainConfig = this.blockchainConfig.config(env);
}
};
ContractsConfig.prototype.loadConfigFile = function(filename) {
try {
this.contractConfig = readYaml.sync(filename);
} catch (e) {
throw new Error("error reading " + filename);
}
return this;
};
ContractsConfig.prototype.loadConfig = function(config) {
this.contractConfig = config;
return this;
};
ContractsConfig.prototype.config = function(env) {
return this.contractConfig[env];
};
ContractsConfig.prototype.is_a_interface = function(target, className) {
if (this.contractStubs[className] && this.contractStubs[className].indexOf(target) >= 0)
return true;
return false;
};
ContractsConfig.prototype.compileContracts = function(env) {
var contractFile, source, j;
var contractsConfig = this.config(env);
this.compiler.init(env);
// determine dependencies
if (contractsConfig != null) {
for (className in contractsConfig) {
options = contractsConfig[className];
if (options.args == null) continue;
ref = options.args; //get arguments
for (j = 0; j < ref.length; j++) {
arg = ref[j];
if (arg[0] === "$") { //check if they are a contract dependency
if (this.contractDependencies[className] === void 0) {
this.contractDependencies[className] = [];
}
this.contractDependencies[className].push(arg.substr(1));
}
}
this.contractStubs[className] = options.stubs;
}
}
compiled_contracts = this.compiler.compile(this.contractFiles); //compile and push to contract DB
for (var className in compiled_contracts) {
if (this.is_a_interface(className, compiled_contracts)) {
continue;
}
this.all_contracts.push(className);
this.contractDB[className] = {
args: [],
types: ['file'],
gasPrice: this.blockchainConfig.gasPrice,
gasLimit: this.blockchainConfig.gasLimit,
compiled: compiled_contracts[className]
}
}
this.configureContractsParameters(contractsConfig);
this.sortContracts();
};
ContractsConfig.prototype.configureContractsParameters = function(contractsConfig) {
for(className in contractsConfig) {
var contractConfig = contractsConfig[className];
var contract;
contract = this.contractDB[className];
if (contract === undefined) {
contract = {
args: [],
types: ['file'],
gasPrice: this.blockchainConfig.gasPrice,
gasLimit: this.blockchainConfig.gasLimit,
compiled: contract
}
this.contractDB[className] = contract;
}
contract.gasPrice = contractConfig.gas_price || contract.gasPrice;
contract.gasLimit = contractConfig.gas_limit || contract.gasLimit;
contract.args = contractConfig.args || [];
contract.address = contractConfig.address;
contract.onDeploy = contractConfig.onDeploy || [];
if (contractConfig.instanceOf !== undefined) {
contract.types.push('instance');
contract.instanceOf = contractConfig.instanceOf;
contract.compiled = compiled_contracts[contractConfig.instanceOf];
}
if (contractConfig.address !== undefined) {
contract.types.push('static');
}
contract.deploy = contractConfig.deploy;
if (contractConfig.deploy === undefined) {
contract.deploy = true;
}
if (this.all_contracts.indexOf(className) < 0) {
this.all_contracts.push(className);
}
}
}
ContractsConfig.prototype.sortContracts = function() {
var converted_dependencies = [], i;
for(contract in this.contractDependencies) {
var dependencies = this.contractDependencies[contract];
for(i=0; i < dependencies.length; i++) {
converted_dependencies.push([contract, dependencies[i]]);
}
}
var orderedDependencies = toposort(converted_dependencies).reverse();
this.all_contracts = this.all_contracts.sort(function(a,b) {
var order_a = orderedDependencies.indexOf(a);
var order_b = orderedDependencies.indexOf(b);
return order_a - order_b;
});;
};
module.exports = ContractsConfig;

View File

@ -1,239 +0,0 @@
var web3 = require('web3');
var fs = require('fs');
var grunt = require('grunt');
var readYaml = require('read-yaml');
var Config = require('./config/config.js');
var BigNumber = require('bignumber.js');
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig, chainManager, withProvider, withChain, _web3) {
if (_web3 !== undefined) {
web3 = _web3;
}
this.contractsManager = contractsConfig;
this.contractsConfig = this.contractsManager.config(env);
this.deployedContracts = {};
this.blockchainConfig = blockchainConfig;
try {
if (withProvider) {
web3.setProvider(new web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
}
primaryAddress = web3.eth.coinbase;
web3.eth.defaultAccount = primaryAddress;
} catch (e) {
throw new Error("==== can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
}
this.chainManager = chainManager;
this.chainManager.init(env, this.blockchainConfig, web3);
this.withChain = withChain;
console.log("primary account address is : " + primaryAddress);
};
Deploy.waitForContract = function(transactionHash, cb) {
web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
if (!e && receipt && receipt.contractAddress !== undefined) {
cb(receipt.contractAddress);
}
else {
Deploy.waitForContract(transactionHash, cb);
}
});
};
Deploy.prototype.deploy_contract = function(contractObject, contractParams, cb) {
var callback = function(e, contract) {
if(!e && contract.address !== undefined) {
cb(contract.address);
}
else {
Deploy.waitForContract(contract.transactionHash, cb);
}
};
contractParams.push(callback);
contractObject["new"].apply(contractObject, contractParams);
}
Deploy.prototype.deploy_contracts = function(env, cb) {
this.contractsManager.compileContracts(env);
var all_contracts = this.contractsManager.all_contracts;
this.contractDB = this.contractsManager.contractDB;
this.deployedContracts = {};
if(this.blockchainConfig.deploy_synchronously)
this.deploy_contract_list_synchronously(env, all_contracts, cb);
else
this.deploy_contract_list(all_contracts.length, env, all_contracts, cb);
}
Deploy.prototype.deploy_contract_list = function(index, env, all_contracts, cb) {
if(index === 0) {
cb();
}
else {
var _this = this;
this.deploy_contract_list(index - 1, env, all_contracts, function() {
var className = all_contracts[index - 1];
_this.deploy_a_contract(env, className, cb);
});
}
}
Deploy.prototype.deploy_contract_list_synchronously = function(env, all_contracts, cb) {
var _this = this
,deployed_contracts_count = 0
all_contracts.forEach(function(className){
_this.deploy_a_contract(env, className, function(){
mark_contract_as_deployed()
});
})
function mark_contract_as_deployed(){
deployed_contracts_count ++;
if(deployed_contracts_count === all_contracts.length)
cb()
}
}
Deploy.prototype.deploy_a_contract = function(env, className, cb) {
var contractDependencies = this.contractsManager.contractDependencies;
var contract = this.contractDB[className];
if (contract.deploy === false) {
console.log("skipping " + className);
cb();
return;
}
var realArgs = [];
for (var l = 0; l < contract.args.length; l++) {
arg = contract.args[l];
if (arg[0] === "$") {
realArgs.push(this.deployedContracts[arg.substr(1)]);
} else {
realArgs.push(arg);
}
}
if (contract.address !== undefined) {
this.deployedContracts[className] = contract.address;
console.log("contract " + className + " at " + contract.address);
cb();
}
else {
var chainContract = this.chainManager.getContract(className, contract.compiled.code, realArgs);
if (chainContract != undefined && web3.eth.getCode(chainContract.address) !== "0x") {
console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address);
this.deployedContracts[className] = chainContract.address;
this.execute_cmds(contract.onDeploy);
cb();
}
else {
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
contractParams = realArgs.slice();
contractParams.push({
from: primaryAddress,
data: contract.compiled.code,
gas: contract.gasLimit,
gasPrice: contract.gasPrice
});
console.log('trying to obtain ' + className + ' address...');
var _this = this;
this.deploy_contract(contractObject, contractParams, function(contractAddress) {
if (web3.eth.getCode(contractAddress) === "0x") {
console.log("=========");
console.log("contract was deployed at " + contractAddress + " but doesn't seem to be working");
console.log("try adjusting your gas values");
console.log("=========");
}
else {
console.log("deployed " + className + " at " + contractAddress);
_this.chainManager.addContract(className, contract.compiled.code, realArgs, contractAddress);
if (_this.withChain) {
_this.chainManager.save();
}
}
_this.deployedContracts[className] = contractAddress;
_this.execute_cmds(contract.onDeploy);
cb();
});
}
}
};
Deploy.prototype.execute_cmds = function(cmds) {
if (cmds == undefined || cmds.length === 0) return;
eval(this.generate_abi_file());
for (var i = 0; i < cmds.length; i++) {
var cmd = cmds[i];
for(className in this.deployedContracts) {
var contractAddress = this.deployedContracts[className];
var re = new RegExp("\\$" + className, 'g');
cmd = cmd.replace(re, '"' + contractAddress + '"');
}
console.log("executing: " + cmd);
eval(cmd);
}
};
Deploy.prototype.generate_provider_file = function() {
var result = "";
result += "if (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {";
result += 'web3 = new Web3(web3.currentProvider);';
result += "} else if (typeof Web3 !== 'undefined') {";
result += 'web3 = new Web3(new Web3.providers.HttpProvider("http://' + this.blockchainConfig.rpcHost + ':' + this.blockchainConfig.rpcPort + '"));';
result += '}';
result += "web3.eth.defaultAccount = web3.eth.accounts[0];";
return result;
};
Deploy.prototype.generate_abi_file = function() {
var result = "";
result += 'blockchain = '+JSON.stringify(this.blockchainConfig)+';';
for(className in this.deployedContracts) {
var deployedContract = this.deployedContracts[className];
var contract = this.contractDB[className];
var abi = JSON.stringify(contract.compiled.info.abiDefinition);
var contractAddress = deployedContract;
console.log('address is ' + contractAddress);
result += className + "Abi = " + abi + ";";
result += className + "Contract = web3.eth.contract(" + className + "Abi);";
result += className + " = " + className + "Contract.at('" + contractAddress + "');";
}
result += 'contractDB = '+JSON.stringify(this.contractDB)+';'
return result;
};
Deploy.prototype.generate_and_write_abi_file = function(destFile) {
var result = this.generate_abi_file();
grunt.file.write(destFile, result);
};
module.exports = Deploy;

View File

@ -1,97 +0,0 @@
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');
var grunt = require('grunt');
var async = require('async');
//var Tests = require('./test.js');
var Blockchain = require('./blockchain.js');
var Deploy = require('./deploy.js');
var SingleDeploy = require('./single_deploy.js');
var Release = require('./ipfs.js');
var Config = require('./config/config.js');
var Compiler = require('./compiler.js');
var ChainManager = require('./chain_manager.js');
var Test = require('./test.js');
Embark = {
init: function(_web3) {
this.blockchainConfig = (new Config.Blockchain());
this.compiler = (new Compiler(this.blockchainConfig));
this.contractsConfig = (new Config.Contracts(this.blockchainConfig, this.compiler));
if (_web3 !== undefined) {
this.web3 = _web3;
}
else {
this.web3 = new Web3();
}
this.chainManager = (new ChainManager());
},
startBlockchain: function(env, use_tmp) {
var chain = new Blockchain(this.blockchainConfig.config(env));
chain.startChain(use_tmp);
},
copyMinerJavascriptToTemp: function(){
//TODO: better with --exec, but need to fix console bug first
wrench.copyDirSyncRecursive(__dirname + "/../js", "/tmp/js", {forceDelete: true});
},
getStartBlockchainCommand: function(env, use_tmp) {
var chain = new Blockchain(this.blockchainConfig.config(env));
return chain.getStartChainCommand(use_tmp);
},
deployContracts: function(env, contractFiles, destFile, chainFile, withProvider, withChain, cb) {
this.contractsConfig.init(contractFiles, env);
this.chainManager.loadConfigFile(chainFile)
var deploy = new Deploy(env, contractFiles, this.blockchainConfig.config(env), this.contractsConfig, this.chainManager, withProvider, withChain, this.web3);
deploy.deploy_contracts(env, function() {
console.log("contracts deployed; generating abi file");
var result = ""
if (withProvider) {
result += deploy.generate_provider_file();
}
result += deploy.generate_abi_file();
cb(result);
});
},
geth: function(env, args) {
var chain = new Blockchain(this.blockchainConfig.config(env));
chain.execGeth(args);
},
deployContract: function(contractFiles, className, args, cb) {
var compiledContracts = this.compiler.compile_solidity(contractFiles);
var config = this.blockchainConfig.config('development');
var deploy = new SingleDeploy(compiledContracts, config.gasLimit, config.gasPrice, this.web3);
deploy.deploy_a_contract(className, args, function() {
var result = "";
result += deploy.generate_abi_file();
cb(result);
});
},
release: Release,
initTests: function() {
var embarkConfig = readYaml.sync("./embark.yml");
var fileExpression = embarkConfig.contracts || ["app/contracts/**/*.sol", "app/contracts/**/*.se"];
var contractFiles = grunt.file.expand(fileExpression);
var blockchainFile = embarkConfig.blockchainConfig || 'config/blockchain.yml';
var contractFile = embarkConfig.contractsConfig || 'config/contracts.yml';
var tests = new Test(contractFiles, blockchainFile, contractFile, 'development');
return tests;
}
}
module.exports = Embark;

View File

@ -1,116 +0,0 @@
var web3 = require('web3');
var fs = require('fs');
var grunt = require('grunt');
var readYaml = require('read-yaml');
var Compiler = require('./compiler.js');
var Config = require('./config/config.js');
var BigNumber = require('bignumber.js');
// this is a temporary module to deploy a single contract, will be refactored
SingleDeploy = function(compiledContracts, gasLimit, gasPrice, _web3) {
if (_web3 !== undefined) {
web3 = _web3;
}
this.compiledContracts = compiledContracts;
this.gasLimit = gasLimit;
this.gasPrice = gasPrice;
this.deployedContracts = {};
web3.eth.defaultAccount = web3.eth.coinbase;
};
SingleDeploy.waitForContract = function(transactionHash, cb) {
web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
if (!e && receipt && receipt.contractAddress !== undefined) {
cb(receipt.contractAddress);
}
else {
SingleDeploy.waitForContract(transactionHash, cb);
}
});
};
SingleDeploy.prototype.deploy_contract = function(contractObject, contractParams, cb) {
var callback = function(e, contract) {
if(!e && contract.address !== undefined) {
cb(contract.address);
}
else {
SingleDeploy.waitForContract(contract.transactionHash, cb);
}
};
contractParams.push(callback);
contractObject["new"].apply(contractObject, contractParams);
};
SingleDeploy.prototype.deploy_a_contract = function(className, args, cb) {
var self = this;
var contract = this.compiledContracts[className];
var contractObject = web3.eth.contract(contract.info.abiDefinition);
contractParams = args.slice();
contractParams.push({
from: web3.eth.coinbase,
data: contract.code,
gas: this.gasLimit,
gasPrice: this.gasPrice
});
console.log('trying to obtain ' + className + ' address...');
this.deploy_contract(contractObject, contractParams, function(contractAddress) {
if (web3.eth.getCode(contractAddress) === "0x") {
console.log("=========");
console.log("contract was deployed at " + contractAddress + " but doesn't seem to be working");
console.log("try adjusting your gas values");
console.log("=========");
}
self.deployedContracts[className] = contractAddress;
cb();
});
};
SingleDeploy.prototype.generate_provider_file = function() {
var result = "";
result += "if (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {";
result += 'web3 = new Web3(web3.currentProvider);';
result += "} else if (typeof Web3 !== 'undefined') {";
result += 'web3 = new Web3(new Web3.providers.HttpProvider("http://' + this.blockchainConfig.rpcHost + ':' + this.blockchainConfig.rpcPort + '"));';
result += '}';
result += "web3.eth.defaultAccount = web3.eth.accounts[0];";
return result;
};
SingleDeploy.prototype.generate_abi_file = function() {
var result = "";
result += 'blockchain = '+JSON.stringify(this.blockchainConfig)+';';
for(className in this.deployedContracts) {
var deployedContract = this.deployedContracts[className];
var contract = this.compiledContracts[className];
var abi = JSON.stringify(contract.info.abiDefinition);
var contractAddress = deployedContract;
console.log('address is ' + contractAddress);
result += className + "Abi = " + abi + ";";
result += className + "Contract = web3.eth.contract(" + className + "Abi);";
result += className + " = " + className + "Contract.at('" + contractAddress + "');";
}
result += 'contractDB = '+JSON.stringify(this.contractDB)+';'
return result;
};
SingleDeploy.prototype.generate_and_write_abi_file = function(destFile) {
var result = this.generate_abi_file();
grunt.file.write(destFile, result);
};
module.exports = SingleDeploy;

View File

@ -1,46 +0,0 @@
try {
var EtherSim = require('ethersim');
} catch(e) {
var EtherSim = false;
}
var Web3 = require('web3');
var web3
Test = function(contractFiles, blockchainFile, contractFile, _env) {
if (EtherSim === false) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim');
exit();
}
this.env = _env || 'development';
this.web3 = new Web3();
this.sim = new EtherSim.init();
this.web3.setProvider(this.sim.provider);
this.contractFiles = contractFiles;
Embark.init(this.web3);
Embark.blockchainConfig.loadConfigFile(blockchainFile);
Embark.contractsConfig.loadConfigFile(contractFile);
Embark.contractsConfig.init(this.contractFiles, this.env);
}
Test.prototype.deployAll = function(cb) {
var web3 = this.web3;
Embark.deployContracts('development', this.contractFiles, "/tmp/abi.js", "chains.json", false, false, function(abi) {
eval(abi);
cb();
});
}
Test.prototype.deployContract = function(className, args, cb) {
var web3 = this.web3;
Embark.deployContract(this.contractFiles, className, args, function(abi) {
eval(abi);
cb();
});
};
module.exports = Test;