web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Conflict for Events with same name for generated abi

Open ShawnWu0x opened this issue 2 years ago • 3 comments

Bug_title

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

  • Web3j core 4.8.7
  • Java 1.8
  • MacOS

Additional context

ShawnWu0x avatar Sep 28 '22 11:09 ShawnWu0x

@ShawnWu0x investigating this

mohamedelshami avatar Oct 21 '22 09:10 mohamedelshami

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

CJ42 avatar Feb 13 '23 10:02 CJ42

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>() {}));
    ;

mattiamonari avatar Mar 02 '23 14:03 mattiamonari