3
3
{-# LANGUAGE GADTs #-}
4
4
{-# LANGUAGE LambdaCase #-}
5
5
{-# LANGUAGE NamedFieldPuns #-}
6
+ {-# LANGUAGE RankNTypes #-}
6
7
{-# LANGUAGE ScopedTypeVariables #-}
8
+ {-# LANGUAGE TypeApplications #-}
7
9
8
10
module Cardano.CLI.Legacy.Governance.Run
9
11
( runLegacyGovernanceCmds
@@ -14,24 +16,24 @@ import Cardano.Api
14
16
import Cardano.Api.Ledger qualified as L
15
17
import Cardano.Api.Shelley
16
18
19
+ import Cardano.CLI.Compatible.Exception
17
20
import Cardano.CLI.EraBased.Governance.GenesisKeyDelegationCertificate.Run
18
21
( runGovernanceGenesisKeyDelegationCertificate
19
22
)
20
23
import Cardano.CLI.EraBased.Governance.Poll.Command qualified as Cmd
21
24
import Cardano.CLI.EraBased.Governance.Poll.Run
22
25
import Cardano.CLI.EraBased.Governance.Run
23
26
import Cardano.CLI.Legacy.Governance.Command
27
+ import Cardano.CLI.Orphan ()
24
28
import Cardano.CLI.Type.Common
25
29
import Cardano.CLI.Type.Error.GovernanceCmdError
26
30
27
31
import Control.Monad
28
32
import Data.Aeson (eitherDecode )
29
33
import Data.ByteString.Lazy qualified as LB
30
- import Data.Function ((&) )
31
34
import Data.Text (Text )
32
- import Data.Text qualified as Text
33
35
34
- runLegacyGovernanceCmds :: LegacyGovernanceCmds -> ExceptT GovernanceCmdError IO ()
36
+ runLegacyGovernanceCmds :: LegacyGovernanceCmds -> CIO e ()
35
37
runLegacyGovernanceCmds = \ case
36
38
GovernanceCreateMirCertificateStakeAddressesCmd anyEra mirpot vKeys rewards out ->
37
39
runLegacyGovernanceMIRCertificatePayStakeAddrs anyEra mirpot vKeys rewards out
@@ -56,7 +58,7 @@ runLegacyGovernanceCreatePoll
56
58
-> [Text ]
57
59
-> Maybe Word
58
60
-> File GovernancePoll Out
59
- -> ExceptT GovernanceCmdError IO ()
61
+ -> CIO e ()
60
62
runLegacyGovernanceCreatePoll prompt choices nonce outFile =
61
63
runGovernanceCreatePollCmd
62
64
Cmd. GovernanceCreatePollCmdArgs
@@ -72,7 +74,7 @@ runLegacyGovernanceAnswerPoll
72
74
=> File GovernancePoll In
73
75
-> Maybe Word
74
76
-> Maybe (File () Out )
75
- -> ExceptT GovernanceCmdError IO ()
77
+ -> CIO e ()
76
78
runLegacyGovernanceAnswerPoll pollFile answerIndex mOutFile =
77
79
runGovernanceAnswerPollCmd
78
80
Cmd. GovernanceAnswerPollCmdArgs
@@ -87,7 +89,7 @@ runLegacyGovernanceVerifyPoll
87
89
=> File GovernancePoll In
88
90
-> File (Tx () ) In
89
91
-> Maybe (File () Out )
90
- -> ExceptT GovernanceCmdError IO ()
92
+ -> CIO e ()
91
93
runLegacyGovernanceVerifyPoll pollFile txFile mOutFile =
92
94
runGovernanceVerifyPollCmd
93
95
Cmd. GovernanceVerifyPollCmdArgs
@@ -105,23 +107,23 @@ runLegacyGovernanceMIRCertificatePayStakeAddrs
105
107
-> [Lovelace ]
106
108
-- ^ Corresponding reward amounts (same length)
107
109
-> File () Out
108
- -> ExceptT GovernanceCmdError IO ()
110
+ -> CIO e ()
109
111
runLegacyGovernanceMIRCertificatePayStakeAddrs (EraInEon w) =
110
112
runGovernanceMIRCertificatePayStakeAddrs w
111
113
112
114
runLegacyGovernanceCreateMirCertificateTransferToTreasuryCmd
113
115
:: EraInEon ShelleyToBabbageEra
114
116
-> Lovelace
115
117
-> File () Out
116
- -> ExceptT GovernanceCmdError IO ()
118
+ -> CIO e ()
117
119
runLegacyGovernanceCreateMirCertificateTransferToTreasuryCmd (EraInEon w) =
118
120
runGovernanceCreateMirCertificateTransferToTreasuryCmd w
119
121
120
122
runLegacyGovernanceCreateMirCertificateTransferToReservesCmd
121
123
:: EraInEon ShelleyToBabbageEra
122
124
-> Lovelace
123
125
-> File () Out
124
- -> ExceptT GovernanceCmdError IO ()
126
+ -> CIO e ()
125
127
runLegacyGovernanceCreateMirCertificateTransferToReservesCmd (EraInEon w) =
126
128
runGovernanceCreateMirCertificateTransferToReservesCmd w
127
129
@@ -133,34 +135,33 @@ runLegacyGovernanceUpdateProposal
133
135
-> ProtocolParametersUpdate
134
136
-> Maybe FilePath
135
137
-- ^ Cost models file path
136
- -> ExceptT GovernanceCmdError IO ()
138
+ -> CIO e ()
137
139
runLegacyGovernanceUpdateProposal upFile eNo genVerKeyFiles upPprams mCostModelFp = do
138
140
finalUpPprams <- case mCostModelFp of
139
141
Nothing -> return upPprams
140
142
Just fp -> do
141
- costModelsBs <- handleIOExceptT ( GovernanceCmdCostModelReadError . FileIOError fp) $ LB. readFile fp
143
+ costModelsBs <- readFileCli fp
142
144
143
145
cModels <-
144
- pure (eitherDecode costModelsBs)
145
- & onLeft (left . GovernanceCmdCostModelsJsonDecodeErr fp . Text. pack)
146
+ fromEitherCli (eitherDecode $ LB. fromStrict costModelsBs)
146
147
147
148
let costModels = fromAlonzoCostModels cModels
148
149
149
- when (null costModels) $ left (GovernanceCmdEmptyCostModel fp)
150
+ when (null costModels) $ throwCliError (GovernanceCmdEmptyCostModel fp)
150
151
151
152
return $ upPprams{protocolUpdateCostModels = costModels}
152
153
153
- when (finalUpPprams == mempty ) $ left GovernanceCmdEmptyUpdateProposalError
154
+ when (finalUpPprams == mempty ) $ throwCliError GovernanceCmdEmptyUpdateProposalError
154
155
155
156
genVKeys <-
156
157
sequence
157
- [ firstExceptT GovernanceCmdTextEnvReadError . newExceptT $
158
+ [ fromEitherIOCli $
158
159
readFileTextEnvelope (AsVerificationKey AsGenesisKey ) vkeyFile
159
160
| vkeyFile <- genVerKeyFiles
160
161
]
161
162
let genKeyHashes = fmap verificationKeyHash genVKeys
162
163
upProp = makeShelleyUpdateProposal finalUpPprams genKeyHashes eNo
163
164
164
- firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $
165
+ fromEitherIOCli @ ( FileError () ) $
165
166
writeLazyByteStringFile upFile $
166
167
textEnvelopeToJSON Nothing upProp
0 commit comments