Support for Generation of Custom Error type#2173
Conversation
Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
…pe to codegen Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
…eneration Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
|
Hello, is there any possibility that this PR will be merged? |
|
|
||
| assertEquals( | ||
| CustomErrorEncoder.calculateSignatureHash("RandomError(address[],bytes)"), | ||
| ("0xbf37b77ddf0fbbf29ee6a3ebda3d177c2d438123b10571806c57958230d9f905")); |
There was a problem hiding this comment.
All unit tests are on point, but I'm interested how did you generate the expected results for all the tests?
There was a problem hiding this comment.
I generated the expected signature hashes used in test cases with ethers.js.
Actually, CustomErrorEncoder is totally identical to EventEncoder, and EventEncoder could be used instead, which makes CustomErrorEncoder looking like a code duplication. But, I think, keeping separate classes for Solidity abi types would be a better option in case of any changes on Solidity side in the future.
…dency on client implementations Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
|
@psychoplasma LGTM, please update also the changelog and I will merge it |
Signed-off-by: Mustafa Morca <psychoplasma@gmail.com>
|
Updated |
Signed-off-by: gtebrean <99179176+gtebrean@users.noreply.github.com>
|
Hi team, Great work on this new feature! The perfect complement to this functionality would be to add the custom error information returned by the contract to the TransactionException.java class. What I mean is that in a call like this: try {
contractInstance.function(...params).send();
} catch (TransactionException ex) {
}the raw response from the node could be: {
"jsonrpc":"2.0",
"id":4,
"error": {
"code": 3,
"message": "execution reverted",
"data": "0xe2517d3f000000000000000000000000 ... "
}
}
The I think it's not possible to get this information even in a simulation using How can I access the data field information or the custom error selector? I appreciate your comments and attention to this matter. |
|
Hi @dgimenez27 That's a good point indeed. Regarding your question,
You can check out the |
|
💡 I created a related issue to propose officially exposing the ➡️ Issue #2180: Expose revert |
What does this PR do?
CustomErrorclass toabipackageCustomErrorEncoderclass toabipackagecodegenpackage for Custom Error(error) type introduced insolidity >=0.8.4With this PR,
codegenwill be able to generate variables for Custom Errors to correspondingContractjava class.codegenwill generate two thingserrortype defined in smart contract's abi withorg.web3j.abi.datatypes.CustomErrorjava classList.<org.web3j.abi.datatypes.CustomError>Java class which contains allorg.web3j.abi.datatypes.CustomErrorvariables defined in the contract classThe former is straight-forward, it's just the Java type corresponding to
errortype 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
How to use
Some notes:
If there is no error type defined in contract's abi, no variables are generated for error except
CUSTOM_ERRORSlist 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 if the client implementations depend onCUSTOM_ERRORSlist, 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?
abiandcodegenpackagesWhy 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