From da572c08f73ba04f0f98f455ecb4e0d5c684d16b Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Mon, 9 Dec 2024 16:50:09 +0000 Subject: [PATCH] Add TxMintValue modifier functions --- cardano-api/internal/Cardano/Api/Tx/Body.hs | 28 +++++++++++++++++++++ cardano-api/src/Cardano/Api.hs | 3 +++ 2 files changed, 31 insertions(+) diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 03443e391d..952a7b7449 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -66,6 +66,9 @@ module Cardano.Api.Tx.Body , setTxProposalProcedures , setTxVotingProcedures , setTxMintValue + , modTxMintValue + , addTxMintValue + , subtractTxMintValue , setTxScriptValidity , setTxCurrentTreasuryValue , setTxTreasuryDonation @@ -1592,6 +1595,31 @@ setTxUpdateProposal v txBodyContent = txBodyContent{txUpdateProposal = v} setTxMintValue :: TxMintValue build era -> TxBodyContent build era -> TxBodyContent build era setTxMintValue v txBodyContent = txBodyContent{txMintValue = v} +modTxMintValue + :: (TxMintValue build era -> TxMintValue build era) + -> TxBodyContent build era + -> TxBodyContent build era +modTxMintValue f tx = tx{txMintValue = f (txMintValue tx)} + +addTxMintValue + :: IsMaryBasedEra era + => Map PolicyId [(AssetName, Quantity, BuildTxWith build (ScriptWitness WitCtxMint era))] + -> TxBodyContent build era + -> TxBodyContent build era +addTxMintValue assets = + modTxMintValue + ( \case + TxMintNone -> TxMintValue maryBasedEra assets + TxMintValue era t -> TxMintValue era (t <> assets) + ) + +subtractTxMintValue + :: IsMaryBasedEra era + => Map PolicyId [(AssetName, Quantity, BuildTxWith build (ScriptWitness WitCtxMint era))] + -> TxBodyContent build era + -> TxBodyContent build era +subtractTxMintValue assets = addTxMintValue (fmap (fmap (\(x, y, z) -> (x, negate y, z))) assets) + setTxScriptValidity :: TxScriptValidity era -> TxBodyContent build era -> TxBodyContent build era setTxScriptValidity v txBodyContent = txBodyContent{txScriptValidity = v} diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 4c28183f30..45459c7a40 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -329,6 +329,9 @@ module Cardano.Api , setTxCertificates , setTxUpdateProposal , setTxMintValue + , modTxMintValue + , addTxMintValue + , subtractTxMintValue , setTxScriptValidity , setTxProposalProcedures , setTxVotingProcedures