2016-08-13 14:48:00 +00:00
|
|
|
var async = require('async');
|
2016-08-14 12:04:34 +00:00
|
|
|
var Compiler = require('./compiler.js');
|
2016-08-13 14:48:00 +00:00
|
|
|
|
2016-09-17 03:56:25 +00:00
|
|
|
var Deploy = function(web3, contractsManager, logger) {
|
2016-08-14 12:04:34 +00:00
|
|
|
this.web3 = web3;
|
|
|
|
this.contractsManager = contractsManager;
|
2016-09-17 03:56:25 +00:00
|
|
|
this.logger = logger;
|
2016-08-14 12:04:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Deploy.prototype.deployContract = function(contract, params, callback) {
|
2016-09-17 03:56:25 +00:00
|
|
|
var self = this;
|
2016-08-14 12:04:34 +00:00
|
|
|
var contractObject = this.web3.eth.contract(contract.abiDefinition);
|
2015-10-09 17:20:35 +00:00
|
|
|
|
2016-08-14 12:04:34 +00:00
|
|
|
var contractParams = params || contract.args;
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2016-08-13 14:48:00 +00:00
|
|
|
contractParams.push({
|
2016-08-14 12:04:34 +00:00
|
|
|
from: this.web3.eth.coinbase,
|
|
|
|
data: contract.code,
|
2016-08-13 14:48:00 +00:00
|
|
|
gas: contract.gasLimit,
|
|
|
|
gasPrice: contract.gasPrice
|
2016-05-30 00:14:27 +00:00
|
|
|
});
|
2016-08-14 12:04:34 +00:00
|
|
|
|
|
|
|
contractParams.push(function(err, transaction) {
|
|
|
|
if (err) {
|
2016-09-17 03:56:25 +00:00
|
|
|
self.logger.info("error");
|
2016-08-14 12:04:34 +00:00
|
|
|
callback(new Error(err));
|
|
|
|
} else if (transaction.address !== undefined) {
|
2016-09-17 03:56:25 +00:00
|
|
|
self.logger.info("address contract: " + transaction.address);
|
2016-08-14 12:04:34 +00:00
|
|
|
contract.deployedAddress = transaction.address;
|
|
|
|
callback(null, transaction.address);
|
|
|
|
}
|
|
|
|
});
|
2015-08-04 12:18:04 +00:00
|
|
|
|
2016-08-13 14:48:00 +00:00
|
|
|
contractObject["new"].apply(contractObject, contractParams);
|
2016-08-10 00:50:12 +00:00
|
|
|
};
|
2015-10-09 14:18:18 +00:00
|
|
|
|
2016-08-14 12:04:34 +00:00
|
|
|
Deploy.prototype.deployAll = function(done) {
|
|
|
|
var self = this;
|
2016-09-17 03:56:25 +00:00
|
|
|
this.logger.info("deployAll");
|
2016-08-14 12:04:34 +00:00
|
|
|
|
|
|
|
async.eachOfSeries(this.contractsManager.listContracts(),
|
|
|
|
function(contract, key, callback) {
|
2016-09-17 03:56:25 +00:00
|
|
|
self.logger.info(arguments);
|
2016-08-14 12:04:34 +00:00
|
|
|
self.deployContract(contract, null, callback);
|
|
|
|
},
|
|
|
|
function(err, results) {
|
2016-09-17 03:56:25 +00:00
|
|
|
self.logger.info("finished");
|
|
|
|
self.logger.info(arguments);
|
2016-08-14 12:04:34 +00:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Deploy;
|
2015-06-28 02:20:07 +00:00
|
|
|
|