zink
zink copied to clipboard
Gather the declaration of errors
Describe the feature
Error has not been implemented yet, ABIs are also required but considered in a separated PR
Solution
#[derive(Errors)]
enum Error {
ERC20InvalidSender { sender: Address }
}
This solution could be similar as the events, see https://github.com/zink-lang/zink/pull/281#pullrequestreview-2475201842
hey @clearloop, assign me
@clearloop is there an existing error handling infrastructure?
@clearloop is there an existing error handling infrastructure?
we currently just have revert!, if I'm not mistaken, solidity errors are using revert internally as well, you can check the proc-macro implementation by @malik672 in #298, the logic is the same
the main difference are:
- logs need to call
log1, log2, log3, log4, and we need to userevert!,revert1!...revert4!(maximum 4 parameters) - for errors, we need to append the variables to the memory as well, then we can revert (name + parameters) together
#[derive(Error)]
pub enum Error {
Error0,
Error1(Bytes32),
Error2(Bytes32, Bytes32),
Error3(Bytes32, Bytes32, Bytes32),
Error4(Bytes32, Bytes32, Bytes32, Bytes32)
}
// which generates
impl Error {
fn error0() {
zink::revert!("Error");
}
fn error1(param: Bytes32) {
zink::revert!("Error", param)
}
// ...
}
for the revert macro, see revert!, and for the example, feel free to ask anything in the telegram channel!
great! thanks
great! thanks
see my implementation in https://github.com/zink-lang/zink/pull/298/commits/a8a3eeca309de405e427ddfb1284ed2f62709e7d, it's actually the same for this issue ^ ^
@clearloop assign me