Skip to content

Commit

Permalink
Merge pull request #704 from locallycompact/lc/extra-modifier-functions
Browse files Browse the repository at this point in the history
Add modifier functions for TxInsCollateral, TxInsReference, TxExtraKe…
  • Loading branch information
smelc authored Dec 9, 2024
2 parents d6a956f + 1307d2a commit 76fba1c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
67 changes: 67 additions & 0 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ module Cardano.Api.Tx.Body
, setTxIns
, modTxIns
, addTxIn
, addTxIns
, setTxInsCollateral
, modTxInsCollateral
, addTxInsCollateral
, addTxInCollateral
, setTxInsReference
, modTxInsReference
, addTxInsReference
, addTxInReference
, setTxOuts
, modTxOuts
, addTxOut
, addTxOuts
, setTxTotalCollateral
, setTxReturnCollateral
, setTxFee
Expand All @@ -49,6 +57,8 @@ module Cardano.Api.Tx.Body
, setTxMetadata
, setTxAuxScripts
, setTxExtraKeyWits
, modTxExtraKeyWits
, addTxExtraKeyWits
, setTxProtocolParams
, setTxWithdrawals
, setTxCertificates
Expand Down Expand Up @@ -1464,12 +1474,49 @@ addTxIn
-> TxBodyContent build era
addTxIn txIn = modTxIns (txIn :)

addTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era
addTxIns txIns = modTxIns (<> txIns)

setTxInsCollateral :: TxInsCollateral era -> TxBodyContent build era -> TxBodyContent build era
setTxInsCollateral v txBodyContent = txBodyContent{txInsCollateral = v}

modTxInsCollateral
:: (TxInsCollateral era -> TxInsCollateral era) -> TxBodyContent build era -> TxBodyContent build era
modTxInsCollateral f txBodyContent = txBodyContent{txInsCollateral = f (txInsCollateral txBodyContent)}

addTxInsCollateral
:: IsAlonzoBasedEra era => [TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsCollateral txInsCollateral =
modTxInsCollateral
( \case
TxInsCollateralNone -> TxInsCollateral alonzoBasedEra txInsCollateral
TxInsCollateral era xs -> TxInsCollateral era (xs <> txInsCollateral)
)

addTxInCollateral
:: IsAlonzoBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInCollateral txInCollateral = addTxInsCollateral [txInCollateral]

setTxInsReference :: TxInsReference era -> TxBodyContent build era -> TxBodyContent build era
setTxInsReference v txBodyContent = txBodyContent{txInsReference = v}

modTxInsReference
:: (TxInsReference era -> TxInsReference era) -> TxBodyContent build era -> TxBodyContent build era
modTxInsReference f txBodyContent = txBodyContent{txInsReference = f (txInsReference txBodyContent)}

addTxInsReference
:: IsBabbageBasedEra era => [TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsReference txInsReference =
modTxInsReference
( \case
TxInsReferenceNone -> TxInsReference babbageBasedEra txInsReference
TxInsReference era xs -> TxInsReference era (xs <> txInsReference)
)

addTxInReference
:: IsBabbageBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInReference txInReference = addTxInsReference [txInReference]

setTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era
setTxOuts v txBodyContent = txBodyContent{txOuts = v}

Expand All @@ -1480,6 +1527,9 @@ modTxOuts f txBodyContent = txBodyContent{txOuts = f (txOuts txBodyContent)}
addTxOut :: TxOut CtxTx era -> TxBodyContent build era -> TxBodyContent build era
addTxOut txOut = modTxOuts (txOut :)

addTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era
addTxOuts txOuts = modTxOuts (<> txOuts)

setTxTotalCollateral :: TxTotalCollateral era -> TxBodyContent build era -> TxBodyContent build era
setTxTotalCollateral v txBodyContent = txBodyContent{txTotalCollateral = v}

Expand Down Expand Up @@ -1507,6 +1557,23 @@ setTxAuxScripts v txBodyContent = txBodyContent{txAuxScripts = v}
setTxExtraKeyWits :: TxExtraKeyWitnesses era -> TxBodyContent build era -> TxBodyContent build era
setTxExtraKeyWits v txBodyContent = txBodyContent{txExtraKeyWits = v}

modTxExtraKeyWits
:: (TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era)
-> TxBodyContent build era
-> TxBodyContent build era
modTxExtraKeyWits f txBodyContent = txBodyContent{txExtraKeyWits = f (txExtraKeyWits txBodyContent)}

addTxExtraKeyWits
:: IsAlonzoBasedEra era => [Hash PaymentKey] -> TxBodyContent build era -> TxBodyContent build era
addTxExtraKeyWits vks =
modTxExtraKeyWits
( \case
TxExtraKeyWitnessesNone ->
TxExtraKeyWitnesses alonzoBasedEra vks
TxExtraKeyWitnesses era vks' ->
TxExtraKeyWitnesses era (vks' <> vks)
)

setTxProtocolParams
:: BuildTxWith build (Maybe (LedgerProtocolParameters era))
-> TxBodyContent build era
Expand Down
10 changes: 10 additions & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,19 @@ module Cardano.Api
, defaultTxValidityUpperBound
, setTxIns
, modTxIns
, addTxIns
, addTxIn
, setTxInsCollateral
, modTxInsCollateral
, addTxInsCollateral
, addTxInCollateral
, setTxInsReference
, modTxInsReference
, addTxInsReference
, addTxInReference
, setTxOuts
, modTxOuts
, addTxOuts
, addTxOut
, setTxTotalCollateral
, setTxReturnCollateral
Expand All @@ -314,6 +322,8 @@ module Cardano.Api
, setTxMetadata
, setTxAuxScripts
, setTxExtraKeyWits
, modTxExtraKeyWits
, addTxExtraKeyWits
, setTxProtocolParams
, setTxWithdrawals
, setTxCertificates
Expand Down

0 comments on commit 76fba1c

Please sign in to comment.