|
6 | 6 | {-# LANGUAGE GADTs #-}
|
7 | 7 | {-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
8 | 8 | {-# LANGUAGE InstanceSigs #-}
|
| 9 | +{-# LANGUAGE LambdaCase #-} |
9 | 10 | {-# LANGUAGE MultiParamTypeClasses #-}
|
10 | 11 | {-# LANGUAGE RankNTypes #-}
|
11 | 12 | {-# LANGUAGE ScopedTypeVariables #-}
|
@@ -69,8 +70,8 @@ import Cardano.Ledger.Crypto (StandardCrypto)
|
69 | 70 | import Cardano.Ledger.Crypto qualified as Shelley (DSIGN)
|
70 | 71 | import Cardano.Ledger.Keys qualified as Shelley
|
71 | 72 |
|
72 |
| -import Codec.CBOR.Decoding (decodeListLenOf) |
73 |
| -import Codec.CBOR.Encoding (encodeListLen) |
| 73 | +import Codec.CBOR.Decoding (Decoder, TokenType (TypeListLen), decodeListLenOf, peekTokenType) |
| 74 | +import Codec.CBOR.Encoding (Encoding, encodeListLen) |
74 | 75 | import Data.Aeson.Types
|
75 | 76 | ( ToJSONKey (..)
|
76 | 77 | , toJSONKeyText
|
@@ -1685,19 +1686,25 @@ data AnyStakePoolVerificationKey
|
1685 | 1686 | deriving (Show, Eq)
|
1686 | 1687 |
|
1687 | 1688 | instance ToCBOR AnyStakePoolVerificationKey where
|
| 1689 | + toCBOR :: AnyStakePoolVerificationKey -> Encoding |
1688 | 1690 | toCBOR (AnyStakePoolNormalVerificationKey vk) =
|
1689 | 1691 | encodeListLen 2 <> toCBOR (0 :: Word8) <> toCBOR vk
|
1690 | 1692 | toCBOR (AnyStakePoolExtendedVerificationKey vk) =
|
1691 | 1693 | encodeListLen 2 <> toCBOR (1 :: Word8) <> toCBOR vk
|
1692 | 1694 |
|
1693 | 1695 | instance FromCBOR AnyStakePoolVerificationKey where
|
| 1696 | + fromCBOR :: Decoder s AnyStakePoolVerificationKey |
1694 | 1697 | fromCBOR =
|
1695 |
| - decodeListLenOf 2 >> do |
1696 |
| - tag <- fromCBOR |
1697 |
| - case tag of |
1698 |
| - 0 -> AnyStakePoolNormalVerificationKey <$> fromCBOR |
1699 |
| - 1 -> AnyStakePoolExtendedVerificationKey <$> fromCBOR |
1700 |
| - _ -> cborError $ DecoderErrorUnknownTag "AnyStakePoolVerificationKey" tag |
| 1698 | + peekTokenType >>= \case |
| 1699 | + TypeListLen -> |
| 1700 | + decodeListLenOf 2 >> do |
| 1701 | + tag <- fromCBOR |
| 1702 | + case tag of |
| 1703 | + 0 -> AnyStakePoolNormalVerificationKey <$> fromCBOR |
| 1704 | + 1 -> AnyStakePoolExtendedVerificationKey <$> fromCBOR |
| 1705 | + _ -> cborError $ DecoderErrorUnknownTag "AnyStakePoolVerificationKey" tag |
| 1706 | + -- This case is for backwards compatibility (with CBOR encoding that doesn't support extended keys) |
| 1707 | + _ -> AnyStakePoolNormalVerificationKey <$> fromCBOR |
1701 | 1708 |
|
1702 | 1709 | anyStakePoolVerificationKeyHash :: AnyStakePoolVerificationKey -> Hash StakePoolKey
|
1703 | 1710 | anyStakePoolVerificationKeyHash (AnyStakePoolNormalVerificationKey vk) = verificationKeyHash vk
|
|
0 commit comments