hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.09k stars 1.68k forks source link

Conflict for Events with same name for generated abi #1781

Open ShawnWu0x opened 2 years ago

ShawnWu0x commented 2 years ago

_Bugtitle

In Solidity, the events may have same names, but with different parameters. Such as Compound's controller contract

There are 2 ActionPaused events with different parameters.

/// @notice Emitted when an action is paused globally
    event ActionPaused(string action, bool pauseState);

    /// @notice Emitted when an action is paused on a market
    event ActionPaused(CToken cToken, string action, bool pauseState);

If we generate the Java file with web3jgen for it, there will be 2 global parameters with name ACTIONPAUSED_EVENT in the generated JAVA file. This is not allowed in Java.

public static final Event ACTIONPAUSED_EVENT = new Event("ActionPaused", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
    ;

    public static final Event ACTIONPAUSED_EVENT = new Event("ActionPaused", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
    ;

Steps To Reproduce

  1. Open Compound's etherscan link controller contract
  2. Copy abi and bin codes to 2 files.
  3. Run web3j generate solidity -a abc.abi -b abc.bin -o ./ -p abi
    • -a is abi file
    • -b is bin file
    • -o is the directory where generate the file
    • -p is the package of java file

Expected behavior

The generated java file should has no ERROR.

Actual behavior

The generated java file built failed with ERROR.

Environment

Additional context

mohamedelshami commented 2 years ago

@ShawnWu0x investigating this

CJ42 commented 1 year ago

Any updates on this? Also encountering the same issue in https://github.com/lukso-network/lsp-smart-contracts/pull/469

mattiamonari commented 1 year ago

How would you like to have the name of duplicated event @CJ42? I'm currently working on it.

It is possible to create in the wrapper a 'numbered list', e.g. :

public static final Event ACTIONPAUSED_EVENT = new Event("ActionPaused", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
    ;

    public static final Event ACTIONPAUSED_EVENT_1 = new Event("ActionPaused", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
    ;