Skip to content

Commit

Permalink
Remove toUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Oct 10, 2024
1 parent c68d32c commit ddfa0a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $
Expand Down
14 changes: 3 additions & 11 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakePool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
:: ()
Expand Down Expand Up @@ -238,7 +235,7 @@ runStakePoolMetadataHashCmd
. newExceptT
$ readByteStringFile poolMetadataFile
StakePoolMetadataURL urlText ->
fetchURLToStakePoolCmdError $ getByteStringFromURL allSchemas urlText
fetchURLToStakePoolCmdError $ getByteStringFromURL allSchemas $ L.urlToText urlText

(_metadata, metadataHash) <-
firstExceptT StakePoolCmdMetadataValidationError
Expand Down Expand Up @@ -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

Expand All @@ -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
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/Run/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:"
Expand Down

0 comments on commit ddfa0a2

Please sign in to comment.