Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Overloaded functions are not all callable by name from the contract instance #22

Open
amaury1093 opened this issue Oct 16, 2018 · 0 comments

Comments

@amaury1093
Copy link
Collaborator

From parity-js/api#8

If I define a contract with an overloaded function, then try to call the function from the parity.js contract instance, I can only access one of the functions by name.

e.g.

contract C {
  function myFunc(address a) { return; }
  function myFunc(address a, uint b) { return; }
}
// after getting contract instances
theContract.instance.myFunc.call({}, ['0x0']); // errors due to missing property in array
theContract.instance.myFunc.call({}, ['0x0', 22]); // works fine

Workaround right now is to use the function signature bytes, (something like theContract.instance.be45fd62.call) which are different for each of the functions.

The code that causes this behaviour is here, where the value of the property corresponding to the function name is overwritten.

One possible fix would be to make contract.instance.myFunc dynamically determine which signature should be called based on the types of the arguments, and then call with the correct function signature based on that. The issue I see with this approach is that js is not typed the same way solidity is, so inferring the types may not be accurate.

Edit:

Seems like web3 handles it like this (setting key as func(argType1,argType2)), and this (choosing the function with the correct "shape" of parameters, if only one such function exists).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant