Skip to content

Commit

Permalink
Add legacy backup decoding for deserialiseWitnessLedgerCddl
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed May 28, 2024
1 parent 260a6aa commit 5743a60
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NamedFieldPuns #-}

-- | Ledger CDDL Serialisation
--
Expand Down Expand Up @@ -187,13 +188,30 @@ deserialiseWitnessLedgerCddl :: forall era .
-> TextEnvelope
-> Either TextEnvelopeCddlError (KeyWitness era)
deserialiseWitnessLedgerCddl sbe te =
shelleyBasedEraConstraints sbe $ mapLeft textEnvelopeErrorToTextEnvelopeCddlError $
shelleyBasedEraConstraints sbe $ legacyDecoding te $ mapLeft textEnvelopeErrorToTextEnvelopeCddlError $
deserialiseFromTextEnvelope asType te

where
asType :: AsType (KeyWitness era)
asType = shelleyBasedEraConstraints sbe $ proxyToAsType Proxy

-- | This wrapper ensures that we can still decode the key witness
-- that were serialized before we migrated to using 'serialiseToTextEnvelope'
legacyDecoding :: TextEnvelope -> Either TextEnvelopeCddlError (KeyWitness era) -> Either TextEnvelopeCddlError (KeyWitness era)
legacyDecoding TextEnvelope{teDescription, teRawCBOR} (Left (TextEnvelopeCddlErrCBORDecodingError _)) =
case teDescription of
"Key BootstrapWitness ShelleyEra" -> do
w <- first TextEnvelopeCddlErrCBORDecodingError
$ CBOR.decodeFullAnnotator
(eraProtVerLow sbe) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teRawCBOR)
Right $ ShelleyBootstrapWitness sbe w
"Key Witness ShelleyEra" -> do
w <- first TextEnvelopeCddlErrCBORDecodingError
$ CBOR.decodeFullAnnotator
(eraProtVerLow sbe) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teRawCBOR)
Right $ ShelleyKeyWitness sbe w
_ -> Left TextEnvelopeCddlUnknownKeyWitness
legacyDecoding _ v = v

writeTxFileTextEnvelopeCddl :: ()
=> ShelleyBasedEra era
-> File content Out
Expand Down

0 comments on commit 5743a60

Please sign in to comment.