mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-24 03:58:13 +00:00
Merge branch 'develop' of github.com:ethereum/web3.js into develop
This commit is contained in:
commit
bc45b70e96
@ -166,6 +166,62 @@ var ContractFactory = function (eth, abi) {
|
||||
this.eth = eth;
|
||||
this.abi = abi;
|
||||
|
||||
/**
|
||||
* Should be called to create new contract on a blockchain
|
||||
*
|
||||
* @method new
|
||||
* @param {Any} contract constructor param1 (optional)
|
||||
* @param {Any} contract constructor param2 (optional)
|
||||
* @param {Object} contract transaction object (required)
|
||||
* @param {Function} callback
|
||||
* @returns {Contract} returns contract instance
|
||||
*/
|
||||
this.new = function () {
|
||||
var contract = new Contract(this.eth, this.abi);
|
||||
|
||||
// parse arguments
|
||||
var options = {}; // required!
|
||||
var callback;
|
||||
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if (utils.isFunction(args[args.length - 1])) {
|
||||
callback = args.pop();
|
||||
}
|
||||
|
||||
var last = args[args.length - 1];
|
||||
if (utils.isObject(last) && !utils.isArray(last)) {
|
||||
options = args.pop();
|
||||
}
|
||||
|
||||
var bytes = encodeConstructorParams(this.abi, args);
|
||||
options.data += bytes;
|
||||
|
||||
if (callback) {
|
||||
|
||||
// wait for the contract address adn check if the code was deployed
|
||||
this.eth.sendTransaction(options, function (err, hash) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
// add the transaction hash
|
||||
contract.transactionHash = hash;
|
||||
|
||||
// call callback for the first time
|
||||
callback(null, contract);
|
||||
|
||||
checkForContractAddress(contract, callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var hash = this.eth.sendTransaction(options);
|
||||
// add the transaction hash
|
||||
contract.transactionHash = hash;
|
||||
checkForContractAddress(contract);
|
||||
}
|
||||
|
||||
return contract;
|
||||
};
|
||||
|
||||
this.new.getData = this.getData.bind(this);
|
||||
};
|
||||
|
||||
@ -180,61 +236,7 @@ var ContractFactory = function (eth, abi) {
|
||||
//return new ContractFactory(abi);
|
||||
//};
|
||||
|
||||
/**
|
||||
* Should be called to create new contract on a blockchain
|
||||
*
|
||||
* @method new
|
||||
* @param {Any} contract constructor param1 (optional)
|
||||
* @param {Any} contract constructor param2 (optional)
|
||||
* @param {Object} contract transaction object (required)
|
||||
* @param {Function} callback
|
||||
* @returns {Contract} returns contract instance
|
||||
*/
|
||||
ContractFactory.prototype.new = function () {
|
||||
var contract = new Contract(this.eth, this.abi);
|
||||
|
||||
// parse arguments
|
||||
var options = {}; // required!
|
||||
var callback;
|
||||
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if (utils.isFunction(args[args.length - 1])) {
|
||||
callback = args.pop();
|
||||
}
|
||||
|
||||
var last = args[args.length - 1];
|
||||
if (utils.isObject(last) && !utils.isArray(last)) {
|
||||
options = args.pop();
|
||||
}
|
||||
|
||||
var bytes = encodeConstructorParams(this.abi, args);
|
||||
options.data += bytes;
|
||||
|
||||
if (callback) {
|
||||
|
||||
// wait for the contract address adn check if the code was deployed
|
||||
this.eth.sendTransaction(options, function (err, hash) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
// add the transaction hash
|
||||
contract.transactionHash = hash;
|
||||
|
||||
// call callback for the first time
|
||||
callback(null, contract);
|
||||
|
||||
checkForContractAddress(contract, callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var hash = this.eth.sendTransaction(options);
|
||||
// add the transaction hash
|
||||
contract.transactionHash = hash;
|
||||
checkForContractAddress(contract);
|
||||
}
|
||||
|
||||
return contract;
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get access to existing contract on a blockchain
|
||||
@ -294,4 +296,3 @@ var Contract = function (eth, abi, address) {
|
||||
};
|
||||
|
||||
module.exports = ContractFactory;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user