Closed expede closed 6 years ago
so, from FinancialValidator
could you have
contract FinancialValidator
enum Reasons {
InsufficientFunds
}
....
if (_amount < 1000) { return customCode(FinancialValidator.Reasons.InsufficientFunds); }
but i'm not sure. it would be nicer to have
if (_amount < 1000) { return FinancialValidator.Reasons.InsufficientFunds; }
or maybe just
contract FinancialValidator {
byte InsufficientFunds = hex"A0";
function checkBalance(int _amount) internal pure returns (Status.Reason) {
if (_amount < 1000) {
return InsufficientFunds;
}
else {
return Status.Reason.Success;
}
}
my eyes are burning - i'm not sure my last example makes sense. time to step away from the machine. 8)
Hmm, yeah. It's a fair point. byte InsufficientFunds = hex"A0";
works 👍🏻 I don't think that it'll compile as Status.Reason
. There's currently no way to go from an number to an enum in Solidity 😭 byte
is a built-in type, so we can cast the Status.Reason.Success
to byte
.
I agree that if you have some custom codes, using the hex values directly makes sense. If someone wanted to restrict return values via a type, the enum is more restricted than byte
.
I think that I see where the confusion is, and I'll add some notes to the code examples 😄
Via @carchrae
A user should be able to map names from a custom enum into the main code set
For example