@@ -1417,7 +1417,7 @@ module.exports = {
1417
1417
1418
1418
},{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
1419
1419
module.exports={
1420
- "version": "0.7.1 "
1420
+ "version": "0.8.0 "
1421
1421
}
1422
1422
1423
1423
},{}],9:[function(require,module,exports){
@@ -1839,6 +1839,55 @@ var contract = function (abi) {
1839
1839
return new ContractFactory(abi);
1840
1840
};
1841
1841
1842
+ /**
1843
+ * Should be called to create new ContractFactory
1844
+ *
1845
+ * @method checkForContractAddress
1846
+ * @param {Object} contract
1847
+ * @param {Function} callback
1848
+ * @returns {Undefined}
1849
+ */
1850
+ var checkForContractAddress = function(contract, callback){
1851
+ var count = 0;
1852
+
1853
+ // wait for receipt
1854
+ var filter = web3.eth.filter('latest', function(e){
1855
+ if(!e) {
1856
+ count++;
1857
+
1858
+ // stop watching after 50 blocks (timeout)
1859
+ if(count > 50) {
1860
+ if(callback)
1861
+ callback(new Error('Contract couldn\'t be deployed'));
1862
+
1863
+ filter.stopWatching();
1864
+
1865
+ } else {
1866
+
1867
+ web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
1868
+ if(receipt) {
1869
+
1870
+ web3.eth.getCode(receipt.contractAddress, function(e, code){
1871
+ if(code.length > 2) {
1872
+
1873
+ contract.address = receipt.contractAddress;
1874
+
1875
+ if(callback)
1876
+ callback(null, contract);
1877
+
1878
+ } else if(callback) {
1879
+ callback(new Error('The contract code couldn\'t be stored'));
1880
+ }
1881
+
1882
+ filter.stopWatching();
1883
+ });
1884
+ }
1885
+ });
1886
+ }
1887
+ }
1888
+ });
1889
+ };
1890
+
1842
1891
/**
1843
1892
* Should be called to create new ContractFactory instance
1844
1893
*
@@ -1857,10 +1906,11 @@ var ContractFactory = function (abi) {
1857
1906
* @param {Any} contract constructor param2 (optional)
1858
1907
* @param {Object} contract transaction object (required)
1859
1908
* @param {Function} callback
1860
- * @returns {Contract} returns contract if no callback was passed,
1861
- * otherwise calls callback function (err, contract)
1909
+ * @returns {Contract} returns contract instance
1862
1910
*/
1863
1911
ContractFactory.prototype.new = function () {
1912
+ var contract = new Contract(this.abi);
1913
+
1864
1914
// parse arguments
1865
1915
var options = {}; // required!
1866
1916
var callback;
@@ -1880,18 +1930,27 @@ ContractFactory.prototype.new = function () {
1880
1930
var bytes = encodeConstructorParams(this.abi, args);
1881
1931
options.data += bytes;
1882
1932
1883
- if (!callback) {
1884
- var address = web3.eth.sendTransaction(options);
1885
- return this.at(address);
1933
+
1934
+ if(callback) {
1935
+
1936
+ // wait for the contract address adn check if the code was deployed
1937
+ web3.eth.sendTransaction(options, function (err, hash) {
1938
+ if (err) {
1939
+ callback(err);
1940
+ } else {
1941
+ // add the transaction hash
1942
+ contract.transactionHash = hash;
1943
+ checkForContractAddress(contract, callback);
1944
+ }
1945
+ });
1946
+ } else {
1947
+ var hash = web3.eth.sendTransaction(options);
1948
+ // add the transaction hash
1949
+ contract.transactionHash = hash;
1950
+ checkForContractAddress(contract);
1886
1951
}
1887
-
1888
- var self = this;
1889
- web3.eth.sendTransaction(options, function (err, address) {
1890
- if (err) {
1891
- callback(err);
1892
- }
1893
- self.at(address, callback);
1894
- });
1952
+
1953
+ return contract;
1895
1954
};
1896
1955
1897
1956
/**
0 commit comments