Skip to content

Commit

Permalink
Straight line code.
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 14, 2023
1 parent c5ca9c2 commit 60529cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
47 changes: 24 additions & 23 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Cardano.CLI.Shelley.Run.Governance

import Control.Monad (unless, when)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, left, newExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, left, newExceptT,
onLeft)
import Data.Aeson (eitherDecode)
import qualified Data.ByteString.Lazy as LB
import Data.Text (Text)
Expand All @@ -21,6 +22,8 @@ import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Types

import qualified Cardano.Ledger.Shelley.TxBody as Shelley
import Control.Monad.IO.Unlift (MonadIO (..))
import Data.Function ((&))


data ShelleyGovernanceCmdError
Expand Down Expand Up @@ -152,26 +155,24 @@ runGovernanceUpdateProposal
-> Maybe FilePath -- ^ Cost models file path
-> ExceptT ShelleyGovernanceCmdError IO ()
runGovernanceUpdateProposal (OutputFile upFile) eNo genVerKeyFiles upPprams mCostModelFp = do
finalUpPprams
<- case mCostModelFp of
Nothing -> return upPprams
Just fp -> do
costModelsBs <-
handleIOExceptT (ShelleyGovernanceCmdCostModelReadError . FileIOError fp)
$ LB.readFile fp
case eitherDecode costModelsBs of
Right cModels -> return $ upPprams {protocolUpdateCostModels = fromAlonzoCostModels cModels}
Left err -> left $ ShelleyGovernanceCmdCostModelsJsonDecodeErr fp $ Text.pack err

when (finalUpPprams == mempty) $ left ShelleyGovernanceCmdEmptyUpdateProposalError
genVKeys <- sequence
[ firstExceptT ShelleyGovernanceCmdTextEnvReadError . newExceptT $
readFileTextEnvelope
(AsVerificationKey AsGenesisKey)
vkeyFile
| VerificationKeyFile vkeyFile <- genVerKeyFiles ]
let genKeyHashes = fmap verificationKeyHash genVKeys
upProp = makeShelleyUpdateProposal finalUpPprams genKeyHashes eNo
firstExceptT ShelleyGovernanceCmdTextEnvWriteError . newExceptT $
writeFileTextEnvelope upFile Nothing upProp
finalUpPprams <- case mCostModelFp of
Nothing -> return upPprams
Just fp -> do
costModelsBs <- handleIOExceptT (ShelleyGovernanceCmdCostModelReadError . FileIOError fp) $ LB.readFile fp

cModels <- pure (eitherDecode costModelsBs)
& onLeft (left . ShelleyGovernanceCmdCostModelsJsonDecodeErr fp . Text.pack)

return $ upPprams {protocolUpdateCostModels = fromAlonzoCostModels cModels}

when (finalUpPprams == mempty) $ left ShelleyGovernanceCmdEmptyUpdateProposalError

genVKeys <- sequence
[ firstExceptT ShelleyGovernanceCmdTextEnvReadError . newExceptT $ readFileTextEnvelope (AsVerificationKey AsGenesisKey) vkeyFile
| VerificationKeyFile vkeyFile <- genVerKeyFiles
]
let genKeyHashes = fmap verificationKeyHash genVKeys
upProp = makeShelleyUpdateProposal finalUpPprams genKeyHashes eNo

firstExceptT ShelleyGovernanceCmdTextEnvWriteError . newExceptT $ writeFileTextEnvelope upFile Nothing upProp

5 changes: 5 additions & 0 deletions update.proposal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "UpdateProposalShelley",
"description": "",
"cborHex": "82a1581c5c5dbf04f506922566f737301c824847df1e2ceadb979e8ccb29070b981a818208008080808080808080808080808080808080a0808081821b00000004a817c8001a03b20b80808080801832"
}

0 comments on commit 60529cc

Please sign in to comment.