Skip to content

Commit

Permalink
Add TxMintValue modifier functions
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Dec 11, 2024
1 parent 76fba1c commit 8fc8660
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ module Cardano.Api.Tx.Body
, setTxProposalProcedures
, setTxVotingProcedures
, setTxMintValue
, modTxMintValue
, addTxMintValue
, subtractTxMintValue
, setTxScriptValidity
, setTxCurrentTreasuryValue
, setTxTreasuryDonation
Expand Down Expand Up @@ -1592,6 +1595,32 @@ 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)
)

-- | Adds the negation of the provided assets and quantities to the txMintValue field of the `TxBodyContent`.
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}

Expand Down
3 changes: 3 additions & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ module Cardano.Api
, setTxCertificates
, setTxUpdateProposal
, setTxMintValue
, modTxMintValue
, addTxMintValue
, subtractTxMintValue
, setTxScriptValidity
, setTxProposalProcedures
, setTxVotingProcedures
Expand Down

0 comments on commit 8fc8660

Please sign in to comment.