diff --git a/cabal.project b/cabal.project index f4357f0bc18..9f9abc87b48 100644 --- a/cabal.project +++ b/cabal.project @@ -45,3 +45,11 @@ program-options constraints: quickcheck-instances==0.3.31, data-default==0.7.1.3 + +source-repository-package + type: git + location: https://github.com/locallycompact/cardano-api + tag: 1307d2af04091d8a3c7e1d798d2b9cb0de7df0df + --sha256: sha256-GoCYnBrStRxoAniCvo08LScfAeY7b2SmBfCDgxrS74c= + subdir: + cardano-api diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index 88488da4ff2..8583933a380 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -73,7 +73,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, mkSimpleTx, mkTransferTx, unsafeBuildTransaction) +import Hydra.Ledger.Cardano (addTxIns, mkSimpleTx, mkTransferTx, unsafeBuildTransaction) import Hydra.Logging (Tracer, traceWith) import Hydra.Options (DirectChainConfig (..), networkId, startChainFrom) import Hydra.Tx (HeadId, IsTx (balance), Party, txId) @@ -460,7 +460,7 @@ singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId = let spendingTx = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(scriptIn, scriptWitness)] + & addTxIns [(scriptIn, scriptWitness)] pure ( Aeson.object [ "blueprintTx" .= spendingTx diff --git a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs index f81cfe96d08..56fcc1eff6a 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, unsafeBuildTransaction) +import Hydra.Ledger.Cardano.Builder (addTxIns, addTxInsReference, addTxInsSpending, unsafeBuildTransaction) import Hydra.Ledger.Cardano.Evaluate (propTransactionEvaluates) import Hydra.Tx.BlueprintTx (CommitBlueprintTx (..)) import Hydra.Tx.Commit (commitTx) @@ -234,7 +234,7 @@ genBlueprintTxWithUTxO = utxoToSpend <- genUTxOAdaOnlyOfSize =<< choose (0, 3) pure ( utxo <> utxoToSpend - , txbody & addVkInputs (toList $ UTxO.inputSet utxoToSpend) + , txbody & addTxInsSpending (toList $ UTxO.inputSet utxoToSpend) ) spendSomeScriptInputs (utxo, txbody) = do @@ -249,7 +249,7 @@ genBlueprintTxWithUTxO = pure ( utxo <> utxoToSpend , txbody - & addInputs + & addTxIns ( UTxO.pairs $ ( \_ -> BuildTxWith $ @@ -263,7 +263,7 @@ genBlueprintTxWithUTxO = addSomeReferenceInputs (utxo, txbody) = do txout <- genTxOutWithReferenceScript txin <- arbitrary - pure (utxo <> UTxO.singleton (txin, txout), txbody & addReferenceInputs [txin]) + pure (utxo <> UTxO.singleton (txin, txout), txbody & addTxInsReference [txin]) addValidityRange (utxo, txbody) = do (start, end) <- arbitrary diff --git a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs index 42fdfa4909c..e6be5089a6a 100644 --- a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs +++ b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs @@ -4,7 +4,6 @@ module Hydra.Ledger.Cardano.Builder where import Hydra.Cardano.Api import Hydra.Prelude -import Data.Default (def) import Data.Map qualified as Map -- * Executing @@ -34,42 +33,8 @@ data InvalidTransactionException = InvalidTransactionException instance Exception InvalidTransactionException --- | Add new inputs to an ongoing builder. -addInputs :: TxIns BuildTx -> TxBodyContent BuildTx -> TxBodyContent BuildTx -addInputs ins tx = - tx{txIns = txIns tx <> ins} - -addReferenceInputs :: [TxIn] -> TxBodyContent BuildTx -> TxBodyContent BuildTx -addReferenceInputs refs' tx = - tx - { txInsReference = case txInsReference tx of - TxInsReferenceNone -> - TxInsReference refs' - TxInsReference refs -> - TxInsReference (refs <> refs') - } - --- | Like 'addInputs' but only for vk inputs which requires no additional data. -addVkInputs :: [TxIn] -> TxBodyContent BuildTx -> TxBodyContent BuildTx -addVkInputs ins = - addInputs ((,BuildTxWith $ KeyWitness KeyWitnessForSpending) <$> ins) - --- | Append new outputs to an ongoing builder. -addOutputs :: [TxOut CtxTx] -> TxBodyContent BuildTx -> TxBodyContent BuildTx -addOutputs outputs tx = - tx{txOuts = txOuts tx <> outputs} - --- | Add extra required key witnesses to a transaction. -addExtraRequiredSigners :: [Hash PaymentKey] -> TxBodyContent BuildTx -> TxBodyContent BuildTx -addExtraRequiredSigners vks tx = - tx{txExtraKeyWits = txExtraKeyWits'} - where - txExtraKeyWits' = - case txExtraKeyWits tx of - TxExtraKeyWitnessesNone -> - TxExtraKeyWitnesses vks - TxExtraKeyWitnesses vks' -> - TxExtraKeyWitnesses (vks' <> vks) +addTxInsSpending :: [TxIn] -> TxBodyContent BuildTx -> TxBodyContent BuildTx +addTxInsSpending txIns = addTxIns ((,BuildTxWith $ KeyWitness KeyWitnessForSpending) <$> txIns) -- | Mint tokens with given plutus minting script and redeemer. mintTokens :: ToScriptData redeemer => PlutusScript -> redeemer -> [(AssetName, Quantity)] -> TxBodyContent BuildTx -> TxBodyContent BuildTx @@ -98,13 +63,3 @@ mintTokens script redeemer assets tx = burnTokens :: ToScriptData redeemer => PlutusScript -> redeemer -> [(AssetName, Quantity)] -> TxBodyContent BuildTx -> TxBodyContent BuildTx burnTokens script redeemer assets = mintTokens script redeemer (fmap (second negate) assets) - --- | Set the upper validity bound for this transaction to some 'SlotNo'. -setValidityUpperBound :: SlotNo -> TxBodyContent BuildTx -> TxBodyContent BuildTx -setValidityUpperBound slotNo tx = - tx{txValidityUpperBound = TxValidityUpperBound slotNo} - --- | Set the lower validity bound for this transaction to some 'SlotNo'. -setValidityLowerBound :: SlotNo -> TxBodyContent BuildTx -> TxBodyContent BuildTx -setValidityLowerBound slotNo tx = - tx{txValidityLowerBound = TxValidityLowerBound slotNo} diff --git a/hydra-tx/src/Hydra/Tx/Abort.hs b/hydra-tx/src/Hydra/Tx/Abort.hs index 64034792d3c..7b86e39ecb2 100644 --- a/hydra-tx/src/Hydra/Tx/Abort.hs +++ b/hydra-tx/src/Hydra/Tx/Abort.hs @@ -11,10 +11,6 @@ import Hydra.Contract.HeadState qualified as Head import Hydra.Contract.Initial qualified as Initial import Hydra.Contract.MintAction (MintAction (Burn)) import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, burnTokens, unsafeBuildTransaction, ) @@ -54,11 +50,11 @@ abortTx committedUTxO scriptRegistry vk (headInput, initialHeadOutput) headToken Right $ unsafeBuildTransaction $ defaultTxBodyContent - & addInputs ((headInput, headWitness) : initialInputs <> commitInputs) - & addReferenceInputs ([headScriptRef, initialScriptRef] <> [commitScriptRef | not $ null commitInputs]) - & addOutputs reimbursedOutputs + & addTxIns ((headInput, headWitness) : initialInputs <> commitInputs) + & addTxInsReference ([headScriptRef, initialScriptRef] <> [commitScriptRef | not $ null commitInputs]) + & addTxOuts reimbursedOutputs & burnTokens headTokenScript Burn headTokens - & addExtraRequiredSigners [verificationKeyHash vk] + & addTxExtraKeyWits [verificationKeyHash vk] where headWitness = BuildTxWith $ diff --git a/hydra-tx/src/Hydra/Tx/Close.hs b/hydra-tx/src/Hydra/Tx/Close.hs index d183f34b145..0270f58c852 100644 --- a/hydra-tx/src/Hydra/Tx/Close.hs +++ b/hydra-tx/src/Hydra/Tx/Close.hs @@ -12,12 +12,6 @@ import Hydra.Data.ContestationPeriod (addContestationPeriod) import Hydra.Data.ContestationPeriod qualified as OnChain import Hydra.Data.Party qualified as OnChain import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, - setValidityLowerBound, - setValidityUpperBound, unsafeBuildTransaction, ) import Hydra.Plutus.Extras.Time (posixFromUTCTime) @@ -69,12 +63,12 @@ closeTx :: closeTx scriptRegistry vk headId openVersion confirmedSnapshot startSlotNo (endSlotNo, utcTime) openThreadOutput = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(headInput, headWitness)] - & addReferenceInputs [headScriptRef] - & addOutputs [headOutputAfter] - & addExtraRequiredSigners [verificationKeyHash vk] - & setValidityLowerBound startSlotNo - & setValidityUpperBound endSlotNo + & addTxIns [(headInput, headWitness)] + & addTxInsReference [headScriptRef] + & addTxOuts [headOutputAfter] + & addTxExtraKeyWits [verificationKeyHash vk] + & setTxValidityLowerBound (TxValidityLowerBound startSlotNo) + & setTxValidityUpperBound (TxValidityUpperBound endSlotNo) & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "CloseTx") where OpenThreadOutput diff --git a/hydra-tx/src/Hydra/Tx/CollectCom.hs b/hydra-tx/src/Hydra/Tx/CollectCom.hs index 0becda0a34a..0776d8b80ee 100644 --- a/hydra-tx/src/Hydra/Tx/CollectCom.hs +++ b/hydra-tx/src/Hydra/Tx/CollectCom.hs @@ -11,10 +11,6 @@ import Hydra.Contract.Commit qualified as Commit import Hydra.Contract.Head qualified as Head import Hydra.Contract.HeadState qualified as Head import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, unsafeBuildTransaction, ) import Hydra.Plutus (commitValidatorScript) @@ -51,10 +47,10 @@ collectComTx :: collectComTx networkId scriptRegistry vk headId headParameters (headInput, initialHeadOutput) commits utxoToCollect = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs ((headInput, headWitness) : (mkCommit <$> Map.keys commits)) - & addReferenceInputs [commitScriptRef, headScriptRef] - & addOutputs [headOutput] - & addExtraRequiredSigners [verificationKeyHash vk] + & addTxIns ((headInput, headWitness) : (mkCommit <$> Map.keys commits)) + & addTxInsReference [commitScriptRef, headScriptRef] + & addTxOuts [headOutput] + & addTxExtraKeyWits [verificationKeyHash vk] & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "CollectComTx") where HeadParameters{parties, contestationPeriod} = headParameters diff --git a/hydra-tx/src/Hydra/Tx/Contest.hs b/hydra-tx/src/Hydra/Tx/Contest.hs index 7156b18564d..2e99fcdd801 100644 --- a/hydra-tx/src/Hydra/Tx/Contest.hs +++ b/hydra-tx/src/Hydra/Tx/Contest.hs @@ -8,11 +8,6 @@ import Hydra.Contract.HeadState qualified as Head import Hydra.Data.ContestationPeriod (addContestationPeriod) import Hydra.Data.Party qualified as OnChain import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, - setValidityUpperBound, unsafeBuildTransaction, ) import Hydra.Plutus.Orphans () @@ -62,11 +57,11 @@ contestTx :: contestTx scriptRegistry vk headId contestationPeriod openVersion Snapshot{number, utxo, utxoToDecommit, version} sig (slotNo, _) closedThreadOutput = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(headInput, headWitness)] - & addReferenceInputs [headScriptRef] - & addOutputs [headOutputAfter] - & addExtraRequiredSigners [verificationKeyHash vk] - & setValidityUpperBound slotNo + & addTxIns [(headInput, headWitness)] + & addTxInsReference [headScriptRef] + & addTxOuts [headOutputAfter] + & addTxExtraKeyWits [verificationKeyHash vk] + & setTxValidityUpperBound (TxValidityUpperBound slotNo) & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "ContestTx") where ClosedThreadOutput diff --git a/hydra-tx/src/Hydra/Tx/Decrement.hs b/hydra-tx/src/Hydra/Tx/Decrement.hs index 6c130faf07d..ea6d973eb50 100644 --- a/hydra-tx/src/Hydra/Tx/Decrement.hs +++ b/hydra-tx/src/Hydra/Tx/Decrement.hs @@ -6,10 +6,6 @@ import Hydra.Prelude import Hydra.Contract.Head qualified as Head import Hydra.Contract.HeadState qualified as Head import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, unsafeBuildTransaction, ) import Hydra.Tx.ContestationPeriod (toChain) @@ -43,10 +39,10 @@ decrementTx :: decrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot signatures = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(headInput, headWitness)] - & addReferenceInputs [headScriptRef] - & addOutputs (headOutput' : map toTxContext decommitOutputs) - & addExtraRequiredSigners [verificationKeyHash vk] + & addTxIns [(headInput, headWitness)] + & addTxInsReference [headScriptRef] + & addTxOuts (headOutput' : map toTxContext decommitOutputs) + & addTxExtraKeyWits [verificationKeyHash vk] & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "DecrementTx") where headRedeemer = diff --git a/hydra-tx/src/Hydra/Tx/Fanout.hs b/hydra-tx/src/Hydra/Tx/Fanout.hs index f60e37a9b1a..005a2da2f79 100644 --- a/hydra-tx/src/Hydra/Tx/Fanout.hs +++ b/hydra-tx/src/Hydra/Tx/Fanout.hs @@ -7,11 +7,7 @@ import Hydra.Contract.Head qualified as Head import Hydra.Contract.HeadState qualified as Head import Hydra.Contract.MintAction (MintAction (..)) import Hydra.Ledger.Cardano.Builder ( - addInputs, - addOutputs, - addReferenceInputs, burnTokens, - setValidityLowerBound, unsafeBuildTransaction, ) import Hydra.Tx.ScriptRegistry (ScriptRegistry (..)) @@ -37,11 +33,11 @@ fanoutTx :: fanoutTx scriptRegistry utxo utxoToDecommit (headInput, headOutput) deadlineSlotNo headTokenScript = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(headInput, headWitness)] - & addReferenceInputs [headScriptRef] - & addOutputs (orderedTxOutsToFanout <> orderedTxOutsToDecommit) + & addTxIns [(headInput, headWitness)] + & addTxInsReference [headScriptRef] + & addTxOuts (orderedTxOutsToFanout <> orderedTxOutsToDecommit) & burnTokens headTokenScript Burn headTokens - & setValidityLowerBound (deadlineSlotNo + 1) + & setTxValidityLowerBound (TxValidityLowerBound $ deadlineSlotNo + 1) & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "FanoutTx") where headWitness = diff --git a/hydra-tx/src/Hydra/Tx/Increment.hs b/hydra-tx/src/Hydra/Tx/Increment.hs index c34e4d7441e..43eb16e2767 100644 --- a/hydra-tx/src/Hydra/Tx/Increment.hs +++ b/hydra-tx/src/Hydra/Tx/Increment.hs @@ -9,11 +9,6 @@ import Hydra.Contract.Deposit qualified as Deposit import Hydra.Contract.Head qualified as Head import Hydra.Contract.HeadState qualified as Head import Hydra.Ledger.Cardano.Builder ( - addExtraRequiredSigners, - addInputs, - addOutputs, - addReferenceInputs, - setValidityUpperBound, unsafeBuildTransaction, ) import Hydra.Tx.ContestationPeriod (toChain) @@ -48,11 +43,11 @@ incrementTx :: incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot depositScriptUTxO upperValiditySlot = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs [(headInput, headWitness), (depositIn, depositWitness)] - & addReferenceInputs [headScriptRef] - & addOutputs [headOutput'] - & addExtraRequiredSigners [verificationKeyHash vk] - & setValidityUpperBound upperValiditySlot + & addTxIns [(headInput, headWitness), (depositIn, depositWitness)] + & addTxInsReference [headScriptRef] + & addTxOuts [headOutput'] + & addTxExtraKeyWits [verificationKeyHash vk] + & setTxValidityUpperBound (TxValidityUpperBound upperValiditySlot) & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "IncrementTx") where headRedeemer = diff --git a/hydra-tx/src/Hydra/Tx/Init.hs b/hydra-tx/src/Hydra/Tx/Init.hs index 9c5aa03dc4d..e457fa4b166 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, mintTokens, unsafeBuildTransaction) +import Hydra.Ledger.Cardano.Builder (addTxInsSpending, mintTokens, unsafeBuildTransaction) import Hydra.Plutus (initialValidatorScript) import Hydra.Tx.ContestationPeriod (toChain) import Hydra.Tx.HeadParameters (HeadParameters (..)) @@ -29,8 +29,8 @@ initTx :: initTx networkId seedTxIn participants parameters = unsafeBuildTransaction $ defaultTxBodyContent - & addVkInputs [seedTxIn] - & addOutputs + & addTxInsSpending [seedTxIn] + & addTxOuts ( mkHeadOutputInitial networkId seedTxIn parameters : map (mkInitialOutput networkId seedTxIn) participants ) diff --git a/hydra-tx/src/Hydra/Tx/Recover.hs b/hydra-tx/src/Hydra/Tx/Recover.hs index 10d2146e60b..a25bef2100c 100644 --- a/hydra-tx/src/Hydra/Tx/Recover.hs +++ b/hydra-tx/src/Hydra/Tx/Recover.hs @@ -7,9 +7,6 @@ import Hydra.Cardano.Api import Hydra.Contract.Commit qualified as Commit import Hydra.Contract.Deposit qualified as Deposit import Hydra.Ledger.Cardano.Builder ( - addInputs, - addOutputs, - setValidityLowerBound, unsafeBuildTransaction, ) import Hydra.Tx (HeadId, mkHeadId) @@ -27,9 +24,9 @@ recoverTx :: recoverTx depositTxId deposited lowerBoundSlot = unsafeBuildTransaction $ defaultTxBodyContent - & addInputs recoverInputs - & addOutputs depositOutputs - & setValidityLowerBound lowerBoundSlot + & addTxIns recoverInputs + & addTxOuts depositOutputs + & setTxValidityLowerBound (TxValidityLowerBound lowerBoundSlot) & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "RecoverTx") where recoverInputs = (,depositWitness) <$> [TxIn depositTxId (TxIx 0)]