Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Feb 15, 2022
1 parent 3b86bbd commit 11138da
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 37 deletions.
9 changes: 1 addition & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -33,7 +33,6 @@ module Cardano.CLI.Shelley.Commands
, ProtocolParamsFile (..)
, ProtocolParamsSourceSpec (..)
, WitnessFile (..)
, TxBodyFile (..)
, TxFile (..)
, InputTxFile (..)
, VerificationKeyBase64 (..)
Expand Down Expand Up @@ -224,8 +223,7 @@ data TransactionCmd
(Maybe ProtocolParamsSourceSpec)
(Maybe UpdateProposalFile)
OutputSerialisation
TxBodyFile
RenderScriptCost
TxBuildOutputOptions
| TxSign TxBodyFile [WitnessSigningData] (Maybe NetworkId) TxFile
| TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile
| TxAssembleTxBodyWitness TxBodyFile [WitnessFile] OutputFile
Expand Down Expand Up @@ -537,11 +535,6 @@ newtype PrivKeyFile
newtype WitnessFile
= WitnessFile FilePath
deriving Show

newtype TxBodyFile
= TxBodyFile FilePath
deriving Show

newtype TxFile
= TxFile FilePath
deriving Show
Expand Down
1 change: 0 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Output.hs
Expand Up @@ -187,7 +187,6 @@ instance Error PlutusScriptCostError where

renderScriptCosts
:: ExecutionUnitPrices
-- ^ Protocol parameters cost model(s)
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-- ^ Initial mapping of script witness index to actual script.
-- We need this in order to know which script corresponds to the
Expand Down
9 changes: 4 additions & 5 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -687,8 +687,7 @@ pTransaction =
<*> optional pProtocolParamsSourceSpec
<*> optional pUpdateProposalFile
<*> pOutputSerialisation
<*> pTxBodyFile Output
<*> pCalculatePlutusScriptCost
<*> (OutputTxBodyOnly <$> pTxBodyFile Output <|> pCalculatePlutusScriptCost)

pChangeAddress :: Parser TxOutChangeAddress
pChangeAddress =
Expand Down Expand Up @@ -1320,14 +1319,14 @@ pProtocolParamsFile =
<> Opt.completer (Opt.bashCompleter "file")
)

pCalculatePlutusScriptCost :: Parser RenderScriptCost
pCalculatePlutusScriptCost :: Parser TxBuildOutputOptions
pCalculatePlutusScriptCost =
RenderScriptCostOnly <$> Opt.strOption
OutputScriptCostOnly <$> Opt.strOption
( Opt.long "calculate-plutus-script-cost" <>
Opt.metavar "FILE" <>
Opt.help "Output filepath of the script cost information." <>
Opt.completer (Opt.bashCompleter "file")
) <|> pure DoNotRenderScriptCost
)

pCertificateFile
:: BalanceTxExecUnits
Expand Down
35 changes: 16 additions & 19 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Expand Up @@ -106,7 +106,7 @@ data ShelleyTxCmdError
| ShelleyTxCmdUnsupportedMode !AnyConsensusMode
| ShelleyTxCmdByronEra
| ShelleyTxCmdEraConsensusModeMismatchTxBalance
!TxBodyFile
!TxBuildOutputOptions
!AnyConsensusMode
!AnyCardanoEra
| ShelleyTxCmdBalanceTxBody !TxBodyErrorAutoBalance
Expand All @@ -122,6 +122,7 @@ data ShelleyTxCmdError
!(FileError TextEnvelopeCddlError)
| ShelleyTxCmdTxExecUnitsErr !TransactionValidityError
| ShelleyTxCmdPlutusScriptCostErr !PlutusScriptCostError
| ShelleyTxCmdPParamExecutionUnitsNotAvailable

renderShelleyTxCmdError :: ShelleyTxCmdError -> Text
renderShelleyTxCmdError err =
Expand Down Expand Up @@ -260,6 +261,9 @@ renderShelleyTxCmdError err =
"TextEnvelopeCddl error: " <> Text.pack (displayError cddlErr)
ShelleyTxCmdTxExecUnitsErr err' -> Text.pack $ displayError err'
ShelleyTxCmdPlutusScriptCostErr err'-> Text.pack $ displayError err'
ShelleyTxCmdPParamExecutionUnitsNotAvailable ->
"Execution units not available in the protocol parameters. This is \
\likely due to not being in the Alonzo era"

