Skip to content

Commit b77d23c

Browse files
committed
WIP
1 parent 87cce2e commit b77d23c

File tree

14 files changed

+1351
-950
lines changed

14 files changed

+1351
-950
lines changed

bench/tx-generator/src/Cardano/Benchmarking/PlutusExample.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
{-# LANGUAGE ScopedTypeVariables #-}
44
module Cardano.Benchmarking.PlutusExample
55
where
6-
import Prelude
76
import qualified Data.Map as Map
7+
import Prelude
88

99
import Control.Monad.Trans.Except
1010
import qualified Data.ByteString.Char8 as BSC
1111

12-
import Cardano.CLI.Shelley.Script (readFileScriptInAnyLang)
1312

1413
import Cardano.Api
15-
import Cardano.Api.Shelley ( ProtocolParameters(..), PlutusScript(..)
16-
, fromAlonzoExUnits, protocolParamCostModels, toPlutusData)
14+
import Cardano.Api.Shelley (PlutusScript (..), ProtocolParameters (..), fromAlonzoExUnits,
15+
protocolParamCostModels, toPlutusData)
1716
import Cardano.Ledger.Alonzo.TxInfo (exBudgetToExUnits)
1817

1918
import qualified Plutus.V1.Ledger.Api as Plutus
20-
import Plutus.V1.Ledger.Contexts (ScriptContext(..), ScriptPurpose(..), TxInfo(..), TxOutRef(..))
19+
import Plutus.V1.Ledger.Contexts (ScriptContext (..), ScriptPurpose (..), TxInfo (..),
20+
TxOutRef (..))
2121

2222
readScript :: FilePath -> IO (Script PlutusScriptV1)
2323
readScript fp = do

cardano-api/src/Cardano/Api.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ module Cardano.Api (
697697
-- ** Misc
698698
ScriptLockedTxInsError(..),
699699
TxInsExistError(..),
700+
renderEra,
700701
renderNotScriptLockedTxInsError,
701702
renderTxInsExistError,
702703
txInsExistInUTxO,

cardano-api/src/Cardano/Api/Fees.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
10361036
}
10371037
txbody3 <-
10381038
first TxBodyError $ -- TODO: impossible to fail now
1039-
makeTransactionBody finalTxBodyContent
1039+
createAndValidateTransactionBody finalTxBodyContent
10401040
return (BalancedTxBody finalTxBodyContent txbody3 (TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone) fee)
10411041
where
10421042
-- Essentially we check for the existence of collateral inputs. If they exist we

cardano-api/src/Cardano/Api/Utils.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE LambdaCase #-}
34

45
#if !defined(mingw32_HOST_OS)
@@ -17,6 +18,7 @@ module Cardano.Api.Utils
1718
, note
1819
, parseFilePath
1920
, readFileBlocking
21+
, renderEra
2022
, runParsecParser
2123
, textShow
2224
, writeSecrets
@@ -47,6 +49,8 @@ import System.Posix.Files (ownerReadMode, setFileMode)
4749
import System.Directory (emptyPermissions, readable, setPermissions)
4850
#endif
4951

52+
import Cardano.Api.Eras
53+
5054
(?!) :: Maybe a -> e -> Either e a
5155
Nothing ?! e = Left e
5256
Just x ?! _ = Right x
@@ -121,3 +125,14 @@ readFileBlocking path = bracket
121125

122126
textShow :: Show a => a -> Text
123127
textShow = Text.pack . show
128+
129+
-- TODO: Move me
130+
131+
renderEra :: AnyCardanoEra -> Text
132+
renderEra (AnyCardanoEra ByronEra) = "Byron"
133+
renderEra (AnyCardanoEra ShelleyEra) = "Shelley"
134+
renderEra (AnyCardanoEra AllegraEra) = "Allegra"
135+
renderEra (AnyCardanoEra MaryEra) = "Mary"
136+
renderEra (AnyCardanoEra AlonzoEra) = "Alonzo"
137+
renderEra (AnyCardanoEra BabbageEra) = "Babbage"
138+

cardano-cli/cardano-cli.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ library
8787
Cardano.CLI.Shelley.Run.StakeAddress
8888
Cardano.CLI.Shelley.Run.TextView
8989
Cardano.CLI.Shelley.Run.Transaction
90-
Cardano.CLI.Shelley.Script
90+
Cardano.CLI.Shelley.Run.Read
91+
Cardano.CLI.Shelley.Run.Validate
9192

9293
Cardano.CLI.TopHandler
9394

cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Cardano.CLI.Shelley.Key (InputDecodeError, PaymentVerifier (..)
3131
readVerificationKeyTextOrFileAnyOf, renderVerificationKeyTextOrFileError)
3232
import Cardano.CLI.Shelley.Parsers (AddressCmd (..), AddressKeyType (..), OutputFile (..))
3333
import Cardano.CLI.Shelley.Run.Address.Info (ShelleyAddressInfoError, runAddressInfo)
34-
import Cardano.CLI.Shelley.Script
34+
import Cardano.CLI.Shelley.Run.Read
3535
import Cardano.CLI.Types
3636

3737
data ShelleyAddressCmdError

cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ module Cardano.CLI.Shelley.Run.Genesis
2020
, readAndDecodeShelleyGenesis
2121
, readAlonzoGenesis
2222
, runGenesisCmd
23+
24+
-- * Protocol Parameters
25+
, ProtocolParamsError(..)
26+
, renderProtocolParamsError
27+
, readProtocolParameters
28+
, readProtocolParametersSourceSpec
2329
) where
2430

