diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index de3312b4ee8..934073511eb 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -34,6 +34,7 @@ import Hydra.API.HTTPServer ( TransactionSubmitted (..), ) import Hydra.Cardano.Api ( + defaultTxBodyContent, Coin (..), File (File), Key (SigningKey), @@ -71,7 +72,7 @@ import Hydra.Cluster.Fixture (Actor (..), actorName, alice, aliceSk, aliceVk, bo import Hydra.Cluster.Mithril (MithrilLog) import Hydra.Cluster.Options (Options) import Hydra.Cluster.Util (chainConfigFor, keysFor, modifyConfig, setNetworkId) -import Hydra.Ledger.Cardano (addInputs, emptyTxBody, mkSimpleTx, mkTransferTx, unsafeBuildTransaction) +import Hydra.Ledger.Cardano (addInputs, mkSimpleTx, mkTransferTx, unsafeBuildTransaction) import Hydra.Logging (Tracer, traceWith) import Hydra.Options (DirectChainConfig (..), networkId, startChainFrom) import Hydra.Tx (HeadId, IsTx (balance), Party, txId) @@ -457,7 +458,7 @@ singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId = mkScriptWitness serializedScript (mkScriptDatum ()) (toScriptData ()) let spendingTx = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(scriptIn, scriptWitness)] pure ( Aeson.object diff --git a/hydra-node/src/Hydra/Ledger/Cardano.hs b/hydra-node/src/Hydra/Ledger/Cardano.hs index 6e3b13bcb07..cb524a303c6 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano.hs @@ -137,7 +137,7 @@ mkSimpleTx (txin, TxOut owner valueIn datum refScript) (recipient, valueOut) sk pure $ makeSignedTransaction witnesses body where bodyContent = - emptyTxBody + defaultTxBodyContent { txIns = [(txin, BuildTxWith $ KeyWitness KeyWitnessForSpending)] , txOuts = outs , txFee = TxFeeExplicit fee @@ -170,7 +170,7 @@ mkRangedTx (txin, TxOut owner valueIn datum refScript) (recipient, valueOut) sk pure $ makeSignedTransaction witnesses body where bodyContent = - emptyTxBody + defaultTxBodyContent { txIns = [(txin, BuildTxWith $ KeyWitness KeyWitnessForSpending)] , txOuts = TxOut @CtxTx recipient valueOut TxOutDatumNone ReferenceScriptNone diff --git a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs index f08d9d55c5f..d4b603484b7 100644 --- a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs @@ -44,7 +44,7 @@ import Hydra.Chain.Direct.Tx ( ) import Hydra.Contract.Dummy (dummyValidatorScript) import Hydra.Contract.HeadTokens (headPolicyId) -import Hydra.Ledger.Cardano.Builder (addInputs, addReferenceInputs, addVkInputs, emptyTxBody, unsafeBuildTransaction) +import Hydra.Ledger.Cardano.Builder (addInputs, addReferenceInputs, addVkInputs, unsafeBuildTransaction) import Hydra.Ledger.Cardano.Evaluate (propTransactionEvaluates) import Hydra.Tx.BlueprintTx (CommitBlueprintTx (..)) import Hydra.Tx.Commit (commitTx) @@ -222,7 +222,7 @@ propIsSubmapOf as bs = genBlueprintTxWithUTxO :: Gen (UTxO, Tx) genBlueprintTxWithUTxO = fmap (second unsafeBuildTransaction) $ - spendingPubKeyOutput (mempty, emptyTxBody) + spendingPubKeyOutput (mempty, defaultTxBodyContent) >>= spendSomeScriptInputs >>= addSomeReferenceInputs >>= addValidityRange diff --git a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs index bd996c69643..256c06f79a4 100644 --- a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs +++ b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs @@ -34,50 +34,6 @@ data InvalidTransactionException = InvalidTransactionException instance Exception InvalidTransactionException --- * Constructing - --- | An empty 'TxBodyContent' with all empty/zero values to be extended using --- record updates. --- --- NOTE: 'makeTransactionBody' throws when one tries to build a transaction --- with scripts but no collaterals. This is unfortunate because collaterals are --- currently added after by our integrated wallet. --- --- Similarly, 'makeTransactionBody' throws when building a transaction with --- scripts and no protocol parameters (needed to compute the script integrity --- hash). This is also added by our wallet at the moment and this ugly --- work-around will be removed eventually (related item --- [215](https://github.com/cardano-scaling/hydra/issues/215). --- --- So we currently bypass this by having default but seemingly innofensive --- values for collaterals and protocol params in the 'empty' value -emptyTxBody :: TxBodyContent BuildTx -emptyTxBody = - TxBodyContent - mempty -- inputs - (TxInsCollateral mempty) - TxInsReferenceNone - mempty -- outputs - TxTotalCollateralNone - TxReturnCollateralNone - (TxFeeExplicit 0) - TxValidityNoLowerBound - TxValidityNoUpperBound - TxMetadataNone - TxAuxScriptsNone - (BuildTxWith TxSupplementalDataNone) - TxExtraKeyWitnessesNone - (BuildTxWith $ Just $ LedgerProtocolParameters def) - TxWithdrawalsNone - TxCertificatesNone - TxUpdateProposalNone - TxMintValueNone - TxScriptValidityNone - Nothing - Nothing - Nothing - Nothing - -- | Add new inputs to an ongoing builder. addInputs :: TxIns BuildTx -> TxBodyContent BuildTx -> TxBodyContent BuildTx addInputs ins tx = diff --git a/hydra-tx/src/Hydra/Tx/Abort.hs b/hydra-tx/src/Hydra/Tx/Abort.hs index f6817c27368..64034792d3c 100644 --- a/hydra-tx/src/Hydra/Tx/Abort.hs +++ b/hydra-tx/src/Hydra/Tx/Abort.hs @@ -16,7 +16,6 @@ import Hydra.Ledger.Cardano.Builder ( addOutputs, addReferenceInputs, burnTokens, - emptyTxBody, unsafeBuildTransaction, ) import Hydra.Plutus (commitValidatorScript, initialValidatorScript) @@ -54,7 +53,7 @@ abortTx committedUTxO scriptRegistry vk (headInput, initialHeadOutput) headToken | otherwise = Right $ unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs ((headInput, headWitness) : initialInputs <> commitInputs) & addReferenceInputs ([headScriptRef, initialScriptRef] <> [commitScriptRef | not $ null commitInputs]) & addOutputs reimbursedOutputs diff --git a/hydra-tx/src/Hydra/Tx/Close.hs b/hydra-tx/src/Hydra/Tx/Close.hs index bd0c4808bab..d183f34b145 100644 --- a/hydra-tx/src/Hydra/Tx/Close.hs +++ b/hydra-tx/src/Hydra/Tx/Close.hs @@ -16,7 +16,6 @@ import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, addReferenceInputs, - emptyTxBody, setValidityLowerBound, setValidityUpperBound, unsafeBuildTransaction, @@ -69,7 +68,7 @@ closeTx :: Tx closeTx scriptRegistry vk headId openVersion confirmedSnapshot startSlotNo (endSlotNo, utcTime) openThreadOutput = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(headInput, headWitness)] & addReferenceInputs [headScriptRef] & addOutputs [headOutputAfter] diff --git a/hydra-tx/src/Hydra/Tx/CollectCom.hs b/hydra-tx/src/Hydra/Tx/CollectCom.hs index ad3848f5ab6..0becda0a34a 100644 --- a/hydra-tx/src/Hydra/Tx/CollectCom.hs +++ b/hydra-tx/src/Hydra/Tx/CollectCom.hs @@ -15,7 +15,6 @@ import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, addReferenceInputs, - emptyTxBody, unsafeBuildTransaction, ) import Hydra.Plutus (commitValidatorScript) @@ -51,7 +50,7 @@ collectComTx :: Tx collectComTx networkId scriptRegistry vk headId headParameters (headInput, initialHeadOutput) commits utxoToCollect = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs ((headInput, headWitness) : (mkCommit <$> Map.keys commits)) & addReferenceInputs [commitScriptRef, headScriptRef] & addOutputs [headOutput] diff --git a/hydra-tx/src/Hydra/Tx/Contest.hs b/hydra-tx/src/Hydra/Tx/Contest.hs index 519dbf809e9..7156b18564d 100644 --- a/hydra-tx/src/Hydra/Tx/Contest.hs +++ b/hydra-tx/src/Hydra/Tx/Contest.hs @@ -12,7 +12,6 @@ import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, addReferenceInputs, - emptyTxBody, setValidityUpperBound, unsafeBuildTransaction, ) @@ -62,7 +61,7 @@ contestTx :: Tx contestTx scriptRegistry vk headId contestationPeriod openVersion Snapshot{number, utxo, utxoToDecommit, version} sig (slotNo, _) closedThreadOutput = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(headInput, headWitness)] & addReferenceInputs [headScriptRef] & addOutputs [headOutputAfter] diff --git a/hydra-tx/src/Hydra/Tx/Decrement.hs b/hydra-tx/src/Hydra/Tx/Decrement.hs index f1ea3b1793e..6c130faf07d 100644 --- a/hydra-tx/src/Hydra/Tx/Decrement.hs +++ b/hydra-tx/src/Hydra/Tx/Decrement.hs @@ -10,7 +10,6 @@ import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, addReferenceInputs, - emptyTxBody, unsafeBuildTransaction, ) import Hydra.Tx.ContestationPeriod (toChain) @@ -43,7 +42,7 @@ decrementTx :: Tx decrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot signatures = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(headInput, headWitness)] & addReferenceInputs [headScriptRef] & addOutputs (headOutput' : map toTxContext decommitOutputs) diff --git a/hydra-tx/src/Hydra/Tx/Fanout.hs b/hydra-tx/src/Hydra/Tx/Fanout.hs index 4a5776f2db2..f60e37a9b1a 100644 --- a/hydra-tx/src/Hydra/Tx/Fanout.hs +++ b/hydra-tx/src/Hydra/Tx/Fanout.hs @@ -11,7 +11,6 @@ import Hydra.Ledger.Cardano.Builder ( addOutputs, addReferenceInputs, burnTokens, - emptyTxBody, setValidityLowerBound, unsafeBuildTransaction, ) @@ -37,7 +36,7 @@ fanoutTx :: Tx fanoutTx scriptRegistry utxo utxoToDecommit (headInput, headOutput) deadlineSlotNo headTokenScript = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(headInput, headWitness)] & addReferenceInputs [headScriptRef] & addOutputs (orderedTxOutsToFanout <> orderedTxOutsToDecommit) diff --git a/hydra-tx/src/Hydra/Tx/Increment.hs b/hydra-tx/src/Hydra/Tx/Increment.hs index 41e0f8ef1f1..c34e4d7441e 100644 --- a/hydra-tx/src/Hydra/Tx/Increment.hs +++ b/hydra-tx/src/Hydra/Tx/Increment.hs @@ -13,7 +13,6 @@ import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, addReferenceInputs, - emptyTxBody, setValidityUpperBound, unsafeBuildTransaction, ) @@ -48,7 +47,7 @@ incrementTx :: Tx incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot depositScriptUTxO upperValiditySlot = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs [(headInput, headWitness), (depositIn, depositWitness)] & addReferenceInputs [headScriptRef] & addOutputs [headOutput'] diff --git a/hydra-tx/src/Hydra/Tx/Init.hs b/hydra-tx/src/Hydra/Tx/Init.hs index 5edd0e859ac..9c5aa03dc4d 100644 --- a/hydra-tx/src/Hydra/Tx/Init.hs +++ b/hydra-tx/src/Hydra/Tx/Init.hs @@ -8,7 +8,7 @@ import Hydra.Contract.HeadState qualified as Head import Hydra.Contract.HeadTokens qualified as HeadTokens import Hydra.Contract.Initial qualified as Initial import Hydra.Contract.MintAction (MintAction (..)) -import Hydra.Ledger.Cardano.Builder (addOutputs, addVkInputs, emptyTxBody, mintTokens, unsafeBuildTransaction) +import Hydra.Ledger.Cardano.Builder (addOutputs, addVkInputs, mintTokens, unsafeBuildTransaction) import Hydra.Plutus (initialValidatorScript) import Hydra.Tx.ContestationPeriod (toChain) import Hydra.Tx.HeadParameters (HeadParameters (..)) @@ -28,7 +28,7 @@ initTx :: Tx initTx networkId seedTxIn participants parameters = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addVkInputs [seedTxIn] & addOutputs ( mkHeadOutputInitial networkId seedTxIn parameters diff --git a/hydra-tx/src/Hydra/Tx/Recover.hs b/hydra-tx/src/Hydra/Tx/Recover.hs index 9505df15eab..10d2146e60b 100644 --- a/hydra-tx/src/Hydra/Tx/Recover.hs +++ b/hydra-tx/src/Hydra/Tx/Recover.hs @@ -9,7 +9,6 @@ import Hydra.Contract.Deposit qualified as Deposit import Hydra.Ledger.Cardano.Builder ( addInputs, addOutputs, - emptyTxBody, setValidityLowerBound, unsafeBuildTransaction, ) @@ -27,7 +26,7 @@ recoverTx :: Tx recoverTx depositTxId deposited lowerBoundSlot = unsafeBuildTransaction $ - emptyTxBody + defaultTxBodyContent & addInputs recoverInputs & addOutputs depositOutputs & setValidityLowerBound lowerBoundSlot