Skip to content

Commit 94ac263

Browse files
authored
Merge pull request #4924 from IntersectMBO/lehins/make-instant-stake-deserialization-backwards-compatible
Make instantStake deserialization backwards compatible for `Conway` era
2 parents 81637a1 + 24d4f5f commit 94ac263

File tree

1 file changed

+12
-2
lines changed
  • eras/conway/impl/src/Cardano/Ledger/Conway/State

1 file changed

+12
-2
lines changed

eras/conway/impl/src/Cardano/Ledger/Conway/State/Stake.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import Cardano.Ledger.Binary (
2424
DecShareCBOR (..),
2525
EncCBOR (..),
2626
Interns,
27+
TokenType (..),
28+
peekTokenType,
2729
)
2830
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
2931
import Cardano.Ledger.Conway.Era
3032
import Cardano.Ledger.Conway.TxOut ()
3133
import Cardano.Ledger.Core
3234
import Cardano.Ledger.Credential
33-
import Cardano.Ledger.State
35+
import Cardano.Ledger.Shelley.State
3436
import qualified Cardano.Ledger.UMap as UM
3537
import Control.DeepSeq (NFData)
3638
import Data.Aeson (KeyValue, ToJSON (..), object, pairs, (.=))
@@ -50,7 +52,15 @@ newtype ConwayInstantStake era = ConwayInstantStake
5052

5153
instance DecShareCBOR (ConwayInstantStake era) where
5254
type Share (ConwayInstantStake era) = Interns (Credential 'Staking)
53-
decShareCBOR credInterns = ConwayInstantStake <$> decShareCBOR (credInterns, mempty)
55+
decShareCBOR credInterns = do
56+
peekTokenType >>= \case
57+
TypeListLen -> toConwayInstantStake <$> decShareCBOR credInterns
58+
TypeListLen64 -> toConwayInstantStake <$> decShareCBOR credInterns
59+
TypeListLenIndef -> toConwayInstantStake <$> decShareCBOR credInterns
60+
_ -> ConwayInstantStake <$> decShareCBOR (credInterns, mempty)
61+
where
62+
toConwayInstantStake :: ShelleyInstantStake era -> ConwayInstantStake era
63+
toConwayInstantStake = ConwayInstantStake . sisCredentialStake
5464

5565
instance Semigroup (ConwayInstantStake era) where
5666
ConwayInstantStake cs1 <> ConwayInstantStake cs2 =

0 commit comments

Comments
 (0)