From 6917348626ca1f37ce8eeffb33b99001639b00e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Wed, 24 Jan 2024 16:47:57 +0100 Subject: [PATCH] feat(libs): add ResultErrorCodes helper methods --- contracts/libs/Witnet.sol | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/contracts/libs/Witnet.sol b/contracts/libs/Witnet.sol index 57e496a3..876bbcf4 100644 --- a/contracts/libs/Witnet.sol +++ b/contracts/libs/Witnet.sol @@ -246,6 +246,36 @@ library Witnet { UnhandledIntercept } + function isCircumstantial(ResultErrorCodes self) internal pure returns (bool) { + return (self == ResultErrorCodes.CircumstantialFailure); + } + + function lackOfConsensus(ResultErrorCodes self) internal pure returns (bool) { + return ( + self == ResultErrorCodes.InsufficientCommits + || self == ResultErrorCodes.InsufficientMajority + || self == ResultErrorCodes.InsufficientQuorum + ); + } + + function isRetriable(ResultErrorCodes self) internal pure returns (bool) { + return ( + lackOfConsensus(self) + || isCircumstantial(self) + || poorIncentives(self) + ); + } + + function poorIncentives(ResultErrorCodes self) internal pure returns (bool) { + return ( + self == ResultErrorCodes.OversizedTallyResult + || self == ResultErrorCodes.InsufficientCommits + || self == ResultErrorCodes.BridgePoorIncentives + || self == ResultErrorCodes.BridgeOversizedTallyResult + ); + } + + /// Possible Radon data request methods that can be used within a Radon Retrieval. enum RadonDataRequestMethods { /* 0 */ Unknown,