Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate validation and creation of transaction bodies #4468

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mkGenesisTransaction :: forall era .
-> [TxOut CtxTx era]
-> Tx era
mkGenesisTransaction key ttl fee txins txouts
= case makeTransactionBody txBodyContent of
= case createAndValidateTransactionBody txBodyContent of
Right b -> signShelleyTransaction b [WitnessGenesisUTxOKey key]
Left err -> error $ show err
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ metadataSize :: forall era . IsShelleyBasedEra era => AsType era -> Maybe TxMeta
metadataSize p m = dummyTxSize p m - dummyTxSize p Nothing

dummyTxSizeInEra :: forall era . IsShelleyBasedEra era => TxMetadataInEra era -> Int
dummyTxSizeInEra metadata = case makeTransactionBody dummyTx of
dummyTxSizeInEra metadata = case createAndValidateTransactionBody dummyTx of
Right b -> BS.length $ serialiseToCBOR b
Left err -> error $ "metaDataSize " ++ show err
where
Expand Down
2 changes: 1 addition & 1 deletion bench/tx-generator/src/Cardano/TxGenerator/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ genTx :: forall era. IsShelleyBasedEra era =>
-> TxMetadataInEra era
-> TxGenerator era
genTx protocolParameters (collateral, collFunds) fee metadata inFunds outputs
= case makeTransactionBody txBodyContent of
= case createAndValidateTransactionBody txBodyContent of
Left err -> Left $ show err
Right b -> Right ( signShelleyTransaction b $ map WitnessPaymentKey allKeys
, getTxId b
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/gen/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ genTxFee era =

genTxBody :: IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBody era = do
res <- makeTransactionBody <$> genTxBodyContent era
res <- Api.createAndValidateTransactionBody <$> genTxBodyContent era
case res of
Left err -> fail (displayError err)
Right txBody -> pure txBody
Expand Down
3 changes: 2 additions & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ module Cardano.Api (

-- ** Transaction bodies
TxBody(TxBody),
makeTransactionBody,
createAndValidateTransactionBody,
makeTransactionBody, -- TODO: Remove
TxBodyContent(..),
TxBodyError(..),
TxBodyScriptData(..),
Expand Down
8 changes: 4 additions & 4 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
-- 3. update tx with fees
-- 4. balance the transaction and update tx change output
txbody0 <-
first TxBodyError $ makeTransactionBody txbodycontent
first TxBodyError $ createAndValidateTransactionBody txbodycontent
{ txOuts =
TxOut changeaddr (lovelaceToTxOutValue 0) TxOutDatumNone ReferenceScriptNone
: txOuts txbodycontent
Expand Down Expand Up @@ -974,7 +974,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams

let (dummyCollRet, dummyTotColl) = maybeDummyTotalCollAndCollReturnOutput txbodycontent changeaddr
txbody1 <- first TxBodyError $ -- TODO: impossible to fail now
makeTransactionBody txbodycontent1 {
createAndValidateTransactionBody txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees $ Lovelace (2^(32 :: Integer) - 1),
txOuts = TxOut changeaddr
(lovelaceToTxOutValue $ Lovelace (2^(64 :: Integer)) - 1)
Expand All @@ -998,7 +998,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
-- Here we do not want to start with any change output, since that's what
-- we need to calculate.
txbody2 <- first TxBodyError $ -- TODO: impossible to fail now
makeTransactionBody txbodycontent1 {
createAndValidateTransactionBody txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees fee,
txReturnCollateral = retColl,
txTotalCollateral = reqCol
Expand Down Expand Up @@ -1027,7 +1027,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
-- would fit within 2^16-1. That's a possible optimisation.
txbody3 <-
first TxBodyError $ -- TODO: impossible to fail now
makeTransactionBody txbodycontent1 {
createAndValidateTransactionBody txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees fee,
txOuts = accountForNoChange
(TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone)
Expand Down
Loading