Skip to content

Commit f1f262f

Browse files
authored
Merge pull request #832 from locallycompact/lc/utxo-toMap
Add extra functions to `Cardano.Api.Tx.UTxO`.
2 parents d47259d + 762c7a4 commit f1f262f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cardano-api/src/Cardano/Api/Internal/Tx/UTxO.hs

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ singleton i o = UTxO $ Map.singleton i o
6767
lookup :: TxIn -> UTxO era -> Maybe (TxOut CtxUTxO era)
6868
lookup k = Map.lookup k . unUTxO
6969

70+
-- | Synonym for `lookup`.
71+
resolveTxIn :: TxIn -> UTxO era -> Maybe (TxOut CtxUTxO era)
72+
resolveTxIn = Cardano.Api.Internal.Tx.UTxO.lookup
73+
7074
-- | Filter all `TxOut` that satisfy the predicate.
7175
filter :: (TxOut CtxUTxO era -> Bool) -> UTxO era -> UTxO era
7276
filter fn = UTxO . Map.filter fn . unUTxO
@@ -95,6 +99,10 @@ fromList = UTxO . Map.fromList
9599
toList :: UTxO era -> [(TxIn, TxOut CtxUTxO era)]
96100
toList (UTxO xs) = Map.toList xs
97101

102+
-- | Convert to a Map of TxIn/TxOut.
103+
toMap :: UTxO era -> Map TxIn (TxOut CtxUTxO era)
104+
toMap = unUTxO
105+
98106
-- | Convert from a `cardano-api` `UTxO` to a `cardano-ledger` UTxO.
99107
toShelleyUTxO :: ShelleyBasedEra era -> UTxO era -> Ledger.UTxO (ShelleyLedgerEra era)
100108
toShelleyUTxO sbe =

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ module Cardano.Api.Tx.UTxO
33
, UTxO.empty
44
, UTxO.singleton
55
, UTxO.lookup
6+
, UTxO.resolveTxIn
67
, UTxO.filter
78
, UTxO.filterWithKey
89
, UTxO.inputSet
910
, UTxO.txOutputs
1011
, UTxO.difference
1112
, UTxO.fromList
1213
, UTxO.toList
14+
, UTxO.toMap
1315
, UTxO.fromShelleyUTxO
1416
, UTxO.toShelleyUTxO
1517
)

0 commit comments

Comments
 (0)