Skip to content

Commit

Permalink
Implement pTransactionBuildCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Apr 25, 2024
1 parent 282803a commit c049849
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ data TransactionBuildEstimateCmdArgs era = TransactionBuildEstimateCmdArgs
-- ^ Mark script as expected to pass or fail validation
, shelleyWitnesses :: !Int
-- ^ Number of shelley witnesses to be added
, mByronWitnesses :: !(Maybe Int)
, mByronWitnesses :: !(Maybe Int)
, protocolParamsFile :: !ProtocolParamsFile
, totalUTxOValue :: !Value
, txins :: ![(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
Expand Down
22 changes: 22 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,28 @@ pWitnessOverride = Opt.option Opt.auto $ mconcat
, Opt.help "Specify and override the number of witnesses the transaction requires."
]

pNumberOfShelleyKeyWitnesses :: Parser Int
pNumberOfShelleyKeyWitnesses = Opt.option Opt.auto $ mconcat
[ Opt.long "shelley-key-witnesses"
, Opt.metavar "INT"
, Opt.help "Specify the number of Shelley key witnesses the transaction requires."
]

pNumberOfByronKeyWitnesses :: Parser Int
pNumberOfByronKeyWitnesses = Opt.option Opt.auto $ mconcat
[ Opt.long "byron-key-witnesses"
, Opt.metavar "Int"
, Opt.help "Specify the number of Byron key witnesses the transaction requires."
]

pTotalUTxOValue :: Parser Value
pTotalUTxOValue =
Opt.option (readerFromParsecParser parseValue) $ mconcat
[ Opt.long "total-utxo-value"
, Opt.metavar "VALUE"
, Opt.help "The total value of the UTxO that exists at the tx inputs being spent."
]


pTxOut :: Parser TxOutAnyEra
pTxOut =
Expand Down
60 changes: 60 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pTransactionCmds era envCli =
]
]
, pTransactionBuildCmd era envCli
, pTransactionBuildEstimateCmd era envCli
, Just
$ subParser "sign"
$ Opt.info (pTransactionSign envCli)
Expand Down Expand Up @@ -184,6 +185,65 @@ pTransactionBuildCmd era envCli = do
<*> pProposalFiles sbe AutoBalance
<*> (OutputTxBodyOnly <$> pTxBodyFileOut <|> pCalculatePlutusScriptCost)

-- | Estimate the transaction fees without access to a live node.
pTransactionBuildEstimateCmd :: ShelleyBasedEra era -> EnvCli -> Maybe (Parser (TransactionCmds era))
pTransactionBuildEstimateCmd era _envCli = do
pure
$ subParser "build-estimate"
$ Opt.info (pCmd era)
$ Opt.progDescDoc
$ Just $ mconcat
[ pretty @String "Build a balanced transaction without access to a live node (automatically calculates fees)"
, line
, line
, H.yellow $ mconcat
[ "Please note "
, H.underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
where
pCmd :: ShelleyBasedEra era -> Parser (TransactionCmds era)
pCmd sbe =
fmap TransactionBuildEstimateCmd $
TransactionBuildEstimateCmdArgs sbe
<$> optional pScriptValidity
<*> pNumberOfShelleyKeyWitnesses
<*> optional pNumberOfByronKeyWitnesses
<*> pProtocolParamsFile
<*> pTotalUTxOValue
<*> some (pTxIn AutoBalance)
<*> many pReadOnlyReferenceTxIn
<*> many pRequiredSigner
<*> many pTxInCollateral
<*> optional pReturnCollateral
<*> pTotalCollateral
<*> many pTxOut
<*> pChangeAddress
<*> optional (pMintMultiAsset AutoBalance)
<*> optional pInvalidBefore
<*> pInvalidHereafter sbe
<*> many (pCertificateFile AutoBalance)
<*> many (pWithdrawal AutoBalance)
<*> pure mempty -- TODO: Dreps to deregister
<*> pure mempty -- TODO: Stake credentials to deregister
<*> pure mempty -- TOOD: Plutus execution units (Map ScriptWitnessIndex ExecutionUnits)
<*> pure Nothing -- TODO: Total ref scripts size
--- dreps to register TODO:LEft off here
<*> pTxMetadataJsonSchema
<*> many (pScriptFor
"auxiliary-script-file"
Nothing
"Filepath of auxiliary script(s)")
<*> many pMetadataFile
<*> pFeatured (shelleyBasedToCardanoEra sbe) (optional pUpdateProposalFile)
<*> pVoteFiles sbe AutoBalance
<*> pProposalFiles sbe AutoBalance
<*> pure mempty -- TODO: Pools to deregister
<*> pTxBodyFileOut


pChangeAddress :: Parser TxOutChangeAddress
pChangeAddress =
fmap TxOutChangeAddress $ Opt.option (readerFromParsecParser parseAddressAny) $ mconcat
Expand Down

0 comments on commit c049849

Please sign in to comment.