Skip to content

Commit 59b57bd

Browse files
Merge #4468
4468: Separate validation and creation of transaction bodies r=Jimbo4350 a=Jimbo4350 Implement `createTransactionBody` and `createAndValidateTransactionBody`. We want to separate `TxBody` construction and validation to allow the creation of invalid transaction bodies. Closes #3563 Co-authored-by: Jordan Millar <[email protected]>
2 parents 23b855d + c7dd93a commit 59b57bd

File tree

10 files changed

+629
-361
lines changed

10 files changed

+629
-361
lines changed

bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/Genesis.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mkGenesisTransaction :: forall era .
8585
-> [TxOut CtxTx era]
8686
-> Tx era
8787
mkGenesisTransaction key ttl fee txins txouts
88-
= case makeTransactionBody txBodyContent of
88+
= case createAndValidateTransactionBody txBodyContent of
8989
Right b -> signShelleyTransaction b [WitnessGenesisUTxOKey key]
9090
Left err -> error $ show err
9191
where

bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/SizedMetadata.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ metadataSize :: forall era . IsShelleyBasedEra era => AsType era -> Maybe TxMeta
101101
metadataSize p m = dummyTxSize p m - dummyTxSize p Nothing
102102

103103
dummyTxSizeInEra :: forall era . IsShelleyBasedEra era => TxMetadataInEra era -> Int
104-
dummyTxSizeInEra metadata = case makeTransactionBody dummyTx of
104+
dummyTxSizeInEra metadata = case createAndValidateTransactionBody dummyTx of
105105
Right b -> BS.length $ serialiseToCBOR b
106106
Left err -> error $ "metaDataSize " ++ show err
107107
where

bench/tx-generator/src/Cardano/TxGenerator/Tx.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ genTx :: forall era. IsShelleyBasedEra era =>
7575
-> TxMetadataInEra era
7676
-> TxGenerator era
7777
genTx protocolParameters (collateral, collFunds) fee metadata inFunds outputs
78-
= case makeTransactionBody txBodyContent of
78+
= case createAndValidateTransactionBody txBodyContent of
7979
Left err -> Left $ show err
8080
Right b -> Right ( signShelleyTransaction b $ map WitnessPaymentKey allKeys
8181
, getTxId b

cardano-api/gen/Gen/Cardano/Api/Typed.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ genTxFee era =
609609

610610
genTxBody :: IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
611611
genTxBody era = do
612-
res <- makeTransactionBody <$> genTxBodyContent era
612+
res <- Api.createAndValidateTransactionBody <$> genTxBodyContent era
613613
case res of
614614
Left err -> fail (displayError err)
615615
Right txBody -> pure txBody

cardano-api/src/Cardano/Api.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ module Cardano.Api (
155155

156156
-- ** Transaction bodies
157157
TxBody(TxBody),
158-
makeTransactionBody,
158+
createAndValidateTransactionBody,
159+
makeTransactionBody, -- TODO: Remove
159160
TxBodyContent(..),
160161
TxBodyError(..),
161162
TxBodyScriptData(..),

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
934934
-- 3. update tx with fees
935935
-- 4. balance the transaction and update tx change output
936936
txbody0 <-
937-
first TxBodyError $ makeTransactionBody txbodycontent
937+
first TxBodyError $ createAndValidateTransactionBody txbodycontent
938938
{ txOuts =
939939
TxOut changeaddr (lovelaceToTxOutValue 0) TxOutDatumNone ReferenceScriptNone
940940
: txOuts txbodycontent
@@ -974,7 +974,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
974974

975975
let (dummyCollRet, dummyTotColl) = maybeDummyTotalCollAndCollReturnOutput txbodycontent changeaddr
976976
txbody1 <- first TxBodyError $ -- TODO: impossible to fail now
977-
makeTransactionBody txbodycontent1 {
977+
createAndValidateTransactionBody txbodycontent1 {
978978
txFee = TxFeeExplicit explicitTxFees $ Lovelace (2^(32 :: Integer) - 1),
979979
txOuts = TxOut changeaddr
980980
(lovelaceToTxOutValue $ Lovelace (2^(64 :: Integer)) - 1)
@@ -998,7 +998,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
998998
-- Here we do not want to start with any change output, since that's what
999999
-- we need to calculate.
10001000
txbody2 <- first TxBodyError $ -- TODO: impossible to fail now
1001-
makeTransactionBody txbodycontent1 {
1001+
createAndValidateTransactionBody txbodycontent1 {
10021002
txFee = TxFeeExplicit explicitTxFees fee,
10031003
txReturnCollateral = retColl,
10041004
txTotalCollateral = reqCol
@@ -1027,7 +1027,7 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
10271027
-- would fit within 2^16-1. That's a possible optimisation.
10281028
txbody3 <-
10291029
first TxBodyError $ -- TODO: impossible to fail now
1030-
makeTransactionBody txbodycontent1 {
1030+
createAndValidateTransactionBody txbodycontent1 {
10311031
txFee = TxFeeExplicit explicitTxFees fee,
10321032
txOuts = accountForNoChange
10331033
(TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone)

0 commit comments

Comments
 (0)