embark/lib/deploy.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

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-08-14 12:04:34 +00:00
var Deploy = function(web3, contractsManager) {
this.web3 = web3;
this.contractsManager = contractsManager;
};
Deploy.prototype.deployContract = function(contract, params, callback) {
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;
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) {
console.log("error");
callback(new Error(err));
} else if (transaction.address !== undefined) {
console.log("address contract: " + transaction.address);
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-14 12:04:34 +00:00
Deploy.prototype.deployAll = function(done) {
var self = this;
console.log("deployAll");
async.eachOfSeries(this.contractsManager.listContracts(),
function(contract, key, callback) {
console.log(arguments);
self.deployContract(contract, null, callback);
},
function(err, results) {
console.log("finished");
console.log(arguments);
done();
}
);
};
module.exports = Deploy;