Skip to content

Commit

Permalink
final fix and re-generation of golden
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Dec 20, 2024
1 parent ff80d8b commit 7b7e92f
Show file tree
Hide file tree
Showing 5 changed files with 12,282 additions and 9,592 deletions.
36 changes: 7 additions & 29 deletions lib/api/src/Cardano/Wallet/Api/Types/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,10 @@ import Cardano.Wallet.Primitive.Types
)
import Cardano.Wallet.Primitive.Types.DRep
( DRep (..)
, decodeDRepIDBech32
, encodeDRepIDBech32
)
import Cardano.Wallet.Util
( ShowFmt (..)
)
import Control.Applicative
( (<|>)
)
import Control.DeepSeq
( NFData
)
Expand All @@ -93,12 +88,14 @@ import Data.Aeson.Types
, genericParseJSON
, genericToJSON
, withObject
, withText
, (.:)
)
import Data.Bifunctor
( bimap
)
import Control.Monad
( (>=>)
)
import Data.List.NonEmpty
( NonEmpty
)
Expand All @@ -109,7 +106,8 @@ import Data.Quantity
( Quantity (..)
)
import Data.Text.Class
( TextDecodingError (..)
( FromText (..)
, ToText (..)
)
import GHC.Generics
( Generic
Expand Down Expand Up @@ -338,26 +336,6 @@ mkApiAnyCertificate acct' acctPath' = \case
JoinPoolCastVoteExternal (ApiRewardAccount rewardKey) (ApiT poolId') (ApiT vote')

instance ToJSON (ApiT DRep) where
toJSON (ApiT Abstain) = "abstain"
toJSON (ApiT NoConfidence) = "no_confidence"
toJSON (ApiT (FromDRepID drepid)) =
String $ encodeDRepIDBech32 drepid
toJSON = toJSON . toText . getApiT
instance FromJSON (ApiT DRep) where
parseJSON t =
parseAbstain t <|> parseNoConfidence t <|> parseDrepID t
where
parseDrepID = withText "DRepID" $ \txt ->
case decodeDRepIDBech32 txt of
Left (TextDecodingError err) -> fail err
Right drepid ->
pure $ ApiT $ FromDRepID drepid
parseAbstain = withText "Abstain" $ \txt ->
if txt == "abstain" then
pure $ ApiT Abstain
else
fail "'abstain' is expected."
parseNoConfidence = withText "NoConfidence" $ \txt ->
if txt == "no_confidence" then
pure $ ApiT NoConfidence
else
fail "'no_confidence' is expected."
parseJSON = parseJSON >=> eitherToParser . bimap ShowFmt ApiT . fromText
16 changes: 7 additions & 9 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ encodeDRepIDBech32 drepid =
decodeDRepIDBech32 :: Text -> Either TextDecodingError DRepID
decodeDRepIDBech32 t =
case fmap Bech32.dataPartToBytes <$> Bech32.decodeLenient t of
Left _ -> Left textDecodingError
Left _ ->
Left textDecodingError
Right (hrp', Just bytes)
| hrp' == hrpDrep && BS.length bytes == 29 ->
let (fstByte, payload) = first BS.head $ BS.splitAt 1 bytes
Expand All @@ -115,7 +116,10 @@ decodeDRepIDBech32 t =
Right $ DRepFromKeyHash (DRepKeyHash bytes)
| hrp' == hrpDrepScript && BS.length bytes == 28 ->
Right $ DRepFromScriptHash (DRepScriptHash bytes)
Right _ -> Left textDecodingError
| otherwise ->
Left textDecodingError
_ ->
Left textDecodingError
where
textDecodingError = TextDecodingError $ unwords
[ "Invalid DRep key/script hash: expecting a Bech32 encoded value"
Expand All @@ -129,9 +133,6 @@ decodeDRepIDBech32 t =
hrpDrepVKH = [Bech32.humanReadablePart|drep_vkh|]
hrpDrepScript = [Bech32.humanReadablePart|drep_script|]

instance Buildable DRepID where
build = build . encodeDRepIDBech32

-- | A decentralized representation ('DRep') will
-- vote on behalf of the stake delegated to it.
data DRep
Expand All @@ -153,7 +154,4 @@ instance FromText DRep where
_ -> second FromDRepID (decodeDRepIDBech32 txt)

instance Buildable DRep where
build = \case
Abstain -> "abstain"
NoConfidence -> "no_confidence"
FromDRepID drep -> "delegating voting to " <> build drep
build = build . toText
Loading

0 comments on commit 7b7e92f

Please sign in to comment.