diff --git a/cardano-api/ChangeLog.md b/cardano-api/ChangeLog.md index e584702ad57..8341e8b8f19 100644 --- a/cardano-api/ChangeLog.md +++ b/cardano-api/ChangeLog.md @@ -14,6 +14,8 @@ - **Breaking change** - Reduce exposed modules in cardano-api ([PR4546](https://github.com/input-output-hk/cardano-node/pull/4546)) +- **Breaking change** - `deserialiseFromRawBytes` method of the `SerialiseAsRawBytes` type class to return `Either` instead of `Maybe`. Deprecate `eitherDeserialiseFromRawBytes`. Use `deserialiseFromRawBytes` instead. + ### Bugs - Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384)) diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index a04e6009050..66ecc12e0d0 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -472,6 +472,7 @@ module Cardano.Api ( -- | Some types have a natural raw binary format. SerialiseAsRawBytes, serialiseToRawBytes, + deserialiseFromRawBytes, eitherDeserialiseFromRawBytes, serialiseToRawBytesHex, deserialiseFromRawBytesHex, diff --git a/cardano-api/src/Cardano/Api/Address.hs b/cardano-api/src/Cardano/Api/Address.hs index 21d6b57e57f..fd71cc6aa0d 100644 --- a/cardano-api/src/Cardano/Api/Address.hs +++ b/cardano-api/src/Cardano/Api/Address.hs @@ -220,7 +220,7 @@ instance SerialiseAsRawBytes (Address ByronAddr) where . Shelley.BootstrapAddress $ addr - eitherDeserialiseFromRawBytes (AsAddress AsByronAddr) bs = + deserialiseFromRawBytes (AsAddress AsByronAddr) bs = case Shelley.deserialiseAddr bs :: Maybe (Shelley.Addr StandardCrypto) of Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise Address ByronAddr") Just Shelley.Addr{} -> Left (SerialiseAsRawBytesError "Unable to deserialise Address ByronAddr") @@ -231,7 +231,7 @@ instance SerialiseAsRawBytes (Address ShelleyAddr) where serialiseToRawBytes (ShelleyAddress nw pc scr) = Shelley.serialiseAddr (Shelley.Addr nw pc scr) - eitherDeserialiseFromRawBytes (AsAddress AsShelleyAddr) bs = + deserialiseFromRawBytes (AsAddress AsShelleyAddr) bs = case Shelley.deserialiseAddr bs of Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise bootstrap Address ShelleyAddr") Just Shelley.AddrBootstrap{} -> Left (SerialiseAsRawBytesError "Unable to deserialise bootstrap Address ShelleyAddr") @@ -253,7 +253,7 @@ instance SerialiseAddress (Address ByronAddr) where deserialiseAddress (AsAddress AsByronAddr) txt = do bs <- Base58.decodeBase58 Base58.bitcoinAlphabet (Text.encodeUtf8 txt) - rightToMaybe (eitherDeserialiseFromRawBytes (AsAddress AsByronAddr) bs) + rightToMaybe (deserialiseFromRawBytes (AsAddress AsByronAddr) bs) instance SerialiseAddress (Address ShelleyAddr) where serialiseAddress addr@ShelleyAddress{} = @@ -326,7 +326,7 @@ instance SerialiseAsRawBytes AddressAny where serialiseToRawBytes (AddressByron addr) = serialiseToRawBytes addr serialiseToRawBytes (AddressShelley addr) = serialiseToRawBytes addr - eitherDeserialiseFromRawBytes AsAddressAny bs = + deserialiseFromRawBytes AsAddressAny bs = case Shelley.deserialiseAddr bs of Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise AddressAny") Just (Shelley.AddrBootstrap (Shelley.BootstrapAddress addr)) -> @@ -452,9 +452,9 @@ instance (IsCardanoEra era, Typeable era) => SerialiseAsRawBytes (AddressInEra e serialiseToRawBytes (AddressInEra ShelleyAddressInEra{} addr) = serialiseToRawBytes addr - eitherDeserialiseFromRawBytes _ bs = + deserialiseFromRawBytes _ bs = first (const (SerialiseAsRawBytesError "Unable to deserialise AddressInEra era")) $ - anyAddressInEra cardanoEra =<< first unSerialiseAsRawBytesError (eitherDeserialiseFromRawBytes AsAddressAny bs) + anyAddressInEra cardanoEra =<< first unSerialiseAsRawBytesError (deserialiseFromRawBytes AsAddressAny bs) instance IsCardanoEra era => SerialiseAddress (AddressInEra era) where serialiseAddress (AddressInEra ByronAddressInAnyEra addr) = @@ -571,7 +571,7 @@ instance SerialiseAsRawBytes StakeAddress where serialiseToRawBytes (StakeAddress nw sc) = Shelley.serialiseRewardAcnt (Shelley.RewardAcnt nw sc) - eitherDeserialiseFromRawBytes AsStakeAddress bs = + deserialiseFromRawBytes AsStakeAddress bs = case Shelley.deserialiseRewardAcnt bs of Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise StakeAddress") Just (Shelley.RewardAcnt nw sc) -> Right (StakeAddress nw sc) diff --git a/cardano-api/src/Cardano/Api/Block.hs b/cardano-api/src/Cardano/Api/Block.hs index 4bfa9de75d9..22a972d0e3c 100644 --- a/cardano-api/src/Cardano/Api/Block.hs +++ b/cardano-api/src/Cardano/Api/Block.hs @@ -291,7 +291,7 @@ newtype instance Hash BlockHeader = HeaderHash SBS.ShortByteString instance SerialiseAsRawBytes (Hash BlockHeader) where serialiseToRawBytes (HeaderHash bs) = SBS.fromShort bs - eitherDeserialiseFromRawBytes (AsHash AsBlockHeader) bs + deserialiseFromRawBytes (AsHash AsBlockHeader) bs | BS.length bs == 32 = Right $! HeaderHash (SBS.toShort bs) | otherwise = Left (SerialiseAsRawBytesError "Unable to deserialise Hash BlockHeader") diff --git a/cardano-api/src/Cardano/Api/Keys/Byron.hs b/cardano-api/src/Cardano/Api/Keys/Byron.hs index 178e8dbef4f..2f8b6a312be 100644 --- a/cardano-api/src/Cardano/Api/Keys/Byron.hs +++ b/cardano-api/src/Cardano/Api/Keys/Byron.hs @@ -142,7 +142,7 @@ instance SerialiseAsRawBytes (VerificationKey ByronKey) where serialiseToRawBytes (ByronVerificationKey (Byron.VerificationKey xvk)) = Crypto.HD.unXPub xvk - eitherDeserialiseFromRawBytes (AsVerificationKey AsByronKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsByronKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise VerificationKey ByronKey" ++ msg)) $ ByronVerificationKey . Byron.VerificationKey <$> Crypto.HD.xpub bs @@ -150,7 +150,7 @@ instance SerialiseAsRawBytes (SigningKey ByronKey) where serialiseToRawBytes (ByronSigningKey (Byron.SigningKey xsk)) = toStrictByteString $ Crypto.toCBORXPrv xsk - eitherDeserialiseFromRawBytes (AsSigningKey AsByronKey) bs = + deserialiseFromRawBytes (AsSigningKey AsByronKey) bs = first (\e -> SerialiseAsRawBytesError ("Unable to deserialise SigningKey ByronKey" ++ show e)) $ ByronSigningKey . Byron.SigningKey . snd <$> CBOR.deserialiseFromBytes Byron.fromCBORXPrv (LB.fromStrict bs) @@ -164,7 +164,7 @@ instance SerialiseAsRawBytes (Hash ByronKey) where serialiseToRawBytes (ByronKeyHash (Byron.KeyHash vkh)) = Byron.abstractHashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsByronKey) bs = + deserialiseFromRawBytes (AsHash AsByronKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash ByronKey") $ ByronKeyHash . Byron.KeyHash <$> Byron.abstractHashFromBytes bs @@ -236,7 +236,7 @@ instance SerialiseAsRawBytes (Hash ByronKeyLegacy) where serialiseToRawBytes (ByronKeyHashLegacy (Byron.KeyHash vkh)) = Byron.abstractHashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsByronKeyLegacy) bs = + deserialiseFromRawBytes (AsHash AsByronKeyLegacy) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash ByronKeyLegacy") $ ByronKeyHashLegacy . Byron.KeyHash <$> Byron.abstractHashFromBytes bs @@ -244,7 +244,7 @@ instance SerialiseAsRawBytes (VerificationKey ByronKeyLegacy) where serialiseToRawBytes (ByronVerificationKeyLegacy (Byron.VerificationKey xvk)) = Crypto.HD.unXPub xvk - eitherDeserialiseFromRawBytes (AsVerificationKey AsByronKeyLegacy) bs = + deserialiseFromRawBytes (AsVerificationKey AsByronKeyLegacy) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise VerificationKey ByronKeyLegacy" ++ msg)) $ ByronVerificationKeyLegacy . Byron.VerificationKey <$> Crypto.HD.xpub bs @@ -252,7 +252,7 @@ instance SerialiseAsRawBytes (SigningKey ByronKeyLegacy) where serialiseToRawBytes (ByronSigningKeyLegacy (Byron.SigningKey xsk)) = Crypto.HD.unXPrv xsk - eitherDeserialiseFromRawBytes (AsSigningKey AsByronKeyLegacy) bs = + deserialiseFromRawBytes (AsSigningKey AsByronKeyLegacy) bs = first (\e -> SerialiseAsRawBytesError ("Unable to deserialise SigningKey ByronKeyLegacy" ++ show e)) $ ByronSigningKeyLegacy . snd <$> CBOR.deserialiseFromBytes decodeLegacyDelegateKey (LB.fromStrict bs) where diff --git a/cardano-api/src/Cardano/Api/Keys/Class.hs b/cardano-api/src/Cardano/Api/Keys/Class.hs index 7090838baea..7945badef41 100644 --- a/cardano-api/src/Cardano/Api/Keys/Class.hs +++ b/cardano-api/src/Cardano/Api/Keys/Class.hs @@ -75,7 +75,7 @@ generateInsecureSigningKey -> IO (SigningKey keyrole, StdGen) generateInsecureSigningKey g keytype = do let (bs, g') = Random.genByteString (fromIntegral $ deterministicSigningKeySeedSize keytype) g - case eitherDeserialiseFromRawBytes (AsSigningKey keytype) bs of + case deserialiseFromRawBytes (AsSigningKey keytype) bs of Right key -> return (key, g') Left (SerialiseAsRawBytesError msg) -> error $ "generateInsecureSigningKey: Unable to generate insecure key: " <> msg diff --git a/cardano-api/src/Cardano/Api/Keys/Praos.hs b/cardano-api/src/Cardano/Api/Keys/Praos.hs index 1279456ee69..e50a1d07cda 100644 --- a/cardano-api/src/Cardano/Api/Keys/Praos.hs +++ b/cardano-api/src/Cardano/Api/Keys/Praos.hs @@ -97,7 +97,7 @@ instance SerialiseAsRawBytes (VerificationKey KesKey) where serialiseToRawBytes (KesVerificationKey vk) = Crypto.rawSerialiseVerKeyKES vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsKesKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsKesKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey KesKey") $ KesVerificationKey <$> Crypto.rawDeserialiseVerKeyKES bs @@ -105,7 +105,7 @@ instance SerialiseAsRawBytes (SigningKey KesKey) where serialiseToRawBytes (KesSigningKey sk) = Crypto.rawSerialiseSignKeyKES sk - eitherDeserialiseFromRawBytes (AsSigningKey AsKesKey) bs = + deserialiseFromRawBytes (AsSigningKey AsKesKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey KesKey") $ KesSigningKey <$> Crypto.rawDeserialiseSignKeyKES bs @@ -130,7 +130,7 @@ instance SerialiseAsRawBytes (Hash KesKey) where serialiseToRawBytes (KesKeyHash vkh) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsKesKey) bs = + deserialiseFromRawBytes (AsHash AsKesKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash KesKey") $ KesKeyHash <$> Crypto.hashFromBytes bs @@ -204,7 +204,7 @@ instance SerialiseAsRawBytes (VerificationKey VrfKey) where serialiseToRawBytes (VrfVerificationKey vk) = Crypto.rawSerialiseVerKeyVRF vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsVrfKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsVrfKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey VrfKey") $ VrfVerificationKey <$> Crypto.rawDeserialiseVerKeyVRF bs @@ -212,7 +212,7 @@ instance SerialiseAsRawBytes (SigningKey VrfKey) where serialiseToRawBytes (VrfSigningKey sk) = Crypto.rawSerialiseSignKeyVRF sk - eitherDeserialiseFromRawBytes (AsSigningKey AsVrfKey) bs = + deserialiseFromRawBytes (AsSigningKey AsVrfKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey VrfKey") $ VrfSigningKey <$> Crypto.rawDeserialiseSignKeyVRF bs @@ -236,7 +236,7 @@ instance SerialiseAsRawBytes (Hash VrfKey) where serialiseToRawBytes (VrfKeyHash vkh) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsVrfKey) bs = + deserialiseFromRawBytes (AsHash AsVrfKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash VrfKey") $ VrfKeyHash <$> Crypto.hashFromBytes bs diff --git a/cardano-api/src/Cardano/Api/Keys/Shelley.hs b/cardano-api/src/Cardano/Api/Keys/Shelley.hs index ce6f4e2cb4b..0ec6d14dbad 100644 --- a/cardano-api/src/Cardano/Api/Keys/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Keys/Shelley.hs @@ -117,7 +117,7 @@ instance SerialiseAsRawBytes (VerificationKey PaymentKey) where serialiseToRawBytes (PaymentVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsPaymentKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsPaymentKey) bs = maybe (Left (SerialiseAsRawBytesError "Unable to deserialise VerificationKey PaymentKey")) (Right . PaymentVerificationKey . Shelley.VKey) @@ -127,7 +127,7 @@ instance SerialiseAsRawBytes (SigningKey PaymentKey) where serialiseToRawBytes (PaymentSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsPaymentKey) bs = + deserialiseFromRawBytes (AsSigningKey AsPaymentKey) bs = maybe (Left (SerialiseAsRawBytesError "Unable to serialise AsSigningKey AsPaymentKey")) (Right . PaymentSigningKey) @@ -152,7 +152,7 @@ instance SerialiseAsRawBytes (Hash PaymentKey) where serialiseToRawBytes (PaymentKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsPaymentKey) bs = + deserialiseFromRawBytes (AsHash AsPaymentKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash PaymentKey") (PaymentKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs) @@ -264,7 +264,7 @@ instance SerialiseAsRawBytes (VerificationKey PaymentExtendedKey) where serialiseToRawBytes (PaymentExtendedVerificationKey xpub) = Crypto.HD.unXPub xpub - eitherDeserialiseFromRawBytes (AsVerificationKey AsPaymentExtendedKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsPaymentExtendedKey) bs = first (const (SerialiseAsRawBytesError "Unable to deserialise VerificationKey PaymentExtendedKey")) (PaymentExtendedVerificationKey <$> Crypto.HD.xpub bs) @@ -273,7 +273,7 @@ instance SerialiseAsRawBytes (SigningKey PaymentExtendedKey) where serialiseToRawBytes (PaymentExtendedSigningKey xprv) = Crypto.HD.unXPrv xprv - eitherDeserialiseFromRawBytes (AsSigningKey AsPaymentExtendedKey) bs = + deserialiseFromRawBytes (AsSigningKey AsPaymentExtendedKey) bs = first (const (SerialiseAsRawBytesError "Unable to deserialise SigningKey PaymentExtendedKey")) (PaymentExtendedSigningKey <$> Crypto.HD.xprv bs) @@ -298,7 +298,7 @@ instance SerialiseAsRawBytes (Hash PaymentExtendedKey) where serialiseToRawBytes (PaymentExtendedKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsPaymentExtendedKey) bs = + deserialiseFromRawBytes (AsHash AsPaymentExtendedKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash PaymentExtendedKey") $ PaymentExtendedKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -371,7 +371,7 @@ instance SerialiseAsRawBytes (VerificationKey StakeKey) where serialiseToRawBytes (StakeVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsStakeKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsStakeKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey StakeKey") $ StakeVerificationKey . Shelley.VKey <$> Crypto.rawDeserialiseVerKeyDSIGN bs @@ -380,7 +380,7 @@ instance SerialiseAsRawBytes (SigningKey StakeKey) where serialiseToRawBytes (StakeSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsStakeKey) bs = + deserialiseFromRawBytes (AsSigningKey AsStakeKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey StakeKey") $ StakeSigningKey <$> Crypto.rawDeserialiseSignKeyDSIGN bs @@ -404,7 +404,7 @@ instance SerialiseAsRawBytes (Hash StakeKey) where serialiseToRawBytes (StakeKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsStakeKey) bs = + deserialiseFromRawBytes (AsHash AsStakeKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash StakeKey") $ StakeKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -515,7 +515,7 @@ instance SerialiseAsRawBytes (VerificationKey StakeExtendedKey) where serialiseToRawBytes (StakeExtendedVerificationKey xpub) = Crypto.HD.unXPub xpub - eitherDeserialiseFromRawBytes (AsVerificationKey AsStakeExtendedKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsStakeExtendedKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise VerificationKey StakeExtendedKey: " ++ msg)) $ StakeExtendedVerificationKey <$> Crypto.HD.xpub bs @@ -523,7 +523,7 @@ instance SerialiseAsRawBytes (SigningKey StakeExtendedKey) where serialiseToRawBytes (StakeExtendedSigningKey xprv) = Crypto.HD.unXPrv xprv - eitherDeserialiseFromRawBytes (AsSigningKey AsStakeExtendedKey) bs = + deserialiseFromRawBytes (AsSigningKey AsStakeExtendedKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise SigningKey StakeExtendedKey: " ++ msg)) $ StakeExtendedSigningKey <$> Crypto.HD.xprv bs @@ -547,7 +547,7 @@ instance SerialiseAsRawBytes (Hash StakeExtendedKey) where serialiseToRawBytes (StakeExtendedKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsStakeExtendedKey) bs = + deserialiseFromRawBytes (AsHash AsStakeExtendedKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash StakeExtendedKey") $ StakeExtendedKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -619,7 +619,7 @@ instance SerialiseAsRawBytes (VerificationKey GenesisKey) where serialiseToRawBytes (GenesisVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsGenesisKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsGenesisKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey GenesisKey") $ GenesisVerificationKey . Shelley.VKey <$> Crypto.rawDeserialiseVerKeyDSIGN bs @@ -628,7 +628,7 @@ instance SerialiseAsRawBytes (SigningKey GenesisKey) where serialiseToRawBytes (GenesisSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsGenesisKey) bs = + deserialiseFromRawBytes (AsSigningKey AsGenesisKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey GenesisKey") $ GenesisSigningKey <$> Crypto.rawDeserialiseSignKeyDSIGN bs @@ -644,7 +644,7 @@ instance SerialiseAsRawBytes (Hash GenesisKey) where serialiseToRawBytes (GenesisKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsGenesisKey) bs = + deserialiseFromRawBytes (AsHash AsGenesisKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash GenesisKey") $ GenesisKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -756,7 +756,7 @@ instance SerialiseAsRawBytes (VerificationKey GenesisExtendedKey) where serialiseToRawBytes (GenesisExtendedVerificationKey xpub) = Crypto.HD.unXPub xpub - eitherDeserialiseFromRawBytes (AsVerificationKey AsGenesisExtendedKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsGenesisExtendedKey) bs = first (const (SerialiseAsRawBytesError "Unable to deserialise VerificationKey GenesisExtendedKey")) $ GenesisExtendedVerificationKey<$> Crypto.HD.xpub bs @@ -764,7 +764,7 @@ instance SerialiseAsRawBytes (SigningKey GenesisExtendedKey) where serialiseToRawBytes (GenesisExtendedSigningKey xprv) = Crypto.HD.unXPrv xprv - eitherDeserialiseFromRawBytes (AsSigningKey AsGenesisExtendedKey) bs = + deserialiseFromRawBytes (AsSigningKey AsGenesisExtendedKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise SigningKey GenesisExtendedKey" ++ msg)) $ GenesisExtendedSigningKey <$> Crypto.HD.xprv bs @@ -780,7 +780,7 @@ instance SerialiseAsRawBytes (Hash GenesisExtendedKey) where serialiseToRawBytes (GenesisExtendedKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsGenesisExtendedKey) bs = + deserialiseFromRawBytes (AsHash AsGenesisExtendedKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash GenesisExtendedKey") $ GenesisExtendedKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -853,7 +853,7 @@ instance SerialiseAsRawBytes (VerificationKey GenesisDelegateKey) where serialiseToRawBytes (GenesisDelegateVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsGenesisDelegateKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsGenesisDelegateKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey GenesisDelegateKey") $ GenesisDelegateVerificationKey . Shelley.VKey <$> Crypto.rawDeserialiseVerKeyDSIGN bs @@ -862,7 +862,7 @@ instance SerialiseAsRawBytes (SigningKey GenesisDelegateKey) where serialiseToRawBytes (GenesisDelegateSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsGenesisDelegateKey) bs = + deserialiseFromRawBytes (AsSigningKey AsGenesisDelegateKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey GenesisDelegateKey") $ GenesisDelegateSigningKey <$> Crypto.rawDeserialiseSignKeyDSIGN bs @@ -878,7 +878,7 @@ instance SerialiseAsRawBytes (Hash GenesisDelegateKey) where serialiseToRawBytes (GenesisDelegateKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsGenesisDelegateKey) bs = + deserialiseFromRawBytes (AsHash AsGenesisDelegateKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash GenesisDelegateKey") $ GenesisDelegateKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -994,7 +994,7 @@ instance SerialiseAsRawBytes (VerificationKey GenesisDelegateExtendedKey) where serialiseToRawBytes (GenesisDelegateExtendedVerificationKey xpub) = Crypto.HD.unXPub xpub - eitherDeserialiseFromRawBytes (AsVerificationKey AsGenesisDelegateExtendedKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsGenesisDelegateExtendedKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise VerificationKey GenesisDelegateExtendedKey: " ++ msg)) $ GenesisDelegateExtendedVerificationKey <$> Crypto.HD.xpub bs @@ -1002,7 +1002,7 @@ instance SerialiseAsRawBytes (SigningKey GenesisDelegateExtendedKey) where serialiseToRawBytes (GenesisDelegateExtendedSigningKey xprv) = Crypto.HD.unXPrv xprv - eitherDeserialiseFromRawBytes (AsSigningKey AsGenesisDelegateExtendedKey) bs = + deserialiseFromRawBytes (AsSigningKey AsGenesisDelegateExtendedKey) bs = first (\msg -> SerialiseAsRawBytesError ("Unable to deserialise SigningKey GenesisDelegateExtendedKey: " ++ msg)) $ GenesisDelegateExtendedSigningKey <$> Crypto.HD.xprv bs @@ -1018,7 +1018,7 @@ instance SerialiseAsRawBytes (Hash GenesisDelegateExtendedKey) where serialiseToRawBytes (GenesisDelegateExtendedKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsGenesisDelegateExtendedKey) bs = + deserialiseFromRawBytes (AsHash AsGenesisDelegateExtendedKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash GenesisDelegateExtendedKey: ") $ GenesisDelegateExtendedKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -1091,7 +1091,7 @@ instance SerialiseAsRawBytes (VerificationKey GenesisUTxOKey) where serialiseToRawBytes (GenesisUTxOVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsGenesisUTxOKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsGenesisUTxOKey) bs = maybeToRight (SerialiseAsRawBytesError "Enable to deserialise VerificationKey GenesisUTxOKey") $ GenesisUTxOVerificationKey . Shelley.VKey <$> Crypto.rawDeserialiseVerKeyDSIGN bs @@ -1099,7 +1099,7 @@ instance SerialiseAsRawBytes (SigningKey GenesisUTxOKey) where serialiseToRawBytes (GenesisUTxOSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsGenesisUTxOKey) bs = + deserialiseFromRawBytes (AsSigningKey AsGenesisUTxOKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise SigningKey GenesisUTxOKey") $ GenesisUTxOSigningKey <$> Crypto.rawDeserialiseSignKeyDSIGN bs @@ -1115,7 +1115,7 @@ instance SerialiseAsRawBytes (Hash GenesisUTxOKey) where serialiseToRawBytes (GenesisUTxOKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsGenesisUTxOKey) bs = + deserialiseFromRawBytes (AsHash AsGenesisUTxOKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash GenesisUTxOKey") $ GenesisUTxOKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs @@ -1192,7 +1192,7 @@ instance SerialiseAsRawBytes (VerificationKey StakePoolKey) where serialiseToRawBytes (StakePoolVerificationKey (Shelley.VKey vk)) = Crypto.rawSerialiseVerKeyDSIGN vk - eitherDeserialiseFromRawBytes (AsVerificationKey AsStakePoolKey) bs = + deserialiseFromRawBytes (AsVerificationKey AsStakePoolKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise VerificationKey StakePoolKey") $ StakePoolVerificationKey . Shelley.VKey <$> Crypto.rawDeserialiseVerKeyDSIGN bs @@ -1201,7 +1201,7 @@ instance SerialiseAsRawBytes (SigningKey StakePoolKey) where serialiseToRawBytes (StakePoolSigningKey sk) = Crypto.rawSerialiseSignKeyDSIGN sk - eitherDeserialiseFromRawBytes (AsSigningKey AsStakePoolKey) bs = + deserialiseFromRawBytes (AsSigningKey AsStakePoolKey) bs = maybe (Left (SerialiseAsRawBytesError "Unable to deserialise SigningKey StakePoolKey")) (Right . StakePoolSigningKey) @@ -1226,7 +1226,7 @@ instance SerialiseAsRawBytes (Hash StakePoolKey) where serialiseToRawBytes (StakePoolKeyHash (Shelley.KeyHash vkh)) = Crypto.hashToBytes vkh - eitherDeserialiseFromRawBytes (AsHash AsStakePoolKey) bs = + deserialiseFromRawBytes (AsHash AsStakePoolKey) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash StakePoolKey") (StakePoolKeyHash . Shelley.KeyHash <$> Crypto.hashFromBytes bs) diff --git a/cardano-api/src/Cardano/Api/ProtocolParameters.hs b/cardano-api/src/Cardano/Api/ProtocolParameters.hs index 4457fa2286a..bb9ae64a44a 100644 --- a/cardano-api/src/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/src/Cardano/Api/ProtocolParameters.hs @@ -85,7 +85,8 @@ import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto import Cardano.Slotting.Slot (EpochNo) -import Cardano.Ledger.Babbage.PParams (BabbagePParamsHKD(..), BabbagePParamsUpdate, BabbagePParams) +import Cardano.Ledger.Babbage.PParams (BabbagePParams, BabbagePParamsHKD (..), + BabbagePParamsUpdate) import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import qualified Cardano.Ledger.BaseTypes as Ledger import qualified Cardano.Ledger.Core as Ledger @@ -101,7 +102,8 @@ import Cardano.Ledger.Alonzo.PParams (AlonzoPParams, AlonzoPParamsHKD AlonzoPParamsUpdate) import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo import qualified Cardano.Ledger.Shelley.API as Ledger hiding (PParams) -import Cardano.Ledger.Shelley.PParams (ShelleyPParamsUpdate, ShelleyPParamsHKD (..), ShelleyPParams) +import Cardano.Ledger.Shelley.PParams (ShelleyPParams, ShelleyPParamsHKD (..), + ShelleyPParamsUpdate) import Text.PrettyBy.Default (display) @@ -686,7 +688,7 @@ instance SerialiseAsRawBytes PraosNonce where serialiseToRawBytes (PraosNonce h) = Crypto.hashToBytes h - eitherDeserialiseFromRawBytes AsPraosNonce bs = + deserialiseFromRawBytes AsPraosNonce bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise PraosNonce") $ PraosNonce <$> Crypto.hashFromBytes bs diff --git a/cardano-api/src/Cardano/Api/Script.hs b/cardano-api/src/Cardano/Api/Script.hs index aeaf2779515..78acb605b2a 100644 --- a/cardano-api/src/Cardano/Api/Script.hs +++ b/cardano-api/src/Cardano/Api/Script.hs @@ -935,7 +935,7 @@ instance SerialiseAsRawBytes ScriptHash where serialiseToRawBytes (ScriptHash (Shelley.ScriptHash h)) = Crypto.hashToBytes h - eitherDeserialiseFromRawBytes AsScriptHash bs = + deserialiseFromRawBytes AsScriptHash bs = maybeToRight (SerialiseAsRawBytesError "Enable to deserialise ScriptHash") $ ScriptHash . Shelley.ScriptHash <$> Crypto.hashFromBytes bs @@ -1076,7 +1076,7 @@ instance HasTypeProxy lang => HasTypeProxy (PlutusScript lang) where instance (HasTypeProxy lang, Typeable lang) => SerialiseAsRawBytes (PlutusScript lang) where serialiseToRawBytes (PlutusScriptSerialised sbs) = SBS.fromShort sbs - eitherDeserialiseFromRawBytes (AsPlutusScript _) bs = + deserialiseFromRawBytes (AsPlutusScript _) bs = -- TODO alonzo: validate the script syntax and fail decoding if invalid Right (PlutusScriptSerialised (SBS.toShort bs)) diff --git a/cardano-api/src/Cardano/Api/ScriptData.hs b/cardano-api/src/Cardano/Api/ScriptData.hs index 35e1087f314..f6d470a5323 100644 --- a/cardano-api/src/Cardano/Api/ScriptData.hs +++ b/cardano-api/src/Cardano/Api/ScriptData.hs @@ -118,7 +118,7 @@ instance SerialiseAsRawBytes (Hash ScriptData) where serialiseToRawBytes (ScriptDataHash dh) = Crypto.hashToBytes (Ledger.extractHash dh) - eitherDeserialiseFromRawBytes (AsHash AsScriptData) bs = + deserialiseFromRawBytes (AsHash AsScriptData) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash ScriptData") $ ScriptDataHash . Ledger.unsafeMakeSafeHash <$> Crypto.hashFromBytes bs diff --git a/cardano-api/src/Cardano/Api/SerialiseBech32.hs b/cardano-api/src/Cardano/Api/SerialiseBech32.hs index 94f39c28d0b..fe5daca06f7 100644 --- a/cardano-api/src/Cardano/Api/SerialiseBech32.hs +++ b/cardano-api/src/Cardano/Api/SerialiseBech32.hs @@ -66,7 +66,7 @@ deserialiseFromBech32 asType bech32Str = do payload <- Bech32.dataPartToBytes dataPart ?! Bech32DataPartToBytesError (Bech32.dataPartToText dataPart) - value <- case eitherDeserialiseFromRawBytes asType payload of + value <- case deserialiseFromRawBytes asType payload of Right a -> Right a Left _ -> Left $ Bech32DeserialiseFromBytesError payload @@ -95,7 +95,7 @@ deserialiseAnyOfFromBech32 types bech32Str = do payload <- Bech32.dataPartToBytes dataPart ?! Bech32DataPartToBytesError (Bech32.dataPartToText dataPart) - value <- case eitherDeserialiseFromRawBytes actualType payload of + value <- case deserialiseFromRawBytes actualType payload of Right a -> Right a Left _ -> Left $ Bech32DeserialiseFromBytesError payload diff --git a/cardano-api/src/Cardano/Api/SerialiseRaw.hs b/cardano-api/src/Cardano/Api/SerialiseRaw.hs index d294da1d8b3..030aa14dff7 100644 --- a/cardano-api/src/Cardano/Api/SerialiseRaw.hs +++ b/cardano-api/src/Cardano/Api/SerialiseRaw.hs @@ -9,6 +9,7 @@ module Cardano.Api.SerialiseRaw , SerialiseAsRawBytesError(..) , serialiseToRawBytesHex , deserialiseFromRawBytesHex + , eitherDeserialiseFromRawBytes , serialiseToRawBytesHexText ) where @@ -16,7 +17,6 @@ import Data.Bifunctor (Bifunctor (..)) import Data.ByteString (ByteString) import qualified Data.ByteString.Base16 as Base16 import Data.Data (typeRep) -import Data.Either.Combinators (rightToMaybe) import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text @@ -35,10 +35,11 @@ class (HasTypeProxy a, Typeable a) => SerialiseAsRawBytes a where serialiseToRawBytes :: a -> ByteString - deserialiseFromRawBytes :: AsType a -> ByteString -> Maybe a - deserialiseFromRawBytes asType bs = rightToMaybe $ eitherDeserialiseFromRawBytes asType bs + deserialiseFromRawBytes :: AsType a -> ByteString -> Either SerialiseAsRawBytesError a - eitherDeserialiseFromRawBytes :: AsType a -> ByteString -> Either SerialiseAsRawBytesError a +eitherDeserialiseFromRawBytes :: SerialiseAsRawBytes a => AsType a -> ByteString -> Either SerialiseAsRawBytesError a +eitherDeserialiseFromRawBytes = deserialiseFromRawBytes +{-# DEPRECATED eitherDeserialiseFromRawBytes "Use deserialiseFromRawBytes instead" #-} serialiseToRawBytesHex :: SerialiseAsRawBytes a => a -> ByteString serialiseToRawBytesHex = Base16.encode . serialiseToRawBytes @@ -74,6 +75,6 @@ deserialiseFromRawBytesHex => AsType a -> ByteString -> Either RawBytesHexError a deserialiseFromRawBytesHex proxy hex = do raw <- first (RawBytesHexErrorBase16DecodeFail hex) $ Base16.decode hex - case eitherDeserialiseFromRawBytes proxy raw of + case deserialiseFromRawBytes proxy raw of Left e -> Left $ RawBytesHexErrorRawBytesDecodeFail hex (typeRep proxy) e Right a -> Right a diff --git a/cardano-api/src/Cardano/Api/SerialiseUsing.hs b/cardano-api/src/Cardano/Api/SerialiseUsing.hs index bc4958b8f2c..7682278a245 100644 --- a/cardano-api/src/Cardano/Api/SerialiseUsing.hs +++ b/cardano-api/src/Cardano/Api/SerialiseUsing.hs @@ -39,7 +39,7 @@ instance SerialiseAsRawBytes a => ToCBOR (UsingRawBytes a) where instance SerialiseAsRawBytes a => FromCBOR (UsingRawBytes a) where fromCBOR = do bs <- fromCBOR - case eitherDeserialiseFromRawBytes ttoken bs of + case deserialiseFromRawBytes ttoken bs of Right x -> return (UsingRawBytes x) Left (SerialiseAsRawBytesError msg) -> fail ("cannot deserialise as a " ++ tname ++ ". The error was: " ++ msg) where @@ -87,7 +87,7 @@ deserialiseFromRawBytesBase16 :: SerialiseAsRawBytes a => ByteString -> Either String (UsingRawBytesHex a) deserialiseFromRawBytesBase16 str = case Base16.decode str of - Right raw -> case eitherDeserialiseFromRawBytes ttoken raw of + Right raw -> case deserialiseFromRawBytes ttoken raw of Right x -> Right (UsingRawBytesHex x) Left (SerialiseAsRawBytesError msg) -> Left ("cannot deserialise " ++ show str ++ ". The error was: " <> msg) Left msg -> Left ("invalid hex " ++ show str ++ ", " ++ msg) diff --git a/cardano-api/src/Cardano/Api/SpecialByron.hs b/cardano-api/src/Cardano/Api/SpecialByron.hs index de1ba7c10e3..6ffcc651f82 100644 --- a/cardano-api/src/Cardano/Api/SpecialByron.hs +++ b/cardano-api/src/Cardano/Api/SpecialByron.hs @@ -53,7 +53,7 @@ instance HasTypeProxy ByronUpdateProposal where instance SerialiseAsRawBytes ByronUpdateProposal where serialiseToRawBytes (ByronUpdateProposal proposal) = annotation proposal - eitherDeserialiseFromRawBytes AsByronUpdateProposal bs = + deserialiseFromRawBytes AsByronUpdateProposal bs = let lBs = LB.fromStrict bs in case Binary.decodeFull lBs of Left e -> Left $ SerialiseAsRawBytesError $ "Unable to deserialise ByronUpdateProposal: " <> show e @@ -166,7 +166,7 @@ instance HasTypeProxy ByronVote where instance SerialiseAsRawBytes ByronVote where serialiseToRawBytes (ByronVote vote) = Binary.serialize' $ fmap (const ()) vote - eitherDeserialiseFromRawBytes AsByronVote bs = + deserialiseFromRawBytes AsByronVote bs = let lBs = LB.fromStrict bs in case Binary.decodeFull lBs of Left e -> Left $ SerialiseAsRawBytesError $ "Unable to deserialise ByronVote: " <> show e diff --git a/cardano-api/src/Cardano/Api/StakePoolMetadata.hs b/cardano-api/src/Cardano/Api/StakePoolMetadata.hs index fd4701d6eec..d3b6c77cee7 100644 --- a/cardano-api/src/Cardano/Api/StakePoolMetadata.hs +++ b/cardano-api/src/Cardano/Api/StakePoolMetadata.hs @@ -77,7 +77,7 @@ instance HasTypeProxy StakePoolMetadata where instance SerialiseAsRawBytes (Hash StakePoolMetadata) where serialiseToRawBytes (StakePoolMetadataHash h) = Crypto.hashToBytes h - eitherDeserialiseFromRawBytes (AsHash AsStakePoolMetadata) bs = + deserialiseFromRawBytes (AsHash AsStakePoolMetadata) bs = maybeToRight (SerialiseAsRawBytesError "Unable to deserialise Hash StakePoolMetadata") $ StakePoolMetadataHash <$> Crypto.hashFromBytes bs diff --git a/cardano-api/src/Cardano/Api/TxIn.hs b/cardano-api/src/Cardano/Api/TxIn.hs index 4ee31351d29..0e7b36334fc 100644 --- a/cardano-api/src/Cardano/Api/TxIn.hs +++ b/cardano-api/src/Cardano/Api/TxIn.hs @@ -90,7 +90,7 @@ instance HasTypeProxy TxId where instance SerialiseAsRawBytes TxId where serialiseToRawBytes (TxId h) = Crypto.hashToBytes h - eitherDeserialiseFromRawBytes AsTxId bs = case Crypto.hashFromBytes bs of + deserialiseFromRawBytes AsTxId bs = case Crypto.hashFromBytes bs of Just a -> Right (TxId a) Nothing -> Left $ SerialiseAsRawBytesError "Unable to deserialise TxId" diff --git a/cardano-api/src/Cardano/Api/Value.hs b/cardano-api/src/Cardano/Api/Value.hs index c7d09c48492..56e4996cb9a 100644 --- a/cardano-api/src/Cardano/Api/Value.hs +++ b/cardano-api/src/Cardano/Api/Value.hs @@ -83,7 +83,7 @@ import Cardano.Api.SerialiseCBOR import Cardano.Api.SerialiseRaw import Cardano.Api.SerialiseUsing import Cardano.Api.Utils (failEitherWith) -import Cardano.Ledger.Mary.Value (MaryValue (..)) +import Cardano.Ledger.Mary.Value (MaryValue (..)) import qualified Cardano.Ledger.Mary.Value as Mary import qualified Cardano.Ledger.ShelleyMA.Rules as Shelley @@ -152,8 +152,8 @@ instance HasTypeProxy PolicyId where instance SerialiseAsRawBytes PolicyId where serialiseToRawBytes (PolicyId sh) = serialiseToRawBytes sh - eitherDeserialiseFromRawBytes AsPolicyId bs = - PolicyId <$> eitherDeserialiseFromRawBytes AsScriptHash bs + deserialiseFromRawBytes AsPolicyId bs = + PolicyId <$> deserialiseFromRawBytes AsScriptHash bs scriptPolicyId :: Script lang -> PolicyId scriptPolicyId = PolicyId . hashScript @@ -177,7 +177,7 @@ instance HasTypeProxy AssetName where instance SerialiseAsRawBytes AssetName where serialiseToRawBytes (AssetName bs) = bs - eitherDeserialiseFromRawBytes AsAssetName bs + deserialiseFromRawBytes AsAssetName bs | BS.length bs <= 32 = Right (AssetName bs) | otherwise = Left $ SerialiseAsRawBytesError $ "Unable to deserialise AssetName (the bytestring should be no longer than 32 bytes long " <> diff --git a/cardano-api/test/Test/Cardano/Api/Typed/RawBytes.hs b/cardano-api/test/Test/Cardano/Api/Typed/RawBytes.hs index 21c60bb92bc..1deac1f1526 100644 --- a/cardano-api/test/Test/Cardano/Api/Typed/RawBytes.hs +++ b/cardano-api/test/Test/Cardano/Api/Typed/RawBytes.hs @@ -80,7 +80,7 @@ roundtrip_raw_bytes roundtrip_raw_bytes asType g = H.property $ do v <- H.forAll g - H.tripping v serialiseToRawBytes (eitherDeserialiseFromRawBytes asType) + H.tripping v serialiseToRawBytes (deserialiseFromRawBytes asType) roundtrip_verification_key_hash_raw :: (Key keyrole, Eq (Hash keyrole), Show (Hash keyrole)) @@ -89,7 +89,7 @@ roundtrip_verification_key_hash_raw roletoken = H.property $ do vKey <- H.forAll $ genVerificationKey roletoken let vKeyHash = verificationKeyHash vKey - H.tripping vKeyHash serialiseToRawBytes (eitherDeserialiseFromRawBytes (AsHash roletoken)) + H.tripping vKeyHash serialiseToRawBytes (deserialiseFromRawBytes (AsHash roletoken)) -- ----------------------------------------------------------------------------- diff --git a/cardano-cli/src/Cardano/CLI/Byron/Key.hs b/cardano-cli/src/Cardano/CLI/Byron/Key.hs index 0fef29da98b..81929fdf16b 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Key.hs @@ -86,11 +86,11 @@ readByronSigningKey bKeyFormat (SigningKeyFile fp) = do sK <- handleIOExceptT (ReadSigningKeyFailure fp . T.pack . displayException) $ SB.readFile fp case bKeyFormat of LegacyByronKeyFormat -> - case eitherDeserialiseFromRawBytes (AsSigningKey AsByronKeyLegacy) sK of + case deserialiseFromRawBytes (AsSigningKey AsByronKeyLegacy) sK of Right legKey -> right $ AByronSigningKeyLegacy legKey Left _ -> left $ LegacySigningKeyDeserialisationFailed fp NonLegacyByronKeyFormat -> - case eitherDeserialiseFromRawBytes (AsSigningKey AsByronKey) sK of + case deserialiseFromRawBytes (AsSigningKey AsByronKey) sK of Right nonLegSKey -> right $ AByronSigningKey nonLegSKey Left _ -> left $ SigningKeyDeserialisationFailed fp diff --git a/cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs b/cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs index 70a134bfc02..ac29597bd95 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs @@ -77,7 +77,7 @@ readByronUpdateProposal :: FilePath -> ExceptT ByronUpdateProposalError IO Byron readByronUpdateProposal fp = do proposalBs <- handleIOExceptT (ByronReadUpdateProposalFileFailure fp . toS . displayException) $ BS.readFile fp - let proposalResult = eitherDeserialiseFromRawBytes AsByronUpdateProposal proposalBs + let proposalResult = deserialiseFromRawBytes AsByronUpdateProposal proposalBs hoistEither $ first (const (UpdateProposalDecodingError fp)) proposalResult submitByronUpdateProposal diff --git a/cardano-cli/src/Cardano/CLI/Byron/Vote.hs b/cardano-cli/src/Cardano/CLI/Byron/Vote.hs index e578987ae81..0899762dc4d 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Vote.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Vote.hs @@ -83,5 +83,5 @@ submitByronVote network voteFp = do readByronVote :: FilePath -> ExceptT ByronVoteError IO ByronVote readByronVote fp = do voteBs <- liftIO $ BS.readFile fp - let voteResult = eitherDeserialiseFromRawBytes AsByronVote voteBs + let voteResult = deserialiseFromRawBytes AsByronVote voteBs hoistEither $ first (const (ByronVoteDecodingError fp)) voteResult diff --git a/cardano-cli/test/Test/Golden/Byron/SigningKeys.hs b/cardano-cli/test/Test/Golden/Byron/SigningKeys.hs index 5188eaf36c0..af92e8967cd 100644 --- a/cardano-cli/test/Test/Golden/Byron/SigningKeys.hs +++ b/cardano-cli/test/Test/Golden/Byron/SigningKeys.hs @@ -72,7 +72,7 @@ prop_print_nonLegacy_signing_key_address = propertyOnce $ do prop_generate_and_read_nonlegacy_signingkeys :: Property prop_generate_and_read_nonlegacy_signingkeys = property $ do byronSkey <- liftIO $ generateSigningKey AsByronKey - case eitherDeserialiseFromRawBytes (AsSigningKey AsByronKey) (serialiseToRawBytes byronSkey) of + case deserialiseFromRawBytes (AsSigningKey AsByronKey) (serialiseToRawBytes byronSkey) of Left _ -> failWith Nothing "Failed to deserialise non-legacy Byron signing key. " Right _ -> success diff --git a/cardano-node/src/Cardano/Node/Protocol/Byron.hs b/cardano-node/src/Cardano/Node/Protocol/Byron.hs index 75d77eec7ef..314a331ff9f 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Byron.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Byron.hs @@ -158,7 +158,7 @@ readLeaderCredentials genesisConfig delegCertFileBytes <- liftIO $ LB.readFile delegCertFile ByronSigningKey signingKey <- firstExceptT (const (SigningKeyDeserialiseFailure signingKeyFile)) . hoistEither - $ eitherDeserialiseFromRawBytes (AsSigningKey AsByronKey) $ LB.toStrict signingKeyFileBytes + $ deserialiseFromRawBytes (AsSigningKey AsByronKey) $ LB.toStrict signingKeyFileBytes delegCert <- firstExceptT (CanonicalDecodeFailure delegCertFile) . hoistEither $ canonicalDecodePretty delegCertFileBytes