6
6
7
7
module Cardano.Api.Internal.Tx.UTxO where
8
8
9
- import Cardano.Api.Internal.Eon.ShelleyBasedEra (IsShelleyBasedEra )
9
+ import Cardano.Api.Internal.Eon.ShelleyBasedEra
10
+ ( IsShelleyBasedEra
11
+ , ShelleyBasedEra
12
+ , ShelleyLedgerEra
13
+ )
10
14
import Cardano.Api.Internal.Eras.Core (IsCardanoEra )
11
- import Cardano.Api.Internal.Tx.Body (CtxUTxO , TxOut (.. ))
15
+ import Cardano.Api.Internal.Tx.Body
16
+ ( CtxUTxO
17
+ , TxOut (.. )
18
+ , fromShelleyTxIn
19
+ , fromShelleyTxOut
20
+ , toShelleyTxIn
21
+ , toShelleyTxOut
22
+ )
12
23
import Cardano.Api.Internal.TxIn (TxIn (.. ))
13
24
14
25
import Cardano.Ledger.Babbage ()
26
+ import Cardano.Ledger.Shelley.UTxO qualified as Ledger
15
27
16
28
import Data.Aeson (FromJSON (.. ), ToJSON (.. ))
17
29
import Data.Aeson qualified as Aeson
@@ -74,6 +86,10 @@ filterWithKey fn = UTxO . Map.filterWithKey fn . unUTxO
74
86
inputSet :: UTxO era -> Set TxIn
75
87
inputSet = Map. keysSet . unUTxO
76
88
89
+ -- | Get the UTxO output set.
90
+ txOutputs :: UTxO era -> [TxOut CtxUTxO era ]
91
+ txOutputs = Map. elems . unUTxO
92
+
77
93
-- | Remove the right hand side from the left hand side.
78
94
difference :: UTxO era -> UTxO era -> UTxO era
79
95
difference a b = UTxO $ Map. difference (unUTxO a) (unUTxO b)
@@ -85,3 +101,19 @@ fromList = UTxO . Map.fromList
85
101
-- | Convert to a list of key/value pairs.
86
102
toList :: UTxO era -> [(TxIn , TxOut CtxUTxO era )]
87
103
toList (UTxO xs) = Map. toList xs
104
+
105
+ -- | Convert from a `cardano-api` `UTxO` to a `cardano-ledger` UTxO.
106
+ toShelleyUTxO :: ShelleyBasedEra era -> UTxO era -> Ledger. UTxO (ShelleyLedgerEra era )
107
+ toShelleyUTxO sbe =
108
+ Ledger. UTxO . Map. foldMapWithKey f . unUTxO
109
+ where
110
+ f i o =
111
+ Map. singleton (toShelleyTxIn i) (toShelleyTxOut sbe o)
112
+
113
+ -- | Convert from a `cardano-ledger` `UTxO` to a `cardano-api` UTxO.
114
+ fromShelleyUTxO :: ShelleyBasedEra era -> Ledger. UTxO (ShelleyLedgerEra era ) -> UTxO era
115
+ fromShelleyUTxO sbe =
116
+ UTxO . Map. foldMapWithKey f . Ledger. unUTxO
117
+ where
118
+ f i o =
119
+ Map. singleton (fromShelleyTxIn i) (fromShelleyTxOut sbe o)
0 commit comments