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
@ -14,7 +14,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
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/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file contract.js
|
* @file contract.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
* @date 2014
|
* @date 2014
|
||||||
@ -76,7 +76,7 @@ var addEventsToContract = function (contract) {
|
|||||||
|
|
||||||
var All = new AllEvents(contract._eth._requestManager, events, contract.address);
|
var All = new AllEvents(contract._eth._requestManager, events, contract.address);
|
||||||
All.attachToContract(contract);
|
All.attachToContract(contract);
|
||||||
|
|
||||||
events.map(function (json) {
|
events.map(function (json) {
|
||||||
return new SolidityEvent(contract._eth._requestManager, json, contract.address);
|
return new SolidityEvent(contract._eth._requestManager, json, contract.address);
|
||||||
}).forEach(function (e) {
|
}).forEach(function (e) {
|
||||||
@ -104,7 +104,7 @@ var checkForContractAddress = function(contract, callback){
|
|||||||
|
|
||||||
// stop watching after 50 blocks (timeout)
|
// stop watching after 50 blocks (timeout)
|
||||||
if (count > 50) {
|
if (count > 50) {
|
||||||
|
|
||||||
filter.stopWatching();
|
filter.stopWatching();
|
||||||
callbackFired = true;
|
callbackFired = true;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ var checkForContractAddress = function(contract, callback){
|
|||||||
|
|
||||||
if(callbackFired || !code)
|
if(callbackFired || !code)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
filter.stopWatching();
|
filter.stopWatching();
|
||||||
callbackFired = true;
|
callbackFired = true;
|
||||||
|
|
||||||
@ -166,6 +166,62 @@ var ContractFactory = function (eth, abi) {
|
|||||||
this.eth = eth;
|
this.eth = eth;
|
||||||
this.abi = abi;
|
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);
|
this.new.getData = this.getData.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -180,61 +236,7 @@ var ContractFactory = function (eth, abi) {
|
|||||||
//return new ContractFactory(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
|
* 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) {
|
ContractFactory.prototype.at = function (address, callback) {
|
||||||
var contract = new Contract(this.eth, this.abi, address);
|
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
|
// because we dont want to spoil the interface
|
||||||
addFunctionsToContract(contract);
|
addFunctionsToContract(contract);
|
||||||
addEventsToContract(contract);
|
addEventsToContract(contract);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(null, contract);
|
callback(null, contract);
|
||||||
}
|
}
|
||||||
return contract;
|
return contract;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -294,4 +296,3 @@ var Contract = function (eth, abi, address) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ContractFactory;
|
module.exports = ContractFactory;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user