Skip to content

Commit

Permalink
add estimateGas to contract methods and fixed sendTransaction return …
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
frozeman committed May 20, 2015
1 parent 02556ea commit 0594e7f
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 14 deletions.
22 changes: 20 additions & 2 deletions dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/web3-light.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3-light.min.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/web3.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3.min.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions lib/web3/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0594e7f

Please sign in to comment.