From 79794f92b298cf9e630b9fc05aa5de572a2a528d Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 12:13:25 +0000 Subject: [PATCH 1/6] cardano-api: 10.2 --- cabal.project | 4 +- flake.lock | 124 +++++++++--------- 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/TxOutDatum.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 | 4 +- .../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 +- .../Tx/Contract/Contest/ContestCurrent.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 +- 28 files changed, 114 insertions(+), 144 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 47602d8d6ef..49b1c91e2f2 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1731401651, - "narHash": "sha256-tXaUck9+0Ob4h6GBlbhYMI4ekW5e8biVJU5jPT/rjus=", + "lastModified": 1733408643, + "narHash": "sha256-IH5nYTjx+CYAK4zQAkOs475X+AOhP/GPgwXm5LQHsEE=", "owner": "IntersectMBO", "repo": "cardano-haskell-packages", - "rev": "82b295d6147a566c28dbcf038c54040f06f7e6b4", + "rev": "e062328804c933d296e5956c989b326ea3c69eeb", "type": "github" }, "original": { @@ -73,11 +73,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1727863681, - "narHash": "sha256-lzSItBMYcZ7Q92+u/8XFoFgwslfkUBf8RqsunrIoruQ=", + "lastModified": 1733549414, + "narHash": "sha256-zF75hFsxHxZHBxEK2fcl7+hGI3Vyde1s+n6dXX4pJaw=", "owner": "aiken-lang", "repo": "aiken", - "rev": "c7ae161a39c29656938ce1c8d4f674e387980022", + "rev": "ddc58b9a6554b2a1af4d757e0248ef1d7c6d971e", "type": "github" }, "original": { @@ -387,11 +387,11 @@ }, "crane": { "locked": { - "lastModified": 1730060262, - "narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=", + "lastModified": 1728776144, + "narHash": "sha256-fROVjMcKRoGHofDm8dY3uDUtCMwUICh/KjBFQnuBzfg=", "owner": "ipetkov", "repo": "crane", - "rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76", + "rev": "f876e3d905b922502f031aeec1a84490122254b7", "type": "github" }, "original": { @@ -613,11 +613,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1719994518, - "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", "type": "github" }, "original": { @@ -649,11 +649,11 @@ "nixpkgs-lib": "nixpkgs-lib_3" }, "locked": { - "lastModified": 1725234343, - "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { @@ -667,11 +667,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": { @@ -864,11 +864,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1731371270, - "narHash": "sha256-9hAGzHPyc6EncczyVrDrjElS6H9wwlR4j1fj4JRTigw=", + "lastModified": 1733531400, + "narHash": "sha256-rNSDbhaxeDeYHrjNOGcz1XZPl35tK+OEHL0nt3vG6YM=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "c96fd8da826bb383b7fa36cfe7d386013f070fa4", + "rev": "cd2b3f220e9ba17e7331b2d656585fe88908865d", "type": "github" }, "original": { @@ -990,11 +990,11 @@ "stackage": "stackage_2" }, "locked": { - "lastModified": 1731372695, - "narHash": "sha256-QddLLOvRtrao9Ztuk1rYSXmepxH2/blYRfuRWx/QUyM=", + "lastModified": 1733532713, + "narHash": "sha256-aSnV9U5XhxjbOxkM36PoI9RdJsAV6MNPtOMKik6KWh0=", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "54ddc77cd29c19779489d8f7fae14d70e90d8c68", + "rev": "e26f83af05a3b71e4c6408aa86f2f13701bd2e33", "type": "github" }, "original": { @@ -1029,11 +1029,11 @@ "hls": { "flake": false, "locked": { - "lastModified": 1720542277, - "narHash": "sha256-6MWZpMYB+5VDmQavRzlbItbXqYxuKvvI2F/pahgo7NE=", + "lastModified": 1733307874, + "narHash": "sha256-vIi4w5v9swzJunALrLRxwwU5ndoIG7w1mfByX+S+s9A=", "owner": "haskell", "repo": "haskell-language-server", - "rev": "d331019b3715d3fe78684b170ad1aec06a2c833d", + "rev": "25c5d82ce09431a1b53dfa1784a276a709f5e479", "type": "github" }, "original": { @@ -1494,11 +1494,11 @@ "sodium": "sodium_2" }, "locked": { - "lastModified": 1730297014, - "narHash": "sha256-n3f1iAmltKnorHWx7FrdbGIF/FmEG8SsZshS16vnpz0=", + "lastModified": 1732287300, + "narHash": "sha256-lURsE6HdJX0alscWhbzCWyLRK8GpAgKuXeIgX31Kfqg=", "owner": "input-output-hk", "repo": "iohk-nix", - "rev": "d407eedd4995e88d08e83ef75844a8a9c2e29b36", + "rev": "262cb2aec2ddd914124bab90b06fe24a1a74d02c", "type": "github" }, "original": { @@ -1854,11 +1854,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": { @@ -2110,14 +2110,14 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1719876945, - "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" } }, "nixpkgs-lib_2": { @@ -2134,14 +2134,14 @@ }, "nixpkgs-lib_3": { "locked": { - "lastModified": 1725233747, - "narHash": "sha256-Ss8QWLXdr2JCBPcYChJhz4xJm+h/xjl4G0c0XlP6a74=", + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" } }, "nixpkgs-regression": { @@ -2210,11 +2210,11 @@ }, "nixpkgsLatest": { "locked": { - "lastModified": 1721226092, - "narHash": "sha256-UBvzVpo5sXSi2S/Av+t+Q+C2mhMIw/LBEZR+d6NMjws=", + "lastModified": 1733384649, + "narHash": "sha256-K5DJ2LpPqht7K76bsxetI+YHhGGRyVteTPRQaIIKJpw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c716603a63aca44f39bef1986c13402167450e0a", + "rev": "190c31a89e5eec80dd6604d7f9e5af3802a58a13", "type": "github" }, "original": { @@ -2257,11 +2257,11 @@ }, "nixpkgs_12": { "locked": { - "lastModified": 1725816686, - "narHash": "sha256-0Kq2MkQ/sQX1rhWJ/ySBBQlBJBUK8mPMDcuDhhdBkSU=", + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "add0443ee587a0c44f22793b8c8649a0dbc3bb00", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", "type": "github" }, "original": { @@ -2287,11 +2287,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": { @@ -2524,11 +2524,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": { @@ -2563,11 +2563,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": { @@ -2663,11 +2663,11 @@ "stackage_2": { "flake": false, "locked": { - "lastModified": 1731370260, - "narHash": "sha256-DsuG/LEJduoxwK+VbKubVsCfg1WFAUaewYAUFLW0FRU=", + "lastModified": 1733443946, + "narHash": "sha256-xz8bzbXm5vE3TWdvU+/7CdRSm43D9P8XftYUSVp58Ck=", "owner": "input-output-hk", "repo": "stackage.nix", - "rev": "5b7b9fad43a035243f87f654ac5611f597ce5fc2", + "rev": "2e2aba31ade325ca2c6ab0f4564f568cac2110bd", "type": "github" }, "original": { @@ -2815,11 +2815,11 @@ ] }, "locked": { - "lastModified": 1725271838, - "narHash": "sha256-VcqxWT0O/gMaeWTTjf1r4MOyG49NaNxW4GHTO3xuThE=", + "lastModified": 1727984844, + "narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "9fb342d14b69aefdf46187f6bb80a4a0d97007cd", + "rev": "4446c7a6fc0775df028c5a3f6727945ba8400e64", "type": "github" }, "original": { diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index 4ea8d2e0929..85fe695a9ef 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.KeyWitness @@ -82,7 +81,7 @@ library , base >=4.16 , base16-bytestring , 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 3311853452b..b2c979a157d 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.KeyWitness as Extras @@ -394,7 +392,6 @@ pattern TxBodyContent :: TxValidityUpperBound -> TxMetadataInEra -> TxAuxScripts -> - BuildTxWith buidl (TxSupplementalDatums Era) -> TxExtraKeyWitnesses -> BuildTxWith buidl (Maybe (LedgerProtocolParameters Era)) -> TxWithdrawals buidl Era -> @@ -419,7 +416,6 @@ pattern TxBodyContent , txValidityUpperBound , txMetadata , txAuxScripts - , txSupplementalDatums , txExtraKeyWits , txProtocolParams , txWithdrawals @@ -444,7 +440,6 @@ pattern TxBodyContent txValidityUpperBound txMetadata txAuxScripts - txSupplementalDatums txExtraKeyWits txProtocolParams txWithdrawals @@ -639,7 +634,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 <- @@ -655,12 +650,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 53cb6ad7ca5..38e835916a9 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs @@ -137,10 +137,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 653addc62ba..04e422ab065 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs @@ -41,8 +41,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 -- | Lookup included datum of given 'TxOut'. diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/TxOutDatum.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/TxOutDatum.hs index e25f16d43a7..5164f3396ae 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/TxOutDatum.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/TxOutDatum.hs @@ -11,7 +11,7 @@ mkTxOutDatum :: a -> TxOutDatum CtxTx era mkTxOutDatum = - TxOutDatumInTx (alonzoBasedEra @era) . toScriptData + TxOutSupplementalDatum (alonzoBasedEra @era) . toScriptData -- | Construct a 'TxOutDatum' as a 'ScriptData' hash from some serialisable data. mkTxOutDatumHash :: diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs index af4bc1a2c35..2ab7edb29b6 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs @@ -8,7 +8,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) @@ -25,7 +24,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 843612101bf..b67ea5c58aa 100644 --- a/hydra-cluster/src/Hydra/Cluster/Faucet.hs +++ b/hydra-cluster/src/Hydra/Cluster/Faucet.hs @@ -57,7 +57,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 e3f1d03ed8a..6d9b2611b8c 100644 --- a/hydra-cluster/test/Test/EndToEndSpec.hs +++ b/hydra-cluster/test/Test/EndToEndSpec.hs @@ -151,7 +151,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 d362c39d673..fbf46328e4f 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -132,7 +132,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 981918c045b..83d05ce413f 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -293,7 +293,7 @@ observeCommitTx networkId utxo tx = do policyId <- fromPlutusCurrencySymbol headId pure CommitObservation - { commitOutput = (commitIn, toUTxOContext commitOut) + { commitOutput = (commitIn, toCtxUTxOTxOut commitOut) , party , committed , headId = mkHeadId policyId @@ -433,7 +433,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 cd774caeb10..936ae57e654 100644 --- a/hydra-tx/src/Hydra/Tx/Deposit.hs +++ b/hydra-tx/src/Hydra/Tx/Deposit.hs @@ -77,7 +77,7 @@ observeDepositTx :: observeDepositTx networkId tx = do -- TODO: could just use the first output and fail otherwise (TxIn depositTxId _, depositOut) <- findTxOutByAddress depositAddress 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 3385867e171..71d257c35b2 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseInitial.hs @@ -71,7 +71,7 @@ healthyCloseInitialTx = openThreadOutput 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 37dc64bae5d..3e98872ac98 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUnused.hs @@ -87,7 +87,7 @@ healthyCloseCurrentTx = healthyCloseUpperBoundPointInTime openThreadOutput - datum = toUTxOContext $ mkTxOutDatumInline healthyCurrentOpenDatum + datum = mkTxOutDatumInline healthyCurrentOpenDatum lookupUTxO = UTxO.singleton (healthyOpenHeadTxIn, healthyOpenHeadTxOut datum) @@ -309,7 +309,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 390e9ef1a48..38b12738fc1 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs @@ -133,7 +133,7 @@ healthyCloseOutdatedTx = scriptRegistry = genScriptRegistry `generateWith` 42 datum :: TxOutDatum CtxUTxO - datum = toUTxOContext (mkTxOutDatumInline healthyOutdatedOpenDatum) + datum = mkTxOutDatumInline healthyOutdatedOpenDatum openThreadOutput :: OpenThreadOutput openThreadOutput = @@ -370,7 +370,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/ContestCurrent.hs b/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestCurrent.hs index 601f7d3503f..75057a3fb93 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestCurrent.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Contest/ContestCurrent.hs @@ -181,7 +181,7 @@ healthyClosedHeadTxOut = mkHeadOutput testNetworkId testPolicyId headTxOutDatum & addParticipationTokens healthyParticipants where - headTxOutDatum = toUTxOContext (mkTxOutDatumInline healthyClosedState) + headTxOutDatum = 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 3828c20e99c..ec76f61ea69 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs @@ -52,7 +52,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 7233e63dd99..0eae898a4b6 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs @@ -75,7 +75,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 986614d1052..fbcfe716007 100644 --- a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs +++ b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs @@ -549,7 +549,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 -> @@ -564,8 +564,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 -> @@ -593,7 +593,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 b648b05e3af097ea01faf6ed41db5384a508aac8 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 13:37:47 +0000 Subject: [PATCH 2/6] 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 85fe695a9ef..8847c16fed9 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -81,7 +81,7 @@ library , base >=4.16 , base16-bytestring , 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 b2c979a157d..5820e1c64a5 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api.hs @@ -202,7 +202,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 @@ -580,11 +580,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 38e835916a9..797f89f0816 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs @@ -107,9 +107,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 2ab7edb29b6..6080aa7b480 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs @@ -49,15 +49,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 fbf46328e4f..2a6ec10222f 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -102,7 +102,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 83d05ce413f..f78578c79ab 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -228,7 +228,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 f0e842c32c1..e662e7feb57 100644 --- a/hydra-tx/hydra-tx.cabal +++ b/hydra-tx/hydra-tx.cabal @@ -121,6 +121,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 ec76f61ea69..991cf4ce618 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/FanOut.hs @@ -146,8 +146,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 fbcfe716007..f4c81b9da7f 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 @@ -702,50 +703,37 @@ headTxIn = fst . Prelude.head . filter (isHeadOutput . snd) . UTxO.pairs -- | 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 @@ -967,9 +955,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 67f14852ce7ce1fc116e5be0fb42e6f16980b0e7 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sat, 7 Dec 2024 15:21:51 +0000 Subject: [PATCH 3/6] cardano-api: 10.4 --- hydra-cardano-api/hydra-cardano-api.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index 8847c16fed9..debe20f831b 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -81,7 +81,7 @@ library , base >=4.16 , base16-bytestring , bytestring - , cardano-api ^>=10.3 + , cardano-api ^>=10.4 , cardano-binary , cardano-crypto-class , cardano-ledger-allegra From bb03544cef3092bc8efe407cd4dab6494edbc467 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sun, 8 Dec 2024 10:31:29 +0000 Subject: [PATCH 4/6] Replace emptyTxBody with defaultTxBodyContent from cardano-api --- hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 5 ++- hydra-node/src/Hydra/Ledger/Cardano.hs | 4 +- hydra-node/test/Hydra/Chain/Direct/TxSpec.hs | 4 +- hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs | 43 -------------------- hydra-tx/src/Hydra/Tx/Abort.hs | 3 +- hydra-tx/src/Hydra/Tx/Close.hs | 3 +- hydra-tx/src/Hydra/Tx/CollectCom.hs | 3 +- hydra-tx/src/Hydra/Tx/Contest.hs | 3 +- hydra-tx/src/Hydra/Tx/Decrement.hs | 3 +- hydra-tx/src/Hydra/Tx/Fanout.hs | 3 +- hydra-tx/src/Hydra/Tx/Increment.hs | 3 +- hydra-tx/src/Hydra/Tx/Init.hs | 4 +- hydra-tx/src/Hydra/Tx/Recover.hs | 3 +- 13 files changed, 17 insertions(+), 67 deletions(-) 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 7434abe338b..5b03ee33921 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 193b81ead95..f81cfe96d08 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 8b6c340fc97..42fdfa4909c 100644 --- a/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs +++ b/hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs @@ -34,49 +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 - 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 From b39d8324e840b1e337ef4d551931f60602879a12 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sun, 8 Dec 2024 10:31:29 +0000 Subject: [PATCH 5/6] Replace emptyTxBody with defaultTxBodyContent from cardano-api --- hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index 934073511eb..88488da4ff2 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -42,6 +42,7 @@ import Hydra.Cardano.Api ( Tx, TxId, UTxO, + defaultTxBodyContent, getTxBody, getTxId, getVerificationKey, From 51e24d9e15e1860ef50532fe7e00eb2ec77613ab Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Sun, 8 Dec 2024 11:58:08 +0000 Subject: [PATCH 6/6] Use upstream functions for modifying transactions --- cabal.project | 8 +++ hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 4 +- hydra-node/test/Hydra/Chain/Direct/TxSpec.hs | 8 +-- hydra-tx/src/Hydra/Ledger/Cardano/Builder.hs | 60 +------------------- hydra-tx/src/Hydra/Tx/Abort.hs | 12 ++-- hydra-tx/src/Hydra/Tx/Close.hs | 18 ++---- hydra-tx/src/Hydra/Tx/CollectCom.hs | 12 ++-- hydra-tx/src/Hydra/Tx/Contest.hs | 15 ++--- hydra-tx/src/Hydra/Tx/Decrement.hs | 12 ++-- hydra-tx/src/Hydra/Tx/Fanout.hs | 12 ++-- hydra-tx/src/Hydra/Tx/Increment.hs | 15 ++--- hydra-tx/src/Hydra/Tx/Init.hs | 6 +- hydra-tx/src/Hydra/Tx/Recover.hs | 9 +-- 13 files changed, 55 insertions(+), 136 deletions(-) diff --git a/cabal.project b/cabal.project index f4357f0bc18..f4f31e3a154 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: 01f0777722947c391047410fa3b6b76189988508 + --sha256: sha256-Z2E3R26XAPLb28s6brFsrYIJTCXBTtz04ITCZzp2r68= + subdir: + cardano-api diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index 88488da4ff2..00e989a4a5e 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 (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..df42065bcae 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 (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..94a120349d8 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,56 +33,13 @@ 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 -mintTokens script redeemer assets tx = - tx{txMintValue = TxMintValue mintedTokens'} +mintTokens script redeemer assets = addTxMintValue newTokens where - mintedTokens = - case txMintValue tx of - TxMintValueNone -> mempty - TxMintValue t -> t - - mintedTokens' = - Map.union mintedTokens newTokens - newTokens = Map.fromList [(policyId, fmap (\(x, y) -> (x, y, BuildTxWith mintingWitness)) assets)] @@ -98,13 +54,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)]