Skip to content

Commit

Permalink
Replace emptyTxBody with defaultTxBodyContent from cardano-api
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Dec 8, 2024
1 parent dd67f3d commit 72e1391
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 68 deletions.
5 changes: 3 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Hydra.API.HTTPServer (
TransactionSubmitted (..),
)
import Hydra.Cardano.Api (
defaultTxBodyContent,
Coin (..),
File (File),
Key (SigningKey),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -457,7 +458,7 @@ singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId =
mkScriptWitness serializedScript (mkScriptDatum ()) (toScriptData ())
let spendingTx =
unsafeBuildTransaction $
emptyTxBody
defaultTxBodyContent
& addInputs [(scriptIn, scriptWitness)]
pure
( Aeson.object
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Ledger/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -222,7 +222,7 @@ propIsSubmapOf as bs =
genBlueprintTxWithUTxO :: Gen (UTxO, Tx)
genBlueprintTxWithUTxO =
fmap (second unsafeBuildTransaction) $
spendingPubKeyOutput (mempty, emptyTxBody)
spendingPubKeyOutput (mempty, defaultTxBodyContent)
>>= spendSomeScriptInputs
>>= addSomeReferenceInputs
>>= addValidityRange
Expand Down
44 changes: 0 additions & 44 deletions hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Abort.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Hydra.Ledger.Cardano.Builder (
addOutputs,
addReferenceInputs,
burnTokens,
emptyTxBody,
unsafeBuildTransaction,
)
import Hydra.Plutus (commitValidatorScript, initialValidatorScript)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Close.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
addReferenceInputs,
emptyTxBody,
setValidityLowerBound,
setValidityUpperBound,
unsafeBuildTransaction,
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/CollectCom.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
addReferenceInputs,
emptyTxBody,
unsafeBuildTransaction,
)
import Hydra.Plutus (commitValidatorScript)
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Contest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
addReferenceInputs,
emptyTxBody,
setValidityUpperBound,
unsafeBuildTransaction,
)
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Decrement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
addReferenceInputs,
emptyTxBody,
unsafeBuildTransaction,
)
import Hydra.Tx.ContestationPeriod (toChain)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Fanout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Hydra.Ledger.Cardano.Builder (
addOutputs,
addReferenceInputs,
burnTokens,
emptyTxBody,
setValidityLowerBound,
unsafeBuildTransaction,
)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Increment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
addReferenceInputs,
emptyTxBody,
setValidityUpperBound,
unsafeBuildTransaction,
)
Expand Down Expand Up @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions hydra-tx/src/Hydra/Tx/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand All @@ -28,7 +28,7 @@ initTx ::
Tx
initTx networkId seedTxIn participants parameters =
unsafeBuildTransaction $
emptyTxBody
defaultTxBodyContent
& addVkInputs [seedTxIn]
& addOutputs
( mkHeadOutputInitial networkId seedTxIn parameters
Expand Down
3 changes: 1 addition & 2 deletions hydra-tx/src/Hydra/Tx/Recover.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Hydra.Contract.Deposit qualified as Deposit
import Hydra.Ledger.Cardano.Builder (
addInputs,
addOutputs,
emptyTxBody,
setValidityLowerBound,
unsafeBuildTransaction,
)
Expand All @@ -27,7 +26,7 @@ recoverTx ::
Tx
recoverTx depositTxId deposited lowerBoundSlot =
unsafeBuildTransaction $
emptyTxBody
defaultTxBodyContent
& addInputs recoverInputs
& addOutputs depositOutputs
& setValidityLowerBound lowerBoundSlot
Expand Down

0 comments on commit 72e1391

Please sign in to comment.