Merge pull request #212 from ethereum/estimateGas

add estimateGas to contract methods and fixed sendTransaction return value
This commit is contained in:
Marek Kotewicz 2015-05-21 10:38:03 +02:00
commit 2ad458cb39
8 changed files with 93 additions and 14 deletions

22
dist/web3-light.js vendored
View File

@ -2793,13 +2793,30 @@ SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload(args);
if (!callback) {
web3.eth.sendTransaction(payload);
return;
return web3.eth.sendTransaction(payload);
}
web3.eth.sendTransaction(payload, callback);
};
/**
* Should be used to estimateGas of solidity function
*
* @method estimateGas
* @param {Object} options
*/
SolidityFunction.prototype.estimateGas = function () {
var args = Array.prototype.slice.call(arguments);
var callback = this.extractCallback(args);
var payload = this.toPayload(args);
if (!callback) {
return web3.eth.estimateGas(payload);
}
web3.eth.estimateGas(payload, callback);
};
/**
* Should be used to get function display name
*
@ -2867,6 +2884,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
execute.request = this.request.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
execute.estimateGas = this.estimateGas.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

22
dist/web3.js vendored
View File

@ -2793,13 +2793,30 @@ SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload(args);
if (!callback) {
web3.eth.sendTransaction(payload);
return;
return web3.eth.sendTransaction(payload);
}
web3.eth.sendTransaction(payload, callback);
};
/**
* Should be used to estimateGas of solidity function
*
* @method estimateGas
* @param {Object} options
*/
SolidityFunction.prototype.estimateGas = function () {
var args = Array.prototype.slice.call(arguments);
var callback = this.extractCallback(args);
var payload = this.toPayload(args);
if (!callback) {
return web3.eth.estimateGas(payload);
}
web3.eth.estimateGas(payload, callback);
};
/**
* Should be used to get function display name
*
@ -2867,6 +2884,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
execute.request = this.request.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
execute.estimateGas = this.estimateGas.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -122,13 +122,30 @@ SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload(args);
if (!callback) {
web3.eth.sendTransaction(payload);
return;
return web3.eth.sendTransaction(payload);
}
web3.eth.sendTransaction(payload, callback);
};
/**
* Should be used to estimateGas of solidity function
*
* @method estimateGas
* @param {Object} options
*/
SolidityFunction.prototype.estimateGas = function () {
var args = Array.prototype.slice.call(arguments);
var callback = this.extractCallback(args);
var payload = this.toPayload(args);
if (!callback) {
return web3.eth.estimateGas(payload);
}
web3.eth.estimateGas(payload, callback);
};
/**
* Should be used to get function display name
*
@ -196,6 +213,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
execute.request = this.request.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
execute.estimateGas = this.estimateGas.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;

View File

@ -296,6 +296,31 @@ describe('web3.eth.contract', function () {
});
});
it('should explicitly estimateGas with optional params', function () {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_estimateGas');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
gas: '0xc350',
gasPrice: '0xbb8',
value: '0x2710'
}]);
});
var contract = web3.eth.contract(desc).at(address);
contract.send.estimateGas(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000});
});
it('should call testArr method and properly parse result', function () {
var provider = new FakeHttpProvider2();
web3.setProvider(provider);