Skip to content

Commit

Permalink
Allow calling iface.functions.contractFn() without params, even when …
Browse files Browse the repository at this point in the history
…contractFn() takes params. In this case, omit result.data. #44
  • Loading branch information
GFJHogue committed Oct 27, 2017
1 parent aeec6d6 commit e31bdc4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contracts/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,17 @@ function Interface(abi) {

var params = Array.prototype.slice.call(arguments, 0);

if (params.length < inputTypes.length) {
if (params.length < inputTypes.length && params.length) {
throwError('missing parameter');
} else if (params.length > inputTypes.length) {
throwError('too many parameters');
}

signature = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);
if (params.length || !inputTypes.length) {
signature = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);
result.data = signature + Interface.encodeParams(inputTypes, params).substring(2);
}

result.data = signature + Interface.encodeParams(inputTypes, params).substring(2);
if (method.constant) {
result.parse = function(data) {
return Interface.decodeParams(
Expand Down

4 comments on commit e31bdc4

@ricmoo
Copy link
Member

@ricmoo ricmoo commented on e31bdc4 Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move it outside of even needing to be called.

Also, we want to make sure we intentionally error on a method being called with no arguments that requires them.

@GFJHogue
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricmoo Yeah, I agree that would make more sense so the function can maintain a discrete use-case.

@ricmoo
Copy link
Member

@ricmoo ricmoo commented on e31bdc4 Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix in place... Just running the test cases. :)

@ricmoo
Copy link
Member

@ricmoo ricmoo commented on e31bdc4 Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed on my local machine. Once the test cases pass on Travis CI I will publish to NPM.

Please sign in to comment.