Skip to content

Commit 7ef8a14

Browse files
committed
Implement and expose mkTxCertificates
1 parent 0ee6fe4 commit 7ef8a14

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

cardano-api/src/Cardano/Api/Experimental.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,5 @@ import Cardano.Api.Experimental.Plutus.Internal.ScriptWitness
100100
import Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
101101
import Cardano.Api.Experimental.Simple.Script
102102
import Cardano.Api.Experimental.Tx
103-
import Cardano.Api.Experimental.Tx.Internal.Compatible
104103
import Cardano.Api.Experimental.Tx.Internal.Fee
105104
import Cardano.Api.Tx.Internal.Fee (evaluateTransactionExecutionUnitsShelley)

cardano-api/src/Cardano/Api/Experimental/Tx.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ module Cardano.Api.Experimental.Tx
127127
-- * TxBodyContent
128128
, TxBodyContent (..)
129129
, defaultTxBodyContent
130+
, mkTxCertificates
130131
, setTxAuxScripts
131132
, setTxCertificates
132133
, setTxCollateral

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE RankNTypes #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
77
{-# LANGUAGE StandaloneDeriving #-}
8+
{-# LANGUAGE TupleSections #-}
89
{-# LANGUAGE TypeApplications #-}
910

1011
module Cardano.Api.Experimental.Tx.Internal.BodyContent.New
@@ -24,6 +25,7 @@ module Cardano.Api.Experimental.Tx.Internal.BodyContent.New
2425
, makeUnsignedTx
2526
, extractAllIndexedPlutusScriptWitnesses
2627
, txMintValueToValue
28+
, mkTxCertificates
2729

2830
-- * Getters and Setters
2931
, setTxAuxScripts
@@ -66,6 +68,7 @@ import Cardano.Api.Experimental.Simple.Script
6668
import Cardano.Api.Experimental.Tx.Internal.AnyWitness
6769
( AnyWitness (..)
6870
)
71+
import Cardano.Api.Experimental.Tx.Internal.Certificate.Compatible (getTxCertWitness)
6972
import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
7073
( TxScriptWitnessRequirements (..)
7174
, getTxScriptWitnessesRequirements
@@ -365,6 +368,28 @@ newtype TxCertificates era
365368
{unTxCertificates :: OMap (Exp.Certificate era) (Maybe (StakeCredential, AnyWitness era))}
366369
deriving (Show, Eq)
367370

371+
-- | Create 'TxCertificates'. Note that 'Certificate era' will be deduplicated. Only Certificates with a
372+
-- stake credential will be in the result.
373+
--
374+
-- Note that, when building a transaction in Conway era, a witness is not required for staking credential
375+
-- registration, but this is only the case during the transitional period of Conway era and only for staking
376+
-- credential registration certificates without a deposit. Future eras will require a witness for
377+
-- registration certificates, because the one without a deposit will be removed.
378+
mkTxCertificates
379+
:: forall era
380+
. Era era
381+
-> [(Exp.Certificate (LedgerEra era), AnyWitness (LedgerEra era))]
382+
-> TxCertificates (LedgerEra era)
383+
mkTxCertificates era certs = TxCertificates . OMap.fromList $ map getStakeCred certs
384+
where
385+
getStakeCred
386+
:: (Exp.Certificate (LedgerEra era), AnyWitness (LedgerEra era))
387+
-> ( Exp.Certificate (LedgerEra era)
388+
, Maybe (StakeCredential, AnyWitness (LedgerEra era))
389+
)
390+
getStakeCred (c@(Exp.Certificate cert), wit) =
391+
(c, (,wit) <$> getTxCertWitness (convert era) (obtainCommonConstraints era cert))
392+
368393
-- This is incorrect. Only scripts can witness minting!
369394
newtype TxMintValue era
370395
= TxMintValue

0 commit comments

Comments
 (0)