Skip to content

Commit 4352023

Browse files
Add Cardano.Api.Tx.UTxO.totalValue
1 parent cf7de94 commit 4352023

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Cardano.Api.Internal.Tx.Body
2121
, toShelleyTxOut
2222
)
2323
import Cardano.Api.Internal.TxIn (TxIn (..))
24+
import Cardano.Api.Internal.Value (Value (..))
2425

2526
import Cardano.Ledger.Babbage ()
2627
import Cardano.Ledger.Shelley.UTxO qualified as Ledger
@@ -110,6 +111,10 @@ toList (UTxO xs) = Map.toList xs
110111
toMap :: UTxO era -> Map TxIn (TxOut CtxUTxO era)
111112
toMap = unUTxO
112113

114+
-- | Sum the total value of the UTxO.
115+
totalValue :: UTxO era -> Value
116+
totalValue = foldMap txOutValue . unUTxO
117+
113118
-- | Convert from a `cardano-api` `UTxO` to a `cardano-ledger` UTxO.
114119
toShelleyUTxO :: ShelleyBasedEra era -> UTxO era -> Ledger.UTxO (ShelleyLedgerEra era)
115120
toShelleyUTxO sbe =

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

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Cardano.Api.Tx.UTxO
1212
, UTxO.fromList
1313
, UTxO.toList
1414
, UTxO.toMap
15+
, UTxO.totalValue
1516
, UTxO.fromShelleyUTxO
1617
, UTxO.toShelleyUTxO
1718
)

0 commit comments

Comments
 (0)