mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
add new contract.new behaviour
This commit is contained in:
parent
ea0e48d700
commit
08639a1324
55
dist/web3-light.js
vendored
55
dist/web3-light.js
vendored
@ -1838,10 +1838,11 @@ var ContractFactory = function (abi) {
|
||||
* @param {Any} contract constructor param2 (optional)
|
||||
* @param {Object} contract transaction object (required)
|
||||
* @param {Function} callback
|
||||
* @returns {Contract} returns contract if no callback was passed,
|
||||
* otherwise calls callback function (err, contract)
|
||||
* @returns {Contract} returns contract instance
|
||||
*/
|
||||
ContractFactory.prototype.new = function () {
|
||||
var contract = new Contract(this.abi);
|
||||
|
||||
// parse arguments
|
||||
var options = {}; // required!
|
||||
var callback;
|
||||
@ -1861,18 +1862,56 @@ ContractFactory.prototype.new = function () {
|
||||
var bytes = encodeConstructorParams(this.abi, args);
|
||||
options.data += bytes;
|
||||
|
||||
if (!callback) {
|
||||
var address = web3.eth.sendTransaction(options);
|
||||
return this.at(address);
|
||||
}
|
||||
|
||||
// wait for the contract address adn check if the code was deployed
|
||||
var self = this;
|
||||
web3.eth.sendTransaction(options, function (err, address) {
|
||||
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++;
|
||||
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
self.at(address, callback);
|
||||
});
|
||||
|
||||
return contract;
|
||||
};
|
||||
|
||||
/**
|
||||
|
5
dist/web3-light.min.js
vendored
5
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
55
dist/web3.js
vendored
55
dist/web3.js
vendored
@ -1838,10 +1838,11 @@ var ContractFactory = function (abi) {
|
||||
* @param {Any} contract constructor param2 (optional)
|
||||
* @param {Object} contract transaction object (required)
|
||||
* @param {Function} callback
|
||||
* @returns {Contract} returns contract if no callback was passed,
|
||||
* otherwise calls callback function (err, contract)
|
||||
* @returns {Contract} returns contract instance
|
||||
*/
|
||||
ContractFactory.prototype.new = function () {
|
||||
var contract = new Contract(this.abi);
|
||||
|
||||
// parse arguments
|
||||
var options = {}; // required!
|
||||
var callback;
|
||||
@ -1861,18 +1862,56 @@ ContractFactory.prototype.new = function () {
|
||||
var bytes = encodeConstructorParams(this.abi, args);
|
||||
options.data += bytes;
|
||||
|
||||
if (!callback) {
|
||||
var address = web3.eth.sendTransaction(options);
|
||||
return this.at(address);
|
||||
}
|
||||
|
||||
// wait for the contract address adn check if the code was deployed
|
||||
var self = this;
|
||||
web3.eth.sendTransaction(options, function (err, address) {
|
||||
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++;
|
||||
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
self.at(address, callback);
|
||||
});
|
||||
|
||||
return contract;
|
||||
};
|
||||
|
||||
/**
|
||||
|
8
dist/web3.min.js
vendored
8
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -114,10 +114,11 @@ var ContractFactory = function (abi) {
|
||||
* @param {Any} contract constructor param2 (optional)
|
||||
* @param {Object} contract transaction object (required)
|
||||
* @param {Function} callback
|
||||
* @returns {Contract} returns contract if no callback was passed,
|
||||
* otherwise calls callback function (err, contract)
|
||||
* @returns {Contract} returns contract instance
|
||||
*/
|
||||
ContractFactory.prototype.new = function () {
|
||||
var contract = new Contract(this.abi);
|
||||
|
||||
// parse arguments
|
||||
var options = {}; // required!
|
||||
var callback;
|
||||
@ -137,18 +138,56 @@ ContractFactory.prototype.new = function () {
|
||||
var bytes = encodeConstructorParams(this.abi, args);
|
||||
options.data += bytes;
|
||||
|
||||
if (!callback) {
|
||||
var address = web3.eth.sendTransaction(options);
|
||||
return this.at(address);
|
||||
}
|
||||
|
||||
// wait for the contract address adn check if the code was deployed
|
||||
var self = this;
|
||||
web3.eth.sendTransaction(options, function (err, address) {
|
||||
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++;
|
||||
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
self.at(address, callback);
|
||||
});
|
||||
|
||||
return contract;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -219,15 +219,27 @@ describe('web3.eth.contract', function() {
|
||||
]
|
||||
}];
|
||||
|
||||
var steps = 1;
|
||||
|
||||
provider.injectResult(address);
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_sendTransaction');
|
||||
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
|
||||
done();
|
||||
if(steps === 1) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_sendTransaction');
|
||||
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
|
||||
steps++;
|
||||
|
||||
} else if(steps === 2) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_newBlockFilter');
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
var myCon = contract(description).new(2, {data: code});
|
||||
contract(description).new(2, {data: code}, function(e, myCon){
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user