Skip to content

Commit

Permalink
Propagate Cardano.CLI.Shelley.Run.Read and Cardano.CLI.Shelley.Run.Va…
Browse files Browse the repository at this point in the history
…lidate

throughout cardano-cli
Delete Cardano.CLI.Shelley.Script
Remove CddlTx data type
  • Loading branch information
Jimbo4350 committed Oct 10, 2022
1 parent 84b6a13 commit 44bee30
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 925 deletions.
3 changes: 2 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ library
Cardano.CLI.Shelley.Run.StakeAddress
Cardano.CLI.Shelley.Run.TextView
Cardano.CLI.Shelley.Run.Transaction
Cardano.CLI.Shelley.Script
Cardano.CLI.Shelley.Run.Read
Cardano.CLI.Shelley.Run.Validate

Cardano.CLI.TopHandler

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Cardano.CLI.Shelley.Key (InputDecodeError, PaymentVerifier (..)
readVerificationKeyTextOrFileAnyOf, renderVerificationKeyTextOrFileError)
import Cardano.CLI.Shelley.Parsers (AddressCmd (..), AddressKeyType (..), OutputFile (..))
import Cardano.CLI.Shelley.Run.Address.Info (ShelleyAddressInfoError, runAddressInfo)
import Cardano.CLI.Shelley.Script
import Cardano.CLI.Shelley.Run.Read
import Cardano.CLI.Types

data ShelleyAddressCmdError
Expand Down
41 changes: 40 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module Cardano.CLI.Shelley.Run.Genesis
, readAndDecodeShelleyGenesis
, readAlonzoGenesis
, runGenesisCmd

-- * Protocol Parameters
, ProtocolParamsError(..)
, renderProtocolParamsError
, readProtocolParameters
, readProtocolParametersSourceSpec
) where

import Cardano.Prelude hiding (unlines)
Expand Down Expand Up @@ -104,7 +110,7 @@ import Cardano.Chain.Common (BlockCount (unBlockCount))
import Cardano.Chain.Delegation (delegateVK)
import qualified Cardano.Chain.Delegation as Dlg
import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Chain.Update
import Cardano.Chain.Update hiding (ProtocolParameters)
import Cardano.Slotting.Slot (EpochSize (EpochSize))
import Data.Fixed (Fixed (MkFixed))
import qualified Data.Yaml as Yaml
Expand Down Expand Up @@ -1314,3 +1320,36 @@ readAlonzoGenesis fpath = do
lbs <- handleIOExceptT (ShelleyGenesisCmdGenesisFileError . FileIOError fpath) $ LBS.readFile fpath
firstExceptT (ShelleyGenesisCmdAesonDecodeError fpath . Text.pack)
. hoistEither $ Aeson.eitherDecode' lbs


-- Protocol Parameters

data ProtocolParamsError
= ProtocolParamsErrorFile (FileError ())
| ProtocolParamsErrorJSON !FilePath !Text
| ProtocolParamsErrorGenesis !ShelleyGenesisCmdError

renderProtocolParamsError :: ProtocolParamsError -> Text
renderProtocolParamsError (ProtocolParamsErrorFile fileErr) =
Text.pack $ displayError fileErr
renderProtocolParamsError (ProtocolParamsErrorJSON fp jsonErr) =
"Error while decoding the protocol parameters at: " <> Text.pack fp <> " Error: " <> jsonErr
renderProtocolParamsError (ProtocolParamsErrorGenesis err) =
Text.pack $ displayError err

readProtocolParametersSourceSpec :: ProtocolParamsSourceSpec
-> ExceptT ProtocolParamsError IO ProtocolParameters
readProtocolParametersSourceSpec (ParamsFromGenesis (GenesisFile f)) =
fromShelleyPParams . sgProtocolParams
<$> firstExceptT ProtocolParamsErrorGenesis (readShelleyGenesisWithDefault f id)
readProtocolParametersSourceSpec (ParamsFromFile f) = readProtocolParameters f

--TODO: eliminate this and get only the necessary params, and get them in a more
-- helpful way rather than requiring them as a local file.
readProtocolParameters :: ProtocolParamsFile
-> ExceptT ProtocolParamsError IO ProtocolParameters
readProtocolParameters (ProtocolParamsFile fpath) = do
pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
Aeson.eitherDecode' pparams

2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Cardano.CLI.Shelley.Key (InputDecodeError, StakeVerifier (..),
VerificationKeyOrFile, VerificationKeyOrHashOrFile, readVerificationKeyOrFile,
readVerificationKeyOrHashOrFile)
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Shelley.Script (ScriptDecodeError, readFileScriptInAnyLang)
import Cardano.CLI.Shelley.Run.Read
import Cardano.CLI.Types

data ShelleyStakeAddressCmdError
Expand Down
980 changes: 162 additions & 818 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs

Large diffs are not rendered by default.

97 changes: 0 additions & 97 deletions cardano-cli/src/Cardano/CLI/Shelley/Script.hs

This file was deleted.

7 changes: 2 additions & 5 deletions cardano-cli/src/Cardano/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
module Cardano.CLI.Types
( BalanceTxExecUnits (..)
, CBORObject (..)
, CddlTx (..)
, CertificateFile (..)
, CurrentKesPeriod (..)
, EpochLeadershipSchedule (..)
Expand Down Expand Up @@ -51,8 +50,8 @@ import Data.Word (Word64)
import qualified Cardano.Chain.Slotting as Byron

import Cardano.Api (AddressAny, AnyScriptLanguage, EpochNo, ExecutionUnits, Hash,
InAnyCardanoEra, PaymentKey, PolicyId, ScriptData, SlotNo (SlotNo), Tx, TxIn,
Value, WitCtxMint, WitCtxStake, WitCtxTxIn)
PaymentKey, PolicyId, ScriptData, SlotNo (SlotNo), TxIn, Value, WitCtxMint,
WitCtxStake, WitCtxTxIn)

import qualified Cardano.Ledger.Crypto as Crypto

Expand All @@ -74,8 +73,6 @@ data CBORObject = CBORBlockByron Byron.EpochSlots
| CBORVoteByron
deriving Show

newtype CddlTx = CddlTx {unCddlTx :: InAnyCardanoEra Tx} deriving (Show, Eq)

-- Encompasses stake certificates, stake pool certificates,
-- genesis delegate certificates and MIR certificates.
newtype CertificateFile = CertificateFile { unCertificateFile :: FilePath }
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/Test/OptParse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import qualified GHC.Stack as GHC

import Cardano.Api

import Cardano.CLI.Shelley.Run.Transaction
import Cardano.CLI.Shelley.Run.Read

import qualified Hedgehog as H
import qualified Hedgehog.Extras.Test.Process as H
Expand Down

0 comments on commit 44bee30

Please sign in to comment.