Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support solidity overloaded methods #190

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Lohann
Copy link

@Lohann Lohann commented Oct 6, 2020

Issue

Solidity supports method overloading and Rust don’t.

How to Reproduce

Currently ethabi-derive and ethabi-contract doesn't support contracts with overloaded methods, like the ERC721 standard:

function safeTransferFrom(address from, address to, uint256 tokenId) external;
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

if you attempt to use

use_contract!(erc721, "../res/ERC721.abi")

Rust will complain with following error:

   | use_contract!(erc721, "../res/ERC721.abi");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | `safe_transfer_from` redefined here
   | previous definition of the module `safe_transfer_from` here
   |
   = note: `safe_transfer_from` must be defined only once in the type namespace of this module
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Proposal

For ethabi-derive, I included a new attribute ethabi_function_options, which receives function parameters.

pub mod erc721 {
    #[derive(ethabi_derive::EthabiContract)]
    #[ethabi_contract_options(path = "../res/ERC721.abi")]
    #[ethabi_function_options(
        signature = "safeTransferFrom(address,address,uint256,bytes)",
        alias = "safe_transfer_from_with_data"
    )]
    struct _Dummy;
}

For ethabi-contract, I included a new Macro Rule which accepts custom function options.

use_contract!{
    erc721,
    "../res/ERC721.abi"
    "safeTransferFrom(address,address,uint256,bytes)" => "safe_transfer_from_with_data",
    "safeTransferFrom(address,address,uint256)" => "regular_safe_transfer_from",
}

erc721::functions::safe_transfer_from_with_data::encode_input(...);
erc721::functions::regular_safe_transfer_from::encode_input(...);

@Lohann Lohann changed the title Feature/ Support contracts with overloaded methods Feature/ Support overloaded methods Oct 7, 2020
@Lohann Lohann changed the title Feature/ Support overloaded methods Support overloaded methods Oct 7, 2020
@Lohann Lohann changed the title Support overloaded methods Support solidity overloaded methods Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant