@openzeppelin/contracts/utils/cryptography/ECDSA.sol line 23
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
Found this code on OpenZeppelin’s repo. I suppose how it could be better?. Apparently, conditional logic can be handled very well and effectively using match in Rust. As opposed to a sequence of if/else statement blocks, it compares data to patterns considerably more rapidly, and the compiler does a statically verified version of it, allowing you to catch many errors at build time before they affect your code. Additionally, it makes it simple to add additional match weapons as your code develops, which is excellent for maintainability.
We are actually planning to add something like that when we implement enums with data. And these are coming sooner or later. Our roadmap for this year is full, but it has a very high chance of being one of the milestones after that.
Until then, there are some design questions that need to be answered. It would be very interesting to see what are people’s opinions on these:
Should it be an expression or a statement?
Syntax for destructuring of tuples, structs and enums with data.
Do we need match guards?
Do we need support for integer ranges? What syntax?
Should it be an expression or a statement?
An expression would be better for matching pattern, destructing enum. It let me rewrite above code much more clear.