2531
import Cardano.Prelude hiding (unlines)
@@ -104,7 +110,7 @@ import Cardano.Chain.Common (BlockCount (unBlockCount))
104110
import Cardano.Chain.Delegation (delegateVK)
105111
import qualified Cardano.Chain.Delegation as Dlg
106112
import qualified Cardano.Chain.Genesis as Genesis
107-
import Cardano.Chain.Update
113+
import Cardano.Chain.Update hiding (ProtocolParameters)
108114
import Cardano.Slotting.Slot (EpochSize (EpochSize))
109115
import Data.Fixed (Fixed (MkFixed))
110116
import qualified Data.Yaml as Yaml
@@ -1314,3 +1320,36 @@ readAlonzoGenesis fpath = do
13141320
lbs <- handleIOExceptT (ShelleyGenesisCmdGenesisFileError . FileIOError fpath) $ LBS.readFile fpath
13151321
firstExceptT (ShelleyGenesisCmdAesonDecodeError fpath . Text.pack)
13161322
. hoistEither $ Aeson.eitherDecode' lbs
1323+
1324+
1325+
-- Protocol Parameters
1326+
1327+
data ProtocolParamsError
1328+
= ProtocolParamsErrorFile (FileError ())
1329+
| ProtocolParamsErrorJSON !FilePath !Text
1330+
| ProtocolParamsErrorGenesis !ShelleyGenesisCmdError
1331+
1332+
renderProtocolParamsError :: ProtocolParamsError -> Text
1333+
renderProtocolParamsError (ProtocolParamsErrorFile fileErr) =
1334+
Text.pack $ displayError fileErr
1335+
renderProtocolParamsError (ProtocolParamsErrorJSON fp jsonErr) =
1336+
"Error while decoding the protocol parameters at: " <> Text.pack fp <> " Error: " <> jsonErr
1337+
renderProtocolParamsError (ProtocolParamsErrorGenesis err) =
1338+
Text.pack $ displayError err
1339+
1340+
readProtocolParametersSourceSpec :: ProtocolParamsSourceSpec
1341+
-> ExceptT ProtocolParamsError IO ProtocolParameters
1342+
readProtocolParametersSourceSpec (ParamsFromGenesis (GenesisFile f)) =
1343+
fromShelleyPParams . sgProtocolParams
1344+
<$> firstExceptT ProtocolParamsErrorGenesis (readShelleyGenesisWithDefault f id)
1345+
readProtocolParametersSourceSpec (ParamsFromFile f) = readProtocolParameters f
1346+
1347+
--TODO: eliminate this and get only the necessary params, and get them in a more
1348+
-- helpful way rather than requiring them as a local file.
1349+
readProtocolParameters :: ProtocolParamsFile
1350+
-> ExceptT ProtocolParamsError IO ProtocolParameters
1351+
readProtocolParameters (ProtocolParamsFile fpath) = do
1352+
pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath
1353+
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
1354+
Aeson.eitherDecode' pparams
1355+

0 commit comments

Comments
 (0)