web3 update

release/1.0.1
Jeffrey Wilcke 9 years ago
parent 0c9c5439d4
commit c5972b4ac7
  1. 79
      jsre/ethereum_js.go

@ -1417,7 +1417,7 @@ module.exports = {
},{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){ },{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
module.exports={ module.exports={
"version": "0.7.1" "version": "0.8.0"
} }
},{}],9:[function(require,module,exports){ },{}],9:[function(require,module,exports){
@ -1839,6 +1839,55 @@ var contract = function (abi) {
return new ContractFactory(abi); return new ContractFactory(abi);
}; };
/**
* Should be called to create new ContractFactory
*
* @method checkForContractAddress
* @param {Object} contract
* @param {Function} callback
* @returns {Undefined}
*/
var checkForContractAddress = function(contract, callback){
var count = 0;
// wait for receipt
var filter = web3.eth.filter('latest', function(e){
if(!e) {
count++;
// stop watching after 50 blocks (timeout)
if(count > 50) {
if(callback)
callback(new Error('Contract couldn\'t be deployed'));
filter.stopWatching();
} else {
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
if(receipt) {
web3.eth.getCode(receipt.contractAddress, function(e, code){
if(code.length > 2) {
contract.address = receipt.contractAddress;
if(callback)
callback(null, contract);
} else if(callback) {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
});
};
/** /**
* Should be called to create new ContractFactory instance * Should be called to create new ContractFactory instance
* *
@ -1857,10 +1906,11 @@ var ContractFactory = function (abi) {
* @param {Any} contract constructor param2 (optional) * @param {Any} contract constructor param2 (optional)
* @param {Object} contract transaction object (required) * @param {Object} contract transaction object (required)
* @param {Function} callback * @param {Function} callback
* @returns {Contract} returns contract if no callback was passed, * @returns {Contract} returns contract instance
* otherwise calls callback function (err, contract)
*/ */
ContractFactory.prototype.new = function () { ContractFactory.prototype.new = function () {
var contract = new Contract(this.abi);
// parse arguments // parse arguments
var options = {}; // required! var options = {}; // required!
var callback; var callback;
@ -1880,18 +1930,27 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args); var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes; options.data += bytes;
if (!callback) {
var address = web3.eth.sendTransaction(options);
return this.at(address);
}
var self = this; if(callback) {
web3.eth.sendTransaction(options, function (err, address) {
// wait for the contract address adn check if the code was deployed
web3.eth.sendTransaction(options, function (err, hash) {
if (err) { if (err) {
callback(err); callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, callback);
} }
self.at(address, callback);
}); });
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract);
}
return contract;
}; };
/** /**

Loading…
Cancel
Save