add sync version

This commit is contained in:
Fabian Vogelsteller 2015-07-06 17:01:14 +02:00
parent 08639a1324
commit a36636e433
5 changed files with 212 additions and 145 deletions

115
dist/web3-light.js vendored
View File

@ -1820,6 +1820,57 @@ var contract = function (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 self = this;
var count = 0;
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -1862,54 +1913,26 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
// wait for the contract address adn check if the code was deployed
var self = this;
var count = 0;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
if(!e) {
count++;
if(callback) {
// 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(hash, 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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
})
}
});
// wait for the contract address adn check if the code was deployed
var self = this;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(self, contract, callback);
}
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(this, contract);
}
return contract;
};

File diff suppressed because one or more lines are too long

115
dist/web3.js vendored
View File

@ -1820,6 +1820,57 @@ var contract = function (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 self = this;
var count = 0;
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -1862,54 +1913,26 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
// wait for the contract address adn check if the code was deployed
var self = this;
var count = 0;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
if(!e) {
count++;
if(callback) {
// 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(hash, 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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
})
}
});
// wait for the contract address adn check if the code was deployed
var self = this;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(self, contract, callback);
}
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(this, contract);
}
return contract;
};

7
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -96,6 +96,57 @@ var contract = function (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 self = this;
var count = 0;
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -138,54 +189,26 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
// wait for the contract address adn check if the code was deployed
var self = this;
var count = 0;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// wait for receipt
var filter = web3.eth.filter('latest', function(e, res){
if(!e) {
count++;
if(callback) {
// 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(hash, 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 {
callback(new Error('The contract code couldn\'t be stored'));
}
filter.stopWatching();
});
}
});
}
}
})
}
});
// wait for the contract address adn check if the code was deployed
var self = this;
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(self, contract, callback);
}
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress.call(this, contract);
}
return contract;
};