From b61cf71eaaa6fa05cfc4493df8b36c2fac1fb564 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 12:13:25 +0000 Subject: [PATCH 1/3] cardano-api: 10.2 --- cabal.project | 4 +- flake.lock | 98 +++++++++---------- hydra-cardano-api/hydra-cardano-api.cabal | 3 +- hydra-cardano-api/src/Hydra/Cardano/Api.hs | 17 ++-- .../src/Hydra/Cardano/Api/CtxUTxO.hs | 20 ---- .../src/Hydra/Cardano/Api/Pretty.hs | 4 +- .../src/Hydra/Cardano/Api/ScriptData.hs | 2 +- .../src/Hydra/Cardano/Api/Value.hs | 3 +- hydra-cluster/src/Hydra/Cluster/Faucet.hs | 2 +- hydra-cluster/test/Test/EndToEndSpec.hs | 2 +- hydra-node/src/Hydra/Chain/CardanoClient.hs | 1 - hydra-node/src/Hydra/Chain/Direct/Tx.hs | 4 +- hydra-node/src/Hydra/Ledger/Cardano.hs | 2 +- hydra-node/test/Hydra/Chain/Direct/TxSpec.hs | 6 +- hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs | 1 - hydra-tx/src/Hydra/Tx/Deposit.hs | 2 +- hydra-tx/test/Hydra/Tx/Contract/Abort.hs | 17 ++-- .../Hydra/Tx/Contract/Close/CloseInitial.hs | 2 +- .../Hydra/Tx/Contract/Close/CloseUnused.hs | 5 +- .../test/Hydra/Tx/Contract/Close/CloseUsed.hs | 4 +- hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs | 6 +- hydra-tx/test/Hydra/Tx/Contract/Commit.hs | 10 +- .../test/Hydra/Tx/Contract/Contest/Healthy.hs | 2 +- hydra-tx/test/Hydra/Tx/Contract/Decrement.hs | 2 +- hydra-tx/test/Hydra/Tx/Contract/FanOut.hs | 2 +- hydra-tx/test/Hydra/Tx/Contract/Increment.hs | 2 +- hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs | 8 +- 27 files changed, 101 insertions(+), 130 deletions(-) delete mode 100644 hydra-cardano-api/src/Hydra/Cardano/Api/CtxUTxO.hs diff --git a/cabal.project b/cabal.project index d980aad31a2..f4357f0bc18 100644 --- a/cabal.project +++ b/cabal.project @@ -12,8 +12,8 @@ repository cardano-haskell-packages -- See CONTRIBUTING.md for information about when and how to update these. index-state: - , hackage.haskell.org 2024-11-12T16:26:18Z - , cardano-haskell-packages 2024-11-12T08:40:13Z + , hackage.haskell.org 2024-11-22T14:59:16Z + , cardano-haskell-packages 2024-12-05T13:51:16Z packages: hydra-prelude diff --git a/flake.lock b/flake.lock index e5a562527e9..4b1b40f14a2 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1731401651, - "narHash": "sha256-tXaUck9+0Ob4h6GBlbhYMI4ekW5e8biVJU5jPT/rjus=", + "lastModified": 1734943824, + "narHash": "sha256-kcyysnPJbjdJOmtTldC08xj2Ttp2XcY6ecbYOYdwkmY=", "owner": "IntersectMBO", "repo": "cardano-haskell-packages", - "rev": "82b295d6147a566c28dbcf038c54040f06f7e6b4", + "rev": "6ec767f1afd771816c5f3b383d0e1d3b577d72fe", "type": "github" }, "original": { @@ -73,11 +73,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1729359954, - "narHash": "sha256-cspIIuH+0LJItTz9wk6mChwEMFP3GDpI+KKg0FWM9bQ=", + "lastModified": 1735819052, + "narHash": "sha256-1Q13SKOXW89soBi+6zTHoCbfrjAatgqoD8a4/jILhdk=", "owner": "aiken-lang", "repo": "aiken", - "rev": "a7741ec286bd939784f3183420be845d22de9a25", + "rev": "620fe6b2997537aab655fefaf27b43e5c8ed1916", "type": "github" }, "original": { @@ -628,11 +628,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1719994518, - "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "lastModified": 1735774679, + "narHash": "sha256-soePLBazJk0qQdDVhdbM98vYdssfs3WFedcq+raipRI=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "rev": "f2f7418ce0ab4a5309a4596161d154cfc877af66", "type": "github" }, "original": { @@ -700,11 +700,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -897,11 +897,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1731371270, - "narHash": "sha256-9hAGzHPyc6EncczyVrDrjElS6H9wwlR4j1fj4JRTigw=", + "lastModified": 1735777688, + "narHash": "sha256-ZY/zdPOzBpTfwxDFh5oLnHCqV0Yz77aOa4AXU/llukg=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "c96fd8da826bb383b7fa36cfe7d386013f070fa4", + "rev": "8bbb2063840a8a8519698c32642e8b0c78975df2", "type": "github" }, "original": { @@ -1023,11 +1023,11 @@ "stackage": "stackage_2" }, "locked": { - "lastModified": 1731372695, - "narHash": "sha256-QddLLOvRtrao9Ztuk1rYSXmepxH2/blYRfuRWx/QUyM=", + "lastModified": 1735779099, + "narHash": "sha256-55RMrxp/3aBS+8R5eaWDFSY1UabZZbxBDcJzr8O3+HQ=", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "54ddc77cd29c19779489d8f7fae14d70e90d8c68", + "rev": "a9847e3d5befb6358df648de64ff5628b86d92b3", "type": "github" }, "original": { @@ -1062,11 +1062,11 @@ "hls": { "flake": false, "locked": { - "lastModified": 1720542277, - "narHash": "sha256-6MWZpMYB+5VDmQavRzlbItbXqYxuKvvI2F/pahgo7NE=", + "lastModified": 1735065702, + "narHash": "sha256-jDwyGRqvtyXLRY4PexAOcWVUrlII+IlonBzcRS9v9Gg=", "owner": "haskell", "repo": "haskell-language-server", - "rev": "d331019b3715d3fe78684b170ad1aec06a2c833d", + "rev": "f09500b85f0f75acdbf15096ef0c04e0a134f43a", "type": "github" }, "original": { @@ -1527,11 +1527,11 @@ "sodium": "sodium_2" }, "locked": { - "lastModified": 1730297014, - "narHash": "sha256-n3f1iAmltKnorHWx7FrdbGIF/FmEG8SsZshS16vnpz0=", + "lastModified": 1734618971, + "narHash": "sha256-5StB/VhWHOj3zlBxshqVFa6cwAE0Mk/wxRo3eEfcy74=", "owner": "input-output-hk", "repo": "iohk-nix", - "rev": "d407eedd4995e88d08e83ef75844a8a9c2e29b36", + "rev": "dc900a3448e805243b0ed196017e8eb631e32240", "type": "github" }, "original": { @@ -1713,11 +1713,11 @@ "treefmt-nix": "treefmt-nix_2" }, "locked": { - "lastModified": 1734004356, - "narHash": "sha256-VkjGMXv4o5djKgwVZ3alut1+2w3inR77yo5BvB3DHQU=", + "lastModified": 1735809726, + "narHash": "sha256-dsGImUnYyRD/KG9bkA8PrwOwY/OrRLbT/+sBa0s44M4=", "owner": "input-output-hk", "repo": "mithril", - "rev": "12c09d851f69b178a16ed52048fcd617d2a4e997", + "rev": "df60a00a4c31bb002e1662442fd30b498201cffa", "type": "github" }, "original": { @@ -1909,11 +1909,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1725103162, - "narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=", + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", "type": "github" }, "original": { @@ -2165,14 +2165,14 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1719876945, - "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "lastModified": 1735774519, + "narHash": "sha256-CewEm1o2eVAnoqb6Ml+Qi9Gg/EfNAxbRx1lANGVyoLI=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz" } }, "nixpkgs-lib_2": { @@ -2277,11 +2277,11 @@ }, "nixpkgsLatest": { "locked": { - "lastModified": 1721226092, - "narHash": "sha256-UBvzVpo5sXSi2S/Av+t+Q+C2mhMIw/LBEZR+d6NMjws=", + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c716603a63aca44f39bef1986c13402167450e0a", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", "type": "github" }, "original": { @@ -2370,11 +2370,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1718428119, - "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", "type": "github" }, "original": { @@ -2607,11 +2607,11 @@ }, "process-compose-flake": { "locked": { - "lastModified": 1718031437, - "narHash": "sha256-+RrlkAVZx0QhyeHAGFJnjST+/7Dc3zsDU3zAKXoDXaI=", + "lastModified": 1733325752, + "narHash": "sha256-79tzPuXNRo1NUllafYW6SjeLtjqfnLGq7tHCM7cAXNg=", "owner": "Platonic-Systems", "repo": "process-compose-flake", - "rev": "9344fac44edced4c686721686a6ad904d067c546", + "rev": "1012530b582f1bd3b102295c799358d95abf42d7", "type": "github" }, "original": { @@ -2647,11 +2647,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1725330199, - "narHash": "sha256-oUkdPJIxP3r3YyVOBLkDVLIJiQV9YlrVqA+jNcdpCvM=", + "lastModified": 1732069891, + "narHash": "sha256-moKx8AVJrViCSdA0e0nSsG8b1dAsObI4sRAtbqbvBY8=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a562172c72d00350f9f2ff830e6515b6e7bee6d5", + "rev": "8509a51241c407d583b1963d5079585a992506e8", "type": "github" }, "original": { @@ -2747,11 +2747,11 @@ "stackage_2": { "flake": false, "locked": { - "lastModified": 1731370260, - "narHash": "sha256-DsuG/LEJduoxwK+VbKubVsCfg1WFAUaewYAUFLW0FRU=", + "lastModified": 1735776674, + "narHash": "sha256-Mz6MbNxciGbDUMpAf11yh8Qp89OHr2ZN7Tnuzo+xiuQ=", "owner": "input-output-hk", "repo": "stackage.nix", - "rev": "5b7b9fad43a035243f87f654ac5611f597ce5fc2", + "rev": "b9c770203a5efeaf883fbdcd84939a67f1a5952e", "type": "github" }, "original": { diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index e32ae4d3e2e..a5142c13e79 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -47,7 +47,6 @@ library Hydra.Cardano.Api.BlockHeader Hydra.Cardano.Api.ChainPoint Hydra.Cardano.Api.CtxTx - Hydra.Cardano.Api.CtxUTxO Hydra.Cardano.Api.ExecutionUnits Hydra.Cardano.Api.Hash Hydra.Cardano.Api.Network @@ -79,7 +78,7 @@ library , aeson >=2 , base >=4.16 , bytestring - , cardano-api ^>=10.1 + , cardano-api ^>=10.2 , cardano-binary , cardano-crypto-class , cardano-ledger-allegra diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api.hs b/hydra-cardano-api/src/Hydra/Cardano/Api.hs index 0fa56d4d624..63b5eeca079 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api.hs @@ -72,7 +72,6 @@ import Cardano.Api as X hiding ( fromLedgerValue, green, makeShelleyKeyWitness, - policyId, queryEraHistory, queryProtocolParameters, queryStakePools, @@ -127,7 +126,6 @@ import Hydra.Cardano.Api.AddressInEra as Extras import Hydra.Cardano.Api.BlockHeader as Extras import Hydra.Cardano.Api.ChainPoint as Extras import Hydra.Cardano.Api.CtxTx as Extras -import Hydra.Cardano.Api.CtxUTxO as Extras import Hydra.Cardano.Api.ExecutionUnits as Extras import Hydra.Cardano.Api.Hash as Extras import Hydra.Cardano.Api.NetworkId () @@ -392,7 +390,6 @@ pattern TxBodyContent :: TxValidityUpperBound -> TxMetadataInEra -> TxAuxScripts -> - BuildTxWith buidl (TxSupplementalDatums Era) -> TxExtraKeyWitnesses -> BuildTxWith buidl (Maybe (LedgerProtocolParameters Era)) -> TxWithdrawals buidl Era -> @@ -417,7 +414,6 @@ pattern TxBodyContent , txValidityUpperBound , txMetadata , txAuxScripts - , txSupplementalDatums , txExtraKeyWits , txProtocolParams , txWithdrawals @@ -442,7 +438,6 @@ pattern TxBodyContent txValidityUpperBound txMetadata txAuxScripts - txSupplementalDatums txExtraKeyWits txProtocolParams txWithdrawals @@ -637,7 +632,7 @@ pattern ReferenceScriptNone <- -- ** TxOutDatum type TxOutDatum ctx = Cardano.Api.TxOutDatum ctx Era -{-# COMPLETE TxOutDatumNone, TxOutDatumHash, TxOutDatumInTx, TxOutDatumInline #-} +{-# COMPLETE TxOutDatumNone, TxOutDatumHash, TxOutSupplementalDatum, TxOutDatumInline #-} pattern TxOutDatumNone :: TxOutDatum ctx pattern TxOutDatumNone <- @@ -653,12 +648,12 @@ pattern TxOutDatumHash{txOutDatumHash} <- TxOutDatumHash = Cardano.Api.TxOutDatumHash alonzoBasedEra -pattern TxOutDatumInTx :: HashableScriptData -> TxOutDatum CtxTx -pattern TxOutDatumInTx{txOutDatumScriptData} <- - Cardano.Api.TxOutDatumInTx _ txOutDatumScriptData +pattern TxOutSupplementalDatum :: HashableScriptData -> TxOutDatum CtxTx +pattern TxOutSupplementalDatum{txOutDatumScriptData} <- + Cardano.Api.TxOutSupplementalDatum _ txOutDatumScriptData where - TxOutDatumInTx = - Cardano.Api.TxOutDatumInTx alonzoBasedEra + TxOutSupplementalDatum = + Cardano.Api.TxOutSupplementalDatum alonzoBasedEra pattern TxOutDatumInline :: HashableScriptData -> TxOutDatum ctx pattern TxOutDatumInline{txOutDatumInlineScriptData} <- diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/CtxUTxO.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/CtxUTxO.hs deleted file mode 100644 index eaeeccf752c..00000000000 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/CtxUTxO.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Hydra.Cardano.Api.CtxUTxO where - -import Hydra.Cardano.Api.Prelude - --- | A convenient type-class for transforming types in 'CtxTx' to 'CtxUTxO'. --- --- See also 'ToTxContext' for the reverse. -class ToUTxOContext f where - toUTxOContext :: f CtxTx era -> f CtxUTxO era - -instance ToUTxOContext TxOutDatum where - toUTxOContext = \case - TxOutDatumNone -> TxOutDatumNone - TxOutDatumHash s h -> TxOutDatumHash s h - TxOutDatumInTx s d -> TxOutDatumHash s (hashScriptDataBytes d) - TxOutDatumInline s sd -> TxOutDatumInline s sd - -instance ToUTxOContext TxOut where - toUTxOContext (TxOut addr value dat ref) = - TxOut addr value (toUTxOContext dat) ref diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs index 015695a1fc1..492a479f581 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs @@ -134,10 +134,10 @@ renderTxWithUTxO utxo (Tx body _wits) = "TxOutDatumNone" Api.TxOutDatumHash h -> "TxOutDatumHash " <> show h - Api.TxOutDatumInTx scriptData -> - "TxOutDatumInTx " <> prettyScriptData scriptData Api.TxOutDatumInline scriptData -> "TxOutDatumInline " <> prettyScriptData scriptData + Api.TxOutSupplementalDatum scriptData -> + "TxOutSupplementalDatum " <> prettyScriptData scriptData scriptLines = [ "== SCRIPTS (" <> show (length scripts) <> ")" diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs index 5d4406e732d..5dd51783fbf 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs @@ -34,8 +34,8 @@ fromScriptData = txOutScriptData :: TxOut CtxTx era -> Maybe HashableScriptData txOutScriptData (TxOut _ _ d _) = case d of - TxOutDatumInTx _ sd -> Just sd TxOutDatumInline _ sd -> Just sd + TxOutSupplementalDatum _ sd -> Just sd _ -> Nothing -- * Type Conversions diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs index 61f7d9031ea..92427c32e70 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs @@ -7,7 +7,6 @@ import Cardano.Ledger.Core (getMinCoinTxOut) import Cardano.Ledger.Mary.Value qualified as Ledger import Data.Word (Word64) import GHC.IsList (IsList (..)) -import Hydra.Cardano.Api.CtxUTxO (ToUTxOContext (..)) import Hydra.Cardano.Api.PolicyId (fromPlutusCurrencySymbol) import PlutusLedgerApi.V1.Value (flattenValue) import PlutusLedgerApi.V3 (adaSymbol, adaToken, fromBuiltin, unTokenName) @@ -24,7 +23,7 @@ minUTxOValue pparams (TxOut addr val dat ref) = lovelaceToValue $ getMinCoinTxOut pparams - (toShelleyTxOut shelleyBasedEra (toUTxOContext out')) + (toShelleyTxOut shelleyBasedEra $ toCtxUTxOTxOut out') where out' = TxOut diff --git a/hydra-cluster/src/Hydra/Cluster/Faucet.hs b/hydra-cluster/src/Hydra/Cluster/Faucet.hs index 6ddb3ff56a2..fb17367247b 100644 --- a/hydra-cluster/src/Hydra/Cluster/Faucet.hs +++ b/hydra-cluster/src/Hydra/Cluster/Faucet.hs @@ -56,7 +56,7 @@ seedFromFaucet node@RunningNode{networkId, nodeSocket} receivingVerificationKey (faucetVk, faucetSk) <- keysFor Faucet seedTx <- retryOnExceptions tracer $ submitSeedTx faucetVk faucetSk producedUTxO <- awaitTransaction networkId nodeSocket seedTx - pure $ UTxO.filter (== toUTxOContext theOutput) producedUTxO + pure $ UTxO.filter (== toCtxUTxOTxOut theOutput) producedUTxO where submitSeedTx faucetVk faucetSk = do faucetUTxO <- findFaucetUTxO node lovelace diff --git a/hydra-cluster/test/Test/EndToEndSpec.hs b/hydra-cluster/test/Test/EndToEndSpec.hs index 332cee77201..23cff102141 100644 --- a/hydra-cluster/test/Test/EndToEndSpec.hs +++ b/hydra-cluster/test/Test/EndToEndSpec.hs @@ -146,7 +146,7 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do -- Restart a hydra-node in offline mode expect we can reverse the transaction (it retains state) withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 1 aliceSk [] [1] $ \node -> do let - bobTxOut = toUTxOContext $ List.head (txOuts' aliceToBob) + bobTxOut = toCtxUTxOTxOut $ List.head (txOuts' aliceToBob) Right bobToAlice = mkSimpleTx (mkTxIn aliceToBob 0, bobTxOut) diff --git a/hydra-node/src/Hydra/Chain/CardanoClient.hs b/hydra-node/src/Hydra/Chain/CardanoClient.hs index 28a638f0b96..cfa91d40f25 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -118,7 +118,6 @@ buildTransaction networkId socket changeAddress utxoToSpend collateral outs = do TxValidityNoUpperBound TxMetadataNone TxAuxScriptsNone - (BuildTxWith TxSupplementalDataNone) TxExtraKeyWitnessesNone (BuildTxWith $ Just $ LedgerProtocolParameters pparams) TxWithdrawalsNone diff --git a/hydra-node/src/Hydra/Chain/Direct/Tx.hs b/hydra-node/src/Hydra/Chain/Direct/Tx.hs index e7692028a8d..c8881fdf5a8 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -250,7 +250,7 @@ observeCommitTx networkId utxo tx = do policyId <- fromPlutusCurrencySymbol headId pure CommitObservation - { commitOutput = (commitIn, toUTxOContext commitOut) + { commitOutput = (commitIn, toCtxUTxOTxOut commitOut) , party , committed , headId = mkHeadId policyId @@ -382,7 +382,7 @@ observeDecrementTx utxo tx = do { headId , newVersion = fromChainSnapshotVersion version , distributedOutputs = - toUTxOContext <$> txOuts' tx + toCtxUTxOTxOut <$> txOuts' tx & drop 1 -- NOTE: Head output must be in first position & take (fromIntegral numberOfDecommitOutputs) } diff --git a/hydra-node/src/Hydra/Ledger/Cardano.hs b/hydra-node/src/Hydra/Ledger/Cardano.hs index 6e3b13bcb07..7434abe338b 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano.hs @@ -197,7 +197,7 @@ adjustUTxO tx utxo = let txid = txId tx consumed = txIns' tx produced = - toUTxOContext + toCtxUTxOTxOut <$> fromPairs ((\(txout, ix) -> (TxIn txid (TxIx ix), txout)) <$> zip (txOuts' tx) [0 ..]) utxo' = fromPairs $ filter (\(txin, _) -> txin `notElem` consumed) $ pairs utxo in utxo' <> produced diff --git a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs index f08d9d55c5f..193b81ead95 100644 --- a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs @@ -137,7 +137,7 @@ spec = let commitSigningKey = genSigningKey `generateWith` 42 let commitVerificationKey = getVerificationKey commitSigningKey let healthyInitialTxOut = - setMinUTxOValue Fixture.pparams . toUTxOContext $ + setMinUTxOValue Fixture.pparams . toCtxUTxOTxOut $ mkInitialOutput Fixture.testNetworkId Fixture.testSeedInput $ verificationKeyToOnChainId commitVerificationKey let healthyInitialTxIn = generateWith arbitrary 42 @@ -152,12 +152,12 @@ spec = (mkHeadId Fixture.testPolicyId) ownParty CommitBlueprintTx{lookupUTxO, blueprintTx} - (healthyInitialTxIn, toUTxOContext healthyInitialTxOut, verificationKeyHash ownVerificationKey) + (healthyInitialTxIn, toCtxUTxOTxOut healthyInitialTxOut, verificationKeyHash ownVerificationKey) counterexample ("\n\n\nCommit tx: " <> renderTxWithUTxO lookupUTxO createdTx) $ do let blueprintBody = toLedgerTx blueprintTx ^. bodyTxL let commitTxBody = toLedgerTx createdTx ^. bodyTxL let spendableUTxO = - UTxO.singleton (healthyInitialTxIn, toUTxOContext healthyInitialTxOut) + UTxO.singleton (healthyInitialTxIn, toCtxUTxOTxOut healthyInitialTxOut) <> lookupUTxO <> registryUTxO scriptRegistry diff --git a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs index bd996c69643..255f2e11056 100644 --- a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs +++ b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs @@ -65,7 +65,6 @@ emptyTxBody = TxValidityNoUpperBound TxMetadataNone TxAuxScriptsNone - (BuildTxWith TxSupplementalDataNone) TxExtraKeyWitnessesNone (BuildTxWith $ Just $ LedgerProtocolParameters def) TxWithdrawalsNone diff --git a/hydra-tx/src/Hydra/Tx/Deposit.hs b/hydra-tx/src/Hydra/Tx/Deposit.hs index 955bf4ef97e..88913b65e0a 100644 --- a/hydra-tx/src/Hydra/Tx/Deposit.hs +++ b/hydra-tx/src/Hydra/Tx/Deposit.hs @@ -81,7 +81,7 @@ observeDepositTx :: observeDepositTx networkId tx = do -- TODO: could just use the first output and fail otherwise (TxIn depositTxId _, depositOut) <- findTxOutByAddress (depositAddress networkId) tx - (headId, deposited, deadline) <- observeDepositTxOut (networkIdToNetwork networkId) (toUTxOContext depositOut) + (headId, deposited, deadline) <- observeDepositTxOut (networkIdToNetwork networkId) (toCtxUTxOTxOut depositOut) if all (`elem` txIns' tx) (UTxO.inputSet deposited) then Just diff --git a/hydra-tx/test/Hydra/Tx/Contract/Abort.hs b/hydra-tx/test/Hydra/Tx/Contract/Abort.hs index 028d0352aaf..adaa51af71f 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Abort.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Abort.hs @@ -64,7 +64,7 @@ healthyAbortTx = (tx, lookupUTxO) where lookupUTxO = - UTxO.singleton (healthyHeadInput, toUTxOContext headOutput) + UTxO.singleton (healthyHeadInput, toCtxUTxOTxOut headOutput) <> UTxO (Map.fromList healthyInitials) <> UTxO (Map.fromList (map (\(i, o, _) -> (i, o)) healthyCommits)) <> registryUTxO scriptRegistry @@ -75,7 +75,7 @@ healthyAbortTx = committedUTxO scriptRegistry somePartyCardanoVerificationKey - (healthyHeadInput, toUTxOContext headOutput) + (healthyHeadInput, toCtxUTxOTxOut headOutput) headTokenScript (Map.fromList healthyInitials) (Map.fromList (map (\(i, o, _) -> (i, o)) healthyCommits)) @@ -286,12 +286,11 @@ genAbortableOutputs parties = initialTxOut :: VerificationKey PaymentKey -> TxOut CtxUTxO initialTxOut vk = - toUTxOContext $ - TxOut - (mkScriptAddress testNetworkId initialScript) - (fromList [(AssetId testPolicyId (assetNameFromVerificationKey vk), 1)]) - (mkTxOutDatumInline initialDatum) - ReferenceScriptNone + TxOut + (mkScriptAddress testNetworkId initialScript) + (fromList [(AssetId testPolicyId (assetNameFromVerificationKey vk), 1)]) + (mkTxOutDatumInline initialDatum) + ReferenceScriptNone initialScript = fromPlutusScript @PlutusScriptV3 initialValidatorScript @@ -315,7 +314,7 @@ generateCommitUTxOs parties = do where mkCommitUTxO :: (VerificationKey PaymentKey, Party) -> UTxO -> (TxOut CtxUTxO, UTxO) mkCommitUTxO (vk, party) utxo = - ( toUTxOContext $ + ( toCtxUTxOTxOut $ TxOut (mkScriptAddress testNetworkId commitScript) commitValue diff --git a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs index c57941f967d..f50796dd87f 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs @@ -75,7 +75,7 @@ healthyCloseInitialTx = setIncrementalActionMaybe (utxoToCommit $ getSnapshot closingSnapshot) (utxoToDecommit $ getSnapshot closingSnapshot) initialDatum :: TxOutDatum CtxUTxO - initialDatum = toUTxOContext (mkTxOutDatumInline healthyInitialOpenDatum) + initialDatum = mkTxOutDatumInline healthyInitialOpenDatum lookupUTxO :: UTxO' (TxOut CtxUTxO) lookupUTxO = diff --git a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs index 21389f5a05a..6722eb53b45 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs @@ -95,7 +95,8 @@ healthyCloseCurrentTx = incrementalAction = fromMaybe NoThing $ setIncrementalActionMaybe (utxoToCommit $ getSnapshot closeUnusedSnapshot) (utxoToDecommit $ getSnapshot closeUnusedSnapshot) - datum = toUTxOContext $ mkTxOutDatumInline healthyCurrentOpenDatum + + datum = mkTxOutDatumInline healthyCurrentOpenDatum lookupUTxO = UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut datum) @@ -317,7 +318,7 @@ genCloseCurrentMutation (tx, _utxo) = headTxOut = fromJust $ txOuts' tx !!? 0 - datum = toUTxOContext (mkTxOutDatumInline healthyCurrentOpenDatum) + datum = mkTxOutDatumInline healthyCurrentOpenDatum -- | Generate not acceptable, but interesting deadlines. genMutatedDeadline :: Gen POSIXTime diff --git a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs index a52cffaae0d..6403f2c1732 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs @@ -142,7 +142,7 @@ healthyCloseOutdatedTx = scriptRegistry = genScriptRegistry `generateWith` 42 datum :: TxOutDatum CtxUTxO - datum = toUTxOContext (mkTxOutDatumInline healthyOutdatedOpenDatum) + datum = mkTxOutDatumInline healthyOutdatedOpenDatum openThreadOutput :: OpenThreadOutput openThreadOutput = @@ -379,7 +379,7 @@ genCloseOutdatedMutation (tx, _utxo) = headTxOut = fromJust $ txOuts' tx !!? 0 - datum = toUTxOContext (mkTxOutDatumInline healthyOutdatedOpenDatum) + datum = mkTxOutDatumInline healthyOutdatedOpenDatum -- | Generate not acceptable, but interesting deadlines. genMutatedDeadline :: Gen POSIXTime diff --git a/hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs b/hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs index ee988e9a5cd..56663dfa518 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs @@ -127,7 +127,7 @@ healthyHeadTxOut = mkHeadOutput testNetworkId testPolicyId - (toUTxOContext $ mkTxOutDatumInline healthyCollectComInitialDatum) + (mkTxOutDatumInline healthyCollectComInitialDatum) healthyCollectComInitialDatum :: Head.State healthyCollectComInitialDatum = @@ -236,7 +236,7 @@ genCollectComMutation (tx, _utxo) = illedHeadResolvedInput <- mkHeadOutput testNetworkId <$> fmap headPolicyId (arbitrary `suchThat` (/= testSeedInput)) - <*> pure (toUTxOContext $ mkTxOutDatumInline healthyCollectComInitialDatum) + <*> pure (mkTxOutDatumInline healthyCollectComInitialDatum) return $ ChangeInput healthyHeadTxIn illedHeadResolvedInput (Just $ toScriptData Head.CollectCom) , SomeMutation (pure $ toErrorCode SignerIsNotAParticipant) MutateRequiredSigner <$> do newSigner <- verificationKeyHash <$> genVerificationKey @@ -251,7 +251,7 @@ genCollectComMutation (tx, _utxo) = Changes [ ChangeInput txIn - (toUTxOContext $ mkInitialOutput testNetworkId testSeedInput participant) + (toCtxUTxOTxOut $ mkInitialOutput testNetworkId testSeedInput participant) (Just . toScriptData . Initial.redeemer $ Initial.ViaCommit [toPlutusTxOutRef txIn]) , AddScript $ fromPlutusScript initialValidatorScript ] diff --git a/hydra-tx/test/Hydra/Tx/Contract/Commit.hs b/hydra-tx/test/Hydra/Tx/Contract/Commit.hs index 77afd1c7501..5dac2e89f5d 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Commit.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Commit.hs @@ -41,7 +41,7 @@ healthyCommitTx = (tx', lookupUTxO) where lookupUTxO = - UTxO.singleton (healthyInitialTxIn, toUTxOContext healthyInitialTxOut) + UTxO.singleton (healthyInitialTxIn, toCtxUTxOTxOut healthyInitialTxOut) <> healthyCommittedUTxO <> registryUTxO scriptRegistry @@ -59,7 +59,7 @@ healthyCommitTx = (mkHeadId Fixture.testPolicyId) commitParty CommitBlueprintTx{lookupUTxO = healthyCommittedUTxO, blueprintTx} - (healthyInitialTxIn, toUTxOContext healthyInitialTxOut, initialPubKeyHash) + (healthyInitialTxIn, toCtxUTxOTxOut healthyInitialTxOut, initialPubKeyHash) scriptRegistry = genScriptRegistry `generateWith` 42 @@ -79,7 +79,7 @@ healthyInitialTxIn = generateWith arbitrary 42 healthyInitialTxOut :: TxOut CtxTx healthyInitialTxOut = - setMinUTxOValue Fixture.pparams . toUTxOContext $ + setMinUTxOValue Fixture.pparams . toCtxUTxOTxOut $ mkInitialOutput Fixture.testNetworkId Fixture.testSeedInput $ verificationKeyToOnChainId commitVerificationKey @@ -147,7 +147,7 @@ genCommitMutation (tx, _utxo) = , ChangeOutput 0 mutatedCommitTxOut , ChangeInput healthyInitialTxIn - (toUTxOContext healthyInitialTxOut) + (toCtxUTxOTxOut healthyInitialTxOut) (Just $ toScriptData $ Initial.ViaCommit (removedTxIn `List.delete` allComittedTxIn <&> toPlutusTxOutRef)) ] , SomeMutation (pure $ toErrorCode MissingOrInvalidCommitAuthor) MutateRequiredSigner <$> do @@ -162,7 +162,7 @@ genCommitMutation (tx, _utxo) = [ ChangeOutput 0 (replacePolicyIdWith Fixture.testPolicyId otherHeadId commitTxOut) , ChangeInput healthyInitialTxIn - (toUTxOContext $ replacePolicyIdWith Fixture.testPolicyId otherHeadId healthyInitialTxOut) + (toCtxUTxOTxOut $ replacePolicyIdWith Fixture.testPolicyId otherHeadId healthyInitialTxOut) (Just $ toScriptData $ Initial.ViaCommit (allComittedTxIn <&> toPlutusTxOutRef)) ] , SomeMutation (pure $ toErrorCode MintingOrBurningIsForbidden) MutateTokenMintingOrBurning diff --git a/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs b/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs index 1343aed77b3..562c4db5c06 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs @@ -157,7 +157,7 @@ healthyClosedHeadTxOut = mkHeadOutput testNetworkId testPolicyId headTxOutDatum & addParticipationTokens healthyParticipants where - headTxOutDatum = toUTxOContext (mkTxOutDatumInline healthyClosedState) + headTxOutDatum = toCtxUTxOTxOut (mkTxOutDatumInline healthyClosedState) healthyOnChainContestationPeriod :: OnChain.ContestationPeriod healthyOnChainContestationPeriod = OnChain.contestationPeriodFromDiffTime $ fromInteger healthyContestationPeriodSeconds diff --git a/hydra-tx/test/Hydra/Tx/Contract/Decrement.hs b/hydra-tx/test/Hydra/Tx/Contract/Decrement.hs index 25f75127e8f..ee1aa3bb8a7 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Decrement.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Decrement.hs @@ -70,7 +70,7 @@ healthyDecrementTx = headInput = generateWith arbitrary 42 headOutput = - mkHeadOutput testNetworkId testPolicyId (toUTxOContext $ mkTxOutDatumInline healthyDatum) + mkHeadOutput testNetworkId testPolicyId (mkTxOutDatumInline healthyDatum) & addParticipationTokens healthyParticipants & modifyTxOutValue (<> foldMap txOutValue healthyUTxO) diff --git a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs index 36b7cd66c34..b201da5e71a 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs @@ -53,7 +53,7 @@ healthyFanoutTx = headTokenScript = mkHeadTokenScript testSeedInput - headOutput' = mkHeadOutput testNetworkId testPolicyId (toUTxOContext $ mkTxOutDatumInline healthyFanoutDatum) + headOutput' = mkHeadOutput testNetworkId testPolicyId (mkTxOutDatumInline healthyFanoutDatum) headOutput = modifyTxOutValue (<> participationTokens) headOutput' diff --git a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs index cfb72b45a97..8868e894767 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs @@ -79,7 +79,7 @@ healthyIncrementTx = headInput = generateWith arbitrary 42 headOutput = - mkHeadOutput testNetworkId testPolicyId (toUTxOContext $ mkTxOutDatumInline healthyDatum) + mkHeadOutput testNetworkId testPolicyId (mkTxOutDatumInline healthyDatum) & addParticipationTokens healthyParticipants & modifyTxOutValue (<> foldMap txOutValue healthyUTxO) diff --git a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs index 61f92a22041..b9943eb24d2 100644 --- a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs +++ b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs @@ -525,7 +525,7 @@ addDatum datum scriptData = TxOutDatumNone -> error "unexpected datum none" TxOutDatumHash _ha -> error "hash only, expected full datum" TxOutDatumInline _sd -> error "not useful for inline datums" - TxOutDatumInTx sd -> + TxOutSupplementalDatum sd -> case scriptData of TxBodyNoScriptData -> error "TxBodyNoScriptData unexpected" TxBodyScriptData (Ledger.TxDats dats) redeemers -> @@ -540,8 +540,8 @@ modifyInlineDatum fn txOut = error "Unexpected empty head datum" (TxOutDatumHash _ha) -> error "Unexpected hash-only datum" - (TxOutDatumInTx _sd) -> - error "Unexpected in-tx datum" + (TxOutSupplementalDatum _sd) -> + error "Unexpected supplemental datum" (TxOutDatumInline sd) -> case fromScriptData sd of Just st -> @@ -568,7 +568,7 @@ ensureDatums outs scriptData = where ensureDatum txOut sd = case txOutDatum txOut of - d@(TxOutDatumInTx _) -> addDatum d sd + d@(TxOutSupplementalDatum _) -> addDatum d sd _ -> sd -- | Alter a transaction's redeemers map given some mapping function. From cb52ead1c83937371df4fc31bd89a858e4739e18 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 13:37:47 +0000 Subject: [PATCH 2/3] cardano-api: 10.3 --- hydra-cardano-api/hydra-cardano-api.cabal | 2 +- hydra-cardano-api/src/Hydra/Cardano/Api.hs | 9 ++- .../src/Hydra/Cardano/Api/Pretty.hs | 4 +- .../src/Hydra/Cardano/Api/Value.hs | 9 --- .../src/Hydra/Cardano/Api/Witness.hs | 2 +- hydra-node/src/Hydra/Chain/CardanoClient.hs | 2 +- hydra-node/src/Hydra/Chain/Direct/Tx.hs | 2 +- .../src/Hydra/Plutus/Extras.hs | 3 +- hydra-tx/hydra-tx.cabal | 1 + hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs | 16 +++--- hydra-tx/test/Hydra/Tx/Contract/FanOut.hs | 6 +- hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs | 56 ++++++++----------- 12 files changed, 44 insertions(+), 68 deletions(-) diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index a5142c13e79..3be78a635d8 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -78,7 +78,7 @@ library , aeson >=2 , base >=4.16 , bytestring - , cardano-api ^>=10.2 + , cardano-api ^>=10.3 , cardano-binary , cardano-crypto-class , cardano-ledger-allegra diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api.hs b/hydra-cardano-api/src/Hydra/Cardano/Api.hs index 63b5eeca079..090d7442219 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api.hs @@ -200,7 +200,7 @@ pattern ShelleyAddressInAnyEra <- type BalancedTxBody = Cardano.Api.BalancedTxBody Era {-# COMPLETE BalancedTxBody #-} -pattern BalancedTxBody :: TxBodyContent BuildTx -> UnsignedTx Era -> TxOut CtxTx -> Coin -> BalancedTxBody +pattern BalancedTxBody :: TxBodyContent BuildTx -> TxBody -> TxOut CtxTx -> Coin -> BalancedTxBody pattern BalancedTxBody{balancedTxBodyContent, balancedTxBody, balancedTxChangeOutput, balancedTxFee} <- Cardano.Api.BalancedTxBody balancedTxBodyContent balancedTxBody balancedTxChangeOutput balancedTxFee where @@ -578,11 +578,10 @@ pattern TxMintValueNone <- Cardano.Api.TxMintNone pattern TxMintValue :: - Value -> - BuildTxWith buidl (Map PolicyId (ScriptWitness WitCtxMint)) -> + Map PolicyId [(AssetName, Quantity, BuildTxWith buidl (ScriptWitness WitCtxMint))] -> TxMintValue buidl -pattern TxMintValue{txMintValueInEra, txMintValueScriptWitnesses} <- - Cardano.Api.TxMintValue _ txMintValueInEra txMintValueScriptWitnesses +pattern TxMintValue{txMintValueInEra} <- + Cardano.Api.TxMintValue _ txMintValueInEra where TxMintValue = Cardano.Api.TxMintValue maryBasedEra diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs index 492a479f581..80074c52186 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs @@ -104,9 +104,7 @@ renderTxWithUTxO utxo (Tx body _wits) = ] mintLines = - [ "== MINT/BURN\n" <> case txMintValue content of - Api.TxMintValueNone -> "[]" - Api.TxMintValue val _ -> prettyValue 0 val + [ "== MINT/BURN\n" <> prettyValue 0 (txMintValueToValue $ txMintValue content) ] prettyValue n = diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs index 92427c32e70..8e219346f5e 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs @@ -48,15 +48,6 @@ minUTxOValue pparams (TxOut addr val dat ref) = valueSize :: Value -> Int valueSize = length . toList --- | Access minted assets of a transaction, as an ordered association list. -txMintAssets :: Tx era -> [(AssetId, Quantity)] -txMintAssets = - asList . txMintValue . getTxBodyContent . getTxBody - where - asList = \case - TxMintNone -> [] - TxMintValue _ val _ -> toList val - -- * Type Conversions -- | Convert a cardano-ledger 'Value' into a cardano-api 'Value'. diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Witness.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Witness.hs index 9e3b75fd217..dda9e9e35c5 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Witness.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Witness.hs @@ -38,7 +38,7 @@ mkScriptReference txIn _script datum redeemer = PlutusScriptWitness (scriptLanguageInEra @lang @era) (plutusScriptVersion @lang) - (PReferenceScript txIn Nothing) + (PReferenceScript txIn) datum redeemer (ExecutionUnits 0 0) diff --git a/hydra-node/src/Hydra/Chain/CardanoClient.hs b/hydra-node/src/Hydra/Chain/CardanoClient.hs index cfa91d40f25..fd724190dde 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -88,7 +88,7 @@ buildTransaction networkId socket changeAddress utxoToSpend collateral outs = do eraHistory <- queryEraHistory networkId socket QueryTip stakePools <- queryStakePools networkId socket QueryTip pure $ - second ((\(UnsignedTx unsignedTx) -> fromLedgerTx unsignedTx) . balancedTxBody) $ + second (flip Tx [] . balancedTxBody) $ makeTransactionBodyAutoBalance shelleyBasedEra systemStart diff --git a/hydra-node/src/Hydra/Chain/Direct/Tx.hs b/hydra-node/src/Hydra/Chain/Direct/Tx.hs index c8881fdf5a8..b1bdc9c29ed 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -188,7 +188,7 @@ observeInitTx tx = do mintedTokenNames pid = [ assetName - | (AssetId policyId assetName, q) <- txMintAssets tx + | (AssetId policyId assetName, q) <- toList $ txMintValueToValue $ txMintValue $ getTxBodyContent $ getTxBody tx , q == 1 -- NOTE: Only consider unique tokens , policyId == pid , assetName /= hydraHeadV1AssetName diff --git a/hydra-plutus-extras/src/Hydra/Plutus/Extras.hs b/hydra-plutus-extras/src/Hydra/Plutus/Extras.hs index bf0b4de8ddf..29105297447 100644 --- a/hydra-plutus-extras/src/Hydra/Plutus/Extras.hs +++ b/hydra-plutus-extras/src/Hydra/Plutus/Extras.hs @@ -10,6 +10,7 @@ import Hydra.Prelude import Hydra.Plutus.Extras.Time import Cardano.Api ( + IsPlutusScriptLanguage, PlutusScriptVersion, SerialiseAsRawBytes (serialiseToRawBytes), hashScript, @@ -77,7 +78,7 @@ wrapMintingPolicy f c = -- | Compute the on-chain 'ScriptHash' for a given serialised plutus script. Use -- this to refer to another validator script. -scriptValidatorHash :: PlutusScriptVersion lang -> SerialisedScript -> ScriptHash +scriptValidatorHash :: IsPlutusScriptLanguage lang => PlutusScriptVersion lang -> SerialisedScript -> ScriptHash scriptValidatorHash version = ScriptHash . toBuiltin diff --git a/hydra-tx/hydra-tx.cabal b/hydra-tx/hydra-tx.cabal index 641825fc61a..0c06a10f29c 100644 --- a/hydra-tx/hydra-tx.cabal +++ b/hydra-tx/hydra-tx.cabal @@ -119,6 +119,7 @@ library testlib build-depends: , base , bytestring + , cardano-api:internal , cardano-crypto-class , cardano-ledger-alonzo , cardano-ledger-api diff --git a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs index 255f2e11056..8b6c340fc97 100644 --- a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs +++ b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs @@ -117,20 +117,18 @@ addExtraRequiredSigners vks tx = -- | Mint tokens with given plutus minting script and redeemer. mintTokens :: ToScriptData redeemer => PlutusScript -> redeemer -> [(AssetName, Quantity)] -> TxBodyContent BuildTx -> TxBodyContent BuildTx mintTokens script redeemer assets tx = - tx{txMintValue = TxMintValue mintedTokens' mintedWitnesses'} + tx{txMintValue = TxMintValue mintedTokens'} where - (mintedTokens, mintedWitnesses) = + mintedTokens = case txMintValue tx of - TxMintValueNone -> - (mempty, mempty) - TxMintValue t (BuildTxWith m) -> - (t, m) + TxMintValueNone -> mempty + TxMintValue t -> t mintedTokens' = - mintedTokens <> fromList (fmap (first (AssetId policyId)) assets) + Map.union mintedTokens newTokens - mintedWitnesses' = - BuildTxWith $ mintedWitnesses <> Map.singleton policyId mintingWitness + newTokens = + Map.fromList [(policyId, fmap (\(x, y) -> (x, y, BuildTxWith mintingWitness)) assets)] mintingWitness = mkScriptWitness script NoScriptDatumForMint (toScriptData redeemer) diff --git a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs index b201da5e71a..0551ec9dc88 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs @@ -148,8 +148,8 @@ genFanoutMutation (tx, _utxo) = ] where burntTokens = - case txMintValue $ txBodyContent $ txBody tx of - TxMintValueNone -> error "expected minted value" - TxMintValue v _ -> toList v + case toList . txMintValueToValue . txMintValue $ txBodyContent $ txBody tx of + [] -> error "expected minted value" + v -> v genSlotBefore (SlotNo slot) = SlotNo <$> choose (0, slot) diff --git a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs index b9943eb24d2..562c7ee6daa 100644 --- a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs +++ b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs @@ -130,6 +130,7 @@ module Test.Hydra.Tx.Mutation where import Hydra.Cardano.Api +import Cardano.Api.Plutus (DebugPlutusFailure (..)) import Cardano.Api.UTxO qualified as UTxO import Cardano.Ledger.Alonzo.Scripts qualified as Ledger import Cardano.Ledger.Alonzo.TxWits qualified as Ledger @@ -213,7 +214,7 @@ propTransactionFailsPhase2 mExpectedError (tx, lookupUTxO) = where matchesErrorMessage :: Text -> ScriptExecutionError -> Bool matchesErrorMessage errMsg = \case - ScriptErrorEvaluationFailed _ errList -> errMsg `elem` errList + ScriptErrorEvaluationFailed (DebugPlutusFailure{dpfExecutionLogs}) -> errMsg `elem` dpfExecutionLogs _otherScriptExecutionError -> False -- * Mutations @@ -667,50 +668,37 @@ alterTxOuts fn tx = -- | A 'Mutation' that changes the minted/burnt quantity of all tokens to a -- non-zero value different than the given one. changeMintedValueQuantityFrom :: Tx -> Integer -> Gen Mutation -changeMintedValueQuantityFrom tx exclude = - ChangeMintedValue - <$> case mintedValue of - TxMintValueNone -> - pure mempty - TxMintValue v _ -> do - someQuantity <- fromInteger <$> arbitrary `suchThat` (/= exclude) `suchThat` (/= 0) - pure . fromList $ map (second $ const someQuantity) $ toList v +changeMintedValueQuantityFrom tx exclude = do + someQuantity <- fromInteger <$> arbitrary `suchThat` (/= exclude) `suchThat` (/= 0) + pure $ ChangeMintedValue $ fromList $ map (second $ const someQuantity) $ toList mintedValue where - mintedValue = txMintValue $ txBodyContent $ txBody tx + mintedValue = txMintValueToValue $ txMintValue $ txBodyContent $ txBody tx -- | A 'Mutation' that changes the minted/burned quantity of tokens like this: -- - when no value is being minted/burned -> add a value -- - when tx is minting or burning values -> add more values on top of that changeMintedTokens :: Tx -> Value -> Gen Mutation changeMintedTokens tx mintValue = - ChangeMintedValue - <$> case mintedValue of - TxMintValueNone -> - pure mintValue - TxMintValue v _ -> - pure $ v <> mintValue + pure $ ChangeMintedValue $ mintedValue <> mintValue where - mintedValue = txMintValue $ txBodyContent $ txBody tx + mintedValue = txMintValueToValue $ txMintValue $ txBodyContent $ txBody tx -- | A `Mutation` that adds an `Arbitrary` participation token with some quantity. -- As usual the quantity can be positive for minting, or negative for burning. addPTWithQuantity :: Tx -> Quantity -> Gen Mutation addPTWithQuantity tx quantity = - ChangeMintedValue <$> do - case mintedValue of - TxMintValue v _ -> do - -- NOTE: We do not expect Ada or any other assets to be minted, so - -- we can take the policy id from the head - case Prelude.head $ toList v of - (AdaAssetId, _) -> error "unexpected mint of Ada" - (AssetId pid _an, _) -> do - -- Some arbitrary token name, which could correspond to a pub key hash - pkh <- arbitrary - pure $ v <> fromList [(AssetId pid pkh, quantity)] - TxMintValueNone -> - pure mempty + ChangeMintedValue + <$> + -- NOTE: We do not expect Ada or any other assets to be minted, so + -- we can take the policy id from the head + case Prelude.head $ toList mintedValue of + (AdaAssetId, _) -> error "unexpected mint of Ada" + (AssetId pid _an, _) -> do + -- Some arbitrary token name, which could correspond to a pub key hash + pkh <- arbitrary + pure $ mintedValue <> fromList [(AssetId pid pkh, quantity)] where - mintedValue = txMintValue $ txBodyContent $ txBody tx + mintedValue = txMintValueToValue $ txMintValue $ txBodyContent $ txBody tx -- | Replace first given 'PolicyId' with the second argument in the whole 'TxOut' value. replacePolicyIdWith :: PolicyId -> PolicyId -> TxOut a -> TxOut a @@ -941,9 +929,9 @@ replaceContesters contesters = \case removePTFromMintedValue :: TxOut CtxUTxO -> Tx -> Value removePTFromMintedValue output tx = - case txMintValue $ txBodyContent $ txBody tx of - TxMintValueNone -> error "expected minted value" - TxMintValue v _ -> fromList $ filter (not . isPT) $ toList v + case toList $ txMintValueToValue $ txMintValue $ txBodyContent $ txBody tx of + [] -> error "expected minted value" + v -> fromList $ filter (not . isPT) v where outValue = txOutValue output assetNames = From 9329c741ebf3ff4d9c166158d5b0fc47d380ac06 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 15:21:51 +0000 Subject: [PATCH 3/3] cardano-api: 10.4 --- hydra-cardano-api/hydra-cardano-api.cabal | 2 +- hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index 3be78a635d8..9584706cce8 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -78,7 +78,7 @@ library , aeson >=2 , base >=4.16 , bytestring - , cardano-api ^>=10.3 + , cardano-api ^>=10.4 , cardano-binary , cardano-crypto-class , cardano-ledger-allegra diff --git a/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs b/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs index 562c4db5c06..d5642e66706 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Contest/Healthy.hs @@ -157,7 +157,7 @@ healthyClosedHeadTxOut = mkHeadOutput testNetworkId testPolicyId headTxOutDatum & addParticipationTokens healthyParticipants where - headTxOutDatum = toCtxUTxOTxOut (mkTxOutDatumInline healthyClosedState) + headTxOutDatum = mkTxOutDatumInline healthyClosedState healthyOnChainContestationPeriod :: OnChain.ContestationPeriod healthyOnChainContestationPeriod = OnChain.contestationPeriodFromDiffTime $ fromInteger healthyContestationPeriodSeconds