diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index b31bc17055..7faa12f9a2 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -526,7 +526,7 @@ carryHashChecks checkHash anchor checkType = L.AnchorData <$> fetchURLErrorToGovernanceActionError checkType - (getByteStringFromURL httpsAndIpfsSchemas $ L.anchorUrl anchor) + (getByteStringFromURL httpsAndIpfsSchemas $ L.urlToText $ L.anchorUrl anchor) let hash = L.hashAnchorData anchorData when (hash /= L.anchorDataHash anchor) $ left $ diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs index a8644d579e..b00dfbaf17 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -187,7 +187,7 @@ runGovernanceDRepMetadataHashCmd Cmd.DrepMetadataFileIn metadataFile -> firstExceptT ReadFileError . newExceptT $ readByteStringFile metadataFile Cmd.DrepMetadataURL urlText -> - fetchURLToGovernanceCmdError $ getByteStringFromURL allSchemas urlText + fetchURLToGovernanceCmdError $ getByteStringFromURL allSchemas $ L.urlToText urlText let (_metadata, metadataHash) = hashDRepMetadata metadataBytes case hashGoal of Cmd.CheckHash expectedHash @@ -225,7 +225,7 @@ carryHashChecks potentiallyCheckedAnchor = L.AnchorData <$> withExceptT FetchURLError - (getByteStringFromURL httpsAndIpfsSchemas $ L.anchorUrl anchor) + (getByteStringFromURL httpsAndIpfsSchemas $ L.urlToText $ L.anchorUrl anchor) let hash = L.hashAnchorData anchorData when (hash /= L.anchorDataHash anchor) $ left $ diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs index 44a03d84e2..15ea5d6e59 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs @@ -28,9 +28,6 @@ import Cardano.CLI.Types.Key (readVerificationKeyOrFile) import Control.Monad (when) import qualified Data.ByteString.Char8 as BS -import Data.Maybe (fromMaybe) -import Data.Text (Text) -import Data.Text.Encoding (encodeUtf8) runStakePoolCmds :: () @@ -238,7 +235,7 @@ runStakePoolMetadataHashCmd . newExceptT $ readByteStringFile poolMetadataFile StakePoolMetadataURL urlText -> - fetchURLToStakePoolCmdError $ getByteStringFromURL allSchemas urlText + fetchURLToStakePoolCmdError $ getByteStringFromURL allSchemas $ L.urlToText urlText (_metadata, metadataHash) <- firstExceptT StakePoolCmdMetadataValidationError @@ -274,11 +271,11 @@ carryHashChecks carryHashChecks potentiallyCheckedAnchor = case pcaMustCheck potentiallyCheckedAnchor of CheckHash -> do - let url = toUrl $ stakePoolMetadataURL anchor + let urlText = stakePoolMetadataURL anchor metadataBytes <- withExceptT StakePoolCmdFetchURLError - (getByteStringFromURL httpsAndIpfsSchemas url) + (getByteStringFromURL httpsAndIpfsSchemas urlText) let expectedHash = stakePoolMetadataHash anchor @@ -293,8 +290,3 @@ carryHashChecks potentiallyCheckedAnchor = TrustHash -> pure () where anchor = pcaAnchor potentiallyCheckedAnchor - - toUrl :: Text -> L.Url - toUrl t = - let l = BS.length (encodeUtf8 t) - in fromMaybe (error "Internal Error: length of URL was miscalculated") $ L.textToUrl l t diff --git a/cardano-cli/src/Cardano/CLI/Run/Hash.hs b/cardano-cli/src/Cardano/CLI/Run/Hash.hs index 4add99eab0..1394d525e9 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Hash.hs @@ -33,6 +33,7 @@ import qualified Data.ByteString.Lazy.Char8 as BSL8 import Data.Char (toLower) import Data.Function import Data.List (intercalate) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import qualified Data.Text.IO as Text @@ -68,7 +69,7 @@ runHashAnchorDataCmd Cmd.HashAnchorDataCmdArgs{toHash, hashGoal} = do return $ Text.encodeUtf8 text Cmd.AnchorDataHashSourceText text -> return $ Text.encodeUtf8 text Cmd.AnchorDataHashSourceURL urlText -> - fetchURLToHashCmdError $ getByteStringFromURL allSchemas urlText + fetchURLToHashCmdError $ getByteStringFromURL allSchemas $ L.urlToText urlText let hash = L.hashAnchorData anchorData case hashGoal of CheckHash expectedHash @@ -100,9 +101,9 @@ allSchemas = [FileSchema, HttpSchema, HttpsSchema, IpfsSchema] httpsAndIpfsSchemas :: [SupportedSchemas] httpsAndIpfsSchemas = [HttpsSchema, IpfsSchema] -getByteStringFromURL :: [SupportedSchemas] -> L.Url -> ExceptT FetchURLError IO BS.ByteString +getByteStringFromURL :: [SupportedSchemas] -> Text -> ExceptT FetchURLError IO BS.ByteString getByteStringFromURL supportedSchemas urlText = do - let urlString = Text.unpack $ L.urlToText urlText + let urlString = Text.unpack urlText uri <- hoistMaybe (FetchURLInvalidURLError urlString) $ parseAbsoluteURI urlString case map toLower $ uriScheme uri of "file:"