mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
Merge branch 'develop' of github.com:ethereum/web3.js into develop
This commit is contained in:
commit
bc45b70e96
@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
/**
|
||||
* @file contract.js
|
||||
* @author Marek Kotewicz <marek@ethdev.com>
|
||||
* @date 2014
|
||||
@ -76,7 +76,7 @@ var addEventsToContract = function (contract) {
|
||||
|
||||
var All = new AllEvents(contract._eth._requestManager, events, contract.address);
|
||||
All.attachToContract(contract);
|
||||
|
||||
|
||||
events.map(function (json) {
|
||||
return new SolidityEvent(contract._eth._requestManager, json, contract.address);
|
||||
}).forEach(function (e) {
|
||||
@ -104,7 +104,7 @@ var checkForContractAddress = function(contract, callback){
|
||||
|
||||
// stop watching after 50 blocks (timeout)
|
||||
if (count > 50) {
|
||||
|
||||
|
||||
filter.stopWatching();
|
||||
callbackFired = true;
|
||||
|
||||
@ -124,7 +124,7 @@ var checkForContractAddress = function(contract, callback){
|
||||
|
||||
if(callbackFired || !code)
|
||||
return;
|
||||
|
||||
|
||||
filter.stopWatching();
|
||||
callbackFired = true;
|
||||
|
||||
@ -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
|
||||
@ -248,14 +250,14 @@ ContractFactory.prototype.new = function () {
|
||||
ContractFactory.prototype.at = function (address, callback) {
|
||||
var contract = new Contract(this.eth, this.abi, address);
|
||||
|
||||
// this functions are not part of prototype,
|
||||
// this functions are not part of prototype,
|
||||
// because we dont want to spoil the interface
|
||||
addFunctionsToContract(contract);
|
||||
addEventsToContract(contract);
|
||||
|
||||
|
||||
if (callback) {
|
||||
callback(null, contract);
|
||||
}
|
||||
}
|
||||
return contract;
|
||||
};
|
||||
|
||||
@ -294,4 +296,3 @@ var Contract = function (eth, abi, address) {
|
||||
};
|
||||
|
||||
module.exports = ContractFactory;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user