Support for Generation of Custom Error type #2173
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
CustomError
class toabi
packageCustomErrorEncoder
class toabi
packagecodegen
package for Custom Error(error
) type introduced insolidity >=0.8.4
With this PR,
codegen
will be able to generate variables for Custom Errors to correspondingContract
java class.codegen
will generate two thingserror
type defined in smart contract's abi withorg.web3j.abi.datatypes.CustomError
java classList.<org.web3j.abi.datatypes.CustomError>
Java class which contains allorg.web3j.abi.datatypes.CustomError
variables defined in the contract classThe former is straight-forward, it's just the Java type corresponding to
error
type in Solidity.The latter is for later use(on the client side) to iterate over contract's error types such as resolving revert reason returned by
eth_call
.Example: let's say we have the following smart contract
Then will generate the following code
Some notes:
If there is no error type defined in contract's abi, no variables are generated for error except
CUSTOM_ERRORS
list which will effectively be an empty list. I thought, at first, not to generate the list if there is no error type defined in abi, but the client implementations depend onCUSTOM_ERRORS
list, then the client implementation would not compile in case of no error type defined in abi.This support will not break backward compatibility for previous solidity versions.
Where should the reviewer start?
abi
andcodegen
packagesWhy is it needed?
Currently there is no support for custom errors, and it requires some effort to resolve revert reasons on the client side.
Checklist