renderEra :: AnyCardanoEra -> Text
renderEra (AnyCardanoEra ByronEra) = "Byron"
Expand Down Expand Up @@ -294,12 +298,10 @@ runTransactionCmd cmd =
case cmd of
TxBuild era consensusModeParams nid mScriptValidity mOverrideWits txins reqSigners
txinsc txouts changeAddr mValue mLowBound mUpperBound certs wdrls metadataSchema
scriptFiles metadataFiles mpparams mUpProp outputFormat txBodyOut
renderScriptCost ->
scriptFiles metadataFiles mpparams mUpProp outputFormat ouput ->
runTxBuild era consensusModeParams nid mScriptValidity txins txinsc txouts changeAddr mValue mLowBound
mUpperBound certs wdrls reqSigners metadataSchema scriptFiles
metadataFiles mpparams mUpProp outputFormat txBodyOut mOverrideWits
renderScriptCost
metadataFiles mpparams mUpProp outputFormat mOverrideWits ouput
TxBuildRaw era mScriptValidity txins txinsc reqSigners txouts mValue mLowBound mUpperBound
fee certs wdrls metadataSchema scriptFiles
metadataFiles mpparams mUpProp outputFormat out ->
Expand Down Expand Up @@ -430,14 +432,13 @@ runTxBuild
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> OutputSerialisation
-> TxBodyFile
-> Maybe Word
-> RenderScriptCost
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO ()
runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mScriptValidity
txins txinsc txouts (TxOutChangeAddress changeAddr) mValue mLowerBound mUpperBound
certFiles withdrawals reqSigners metadataSchema scriptFiles metadataFiles mpparams
mUpdatePropFile outputFormat outBody@(TxBodyFile fpath) mOverrideWits rndrScriptCost = do
mUpdatePropFile outputFormat mOverrideWits outputOptions = do
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError readEnvSocketPath
let localNodeConnInfo = LocalNodeConnectInfo cModeParams networkId sockPath
consensusMode = consensusModeOnly cModeParams
Expand Down Expand Up @@ -467,7 +468,7 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
eInMode <- case toEraInMode era CardanoMode of
Just result -> return result
Nothing ->
left (ShelleyTxCmdEraConsensusModeMismatchTxBalance outBody
left (ShelleyTxCmdEraConsensusModeMismatchTxBalance outputOptions
(AnyConsensusMode CardanoMode) (AnyCardanoEra era))

(utxo, pparams, eraHistory, systemStart, stakePools) <-
Expand Down Expand Up @@ -511,27 +512,23 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
cAddr mOverrideWits

putStrLn $ "Estimated transaction fee: " <> (show fee :: String)
case rndrScriptCost of
RenderScriptCostOnly fp -> do
case outputOptions of
OutputScriptCostOnly fp -> do
case protocolParamPrices pparams of
Just executionUnitPrices -> do
scriptExecUnitsMap <- firstExceptT ShelleyTxCmdTxExecUnitsErr $ hoistEither
$ evaluateTransactionExecutionUnits
eInMode
systemStart
eraHistory
pparams
utxo
balancedTxBody
eInMode systemStart eraHistory
pparams utxo balancedTxBody
scriptCostOutput <- firstExceptT ShelleyTxCmdPlutusScriptCostErr $ hoistEither
$ renderScriptCosts
executionUnitPrices
(collectTxBodyScriptWitnesses txBodyContent)
scriptExecUnitsMap
liftIO $ LBS.writeFile fp $ Aeson.encode scriptCostOutput

Nothing -> panic "Wrong era"
DoNotRenderScriptCost ->
Nothing -> left ShelleyTxCmdPParamExecutionUnitsNotAvailable
OutputTxBodyOnly (TxBodyFile fpath) ->
case outputFormat of
OutputCliSerialisation ->
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
Expand Down
14 changes: 10 additions & 4 deletions cardano-cli/src/Cardano/CLI/Types.hs
Expand Up @@ -12,7 +12,7 @@ module Cardano.CLI.Types
, GenesisFile (..)
, OutputFormat (..)
, OutputSerialisation (..)
, RenderScriptCost(..)
, TxBuildOutputOptions(..)
, SigningKeyFile (..)
, SocketPath (..)
, ScriptFile (..)
Expand All @@ -21,6 +21,7 @@ module Cardano.CLI.Types
, ScriptWitnessFiles (..)
, ScriptDatumOrFile (..)
, TransferDirection(..)
, TxBodyFile (..)
, TxOutAnyEra (..)
, TxOutChangeAddress (..)
, TxOutDatumAnyEra (..)
Expand All @@ -47,9 +48,14 @@ import Cardano.Ledger.Shelley.TxBody (PoolParams (..))

-- | Specify whether to render the script cost as JSON
-- in the cli's build command.
data RenderScriptCost = RenderScriptCostOnly FilePath
| DoNotRenderScriptCost
deriving Show
data TxBuildOutputOptions = OutputScriptCostOnly FilePath
| OutputTxBodyOnly TxBodyFile
deriving Show

newtype TxBodyFile
= TxBodyFile FilePath
deriving Show

-- | Specify what the CBOR file is
-- i.e a block, a tx, etc
data CBORObject = CBORBlockByron Byron.EpochSlots
Expand Down
1 change: 1 addition & 0 deletions scripts/plutus/example-txin-locking-plutus-script.sh
Expand Up @@ -118,6 +118,7 @@ $CARDANO_CLI transaction build \
--tx-in-datum-file "$datumfilepath" \
--protocol-params-file "$WORK/pparams.json" \
--tx-in-redeemer-file "$redeemerfilepath" \
# TODO: Left off here. Need to make --calculate-plutus-script-cost and --outfile alternatives
--out-file $WORK/test-alonzo.body

$CARDANO_CLI transaction sign \
Expand Down

0 comments on commit 11138da

Please sign in to comment.