@@ -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.8.0 "
1420
+ "version": "0.8.1 "
1421
1421
}
1422
1422
1423
1423
},{}],9:[function(require,module,exports){
@@ -1840,21 +1840,23 @@ var contract = function (abi) {
1840
1840
};
1841
1841
1842
1842
/**
1843
- * Should be called to create new ContractFactory
1843
+ * Should be called to check if the contract gets properly deployed on the blockchain.
1844
1844
*
1845
1845
* @method checkForContractAddress
1846
1846
* @param {Object} contract
1847
1847
* @param {Function} callback
1848
1848
* @returns {Undefined}
1849
1849
*/
1850
- var checkForContractAddress = function(contract, callback){
1850
+ var checkForContractAddress = function(contract, abi, callback){
1851
1851
var count = 0;
1852
1852
1853
1853
// wait for receipt
1854
1854
var filter = web3.eth.filter('latest', function(e){
1855
1855
if(!e) {
1856
1856
count++;
1857
1857
1858
+ // console.log('Checking for contract address', count);
1859
+
1858
1860
// stop watching after 50 blocks (timeout)
1859
1861
if(count > 50) {
1860
1862
if(callback)
@@ -1870,8 +1872,14 @@ var checkForContractAddress = function(contract, callback){
1870
1872
web3.eth.getCode(receipt.contractAddress, function(e, code){
1871
1873
if(code.length > 2) {
1872
1874
1875
+ // console.log('Contract code deployed!');
1876
+
1873
1877
contract.address = receipt.contractAddress;
1874
1878
1879
+ // attach events and methods
1880
+ addFunctionsToContract(contract, abi);
1881
+ addEventsToContract(contract, abi);
1882
+
1875
1883
if(callback)
1876
1884
callback(null, contract);
1877
1885
@@ -1909,6 +1917,7 @@ var ContractFactory = function (abi) {
1909
1917
* @returns {Contract} returns contract instance
1910
1918
*/
1911
1919
ContractFactory.prototype.new = function () {
1920
+ var _this = this;
1912
1921
var contract = new Contract(this.abi);
1913
1922
1914
1923
// parse arguments
@@ -1940,14 +1949,14 @@ ContractFactory.prototype.new = function () {
1940
1949
} else {
1941
1950
// add the transaction hash
1942
1951
contract.transactionHash = hash;
1943
- checkForContractAddress(contract, callback);
1952
+ checkForContractAddress(contract, _this.abi, callback);
1944
1953
}
1945
1954
});
1946
1955
} else {
1947
1956
var hash = web3.eth.sendTransaction(options);
1948
1957
// add the transaction hash
1949
1958
contract.transactionHash = hash;
1950
- checkForContractAddress(contract);
1959
+ checkForContractAddress(contract, _this.abi );
1951
1960
}
1952
1961
1953
1962
return contract;
@@ -1963,12 +1972,17 @@ ContractFactory.prototype.new = function () {
1963
1972
* otherwise calls callback function (err, contract)
1964
1973
*/
1965
1974
ContractFactory.prototype.at = function (address, callback) {
1975
+ var contract = new Contract(this.abi, address);
1966
1976
// TODO: address is required
1977
+
1978
+ // attach functions
1979
+ addFunctionsToContract(contract, this.abi);
1980
+ addEventsToContract(contract, this.abi);
1967
1981
1968
1982
if (callback) {
1969
- callback(null, new Contract(this.abi, address) );
1983
+ callback(null, contract );
1970
1984
}
1971
- return new Contract(this.abi, address) ;
1985
+ return contract ;
1972
1986
};
1973
1987
1974
1988
/**
@@ -1980,8 +1994,6 @@ ContractFactory.prototype.at = function (address, callback) {
1980
1994
*/
1981
1995
var Contract = function (abi, address) {
1982
1996
this.address = address;
1983
- addFunctionsToContract(this, abi);
1984
- addEventsToContract(this, abi);
1985
1997
};
1986
1998
1987
1999
module.exports = contract;
@@ -2484,8 +2496,8 @@ SolidityEvent.prototype.encode = function (indexed, options) {
2484
2496
2485
2497
result.topics = [];
2486
2498
2499
+ result.address = this._address;
2487
2500
if (!this._anonymous) {
2488
- result.address = this._address;
2489
2501
result.topics.push('0x' + this.signature());
2490
2502
}
2491
2503
0 commit comments