Skip to content

Commit b28e8e2

Browse files
authored
Merge pull request #767 from locallycompact/lc/utxo-fromtolist
Add top level fromList and toList functions in `Cardano.Api.UTxO`
2 parents 117e229 + a2be277 commit b28e8e2

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

cardano-api/src/Cardano/Api/Internal/Convenience/Query.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Cardano.Api.Internal.ProtocolParameters
3535
import Cardano.Api.Internal.Query
3636
import Cardano.Api.Internal.Query.Expr
3737
import Cardano.Api.Internal.Tx.Body
38-
import Cardano.Api.Internal.Tx.UTxO
38+
import Cardano.Api.Internal.Tx.UTxO (UTxO (..))
3939
import Cardano.Api.Internal.Utils
4040

4141
import Cardano.Ledger.Api qualified as L

cardano-api/src/Cardano/Api/Internal/Fees.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ import Cardano.Api.Internal.Query
360360
import Cardano.Api.Internal.Script
361361
import Cardano.Api.Internal.Tx.Body
362362
import Cardano.Api.Internal.Tx.Sign
363-
import Cardano.Api.Internal.Tx.UTxO
363+
import Cardano.Api.Internal.Tx.UTxO (UTxO (..))
364364
import Cardano.Api.Internal.Value
365365
import Cardano.Api.Ledger.Lens qualified as A
366366

cardano-api/src/Cardano/Api/Internal/Query.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import Cardano.Api.Internal.ProtocolParameters
7979
import Cardano.Api.Internal.Query.Types
8080
import Cardano.Api.Internal.ReexposeLedger qualified as Ledger
8181
import Cardano.Api.Internal.Tx.Body
82-
import Cardano.Api.Internal.Tx.UTxO
82+
import Cardano.Api.Internal.Tx.UTxO (UTxO (..))
8383

8484
import Cardano.Chain.Update.Validation.Interface qualified as Byron.Update
8585
import Cardano.Ledger.Api qualified as L

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import Data.Map (Map)
2121
import Data.Map qualified as Map
2222
import Data.Set (Set)
2323
import Data.Text (Text)
24-
import GHC.Exts (IsList (..))
24+
import GHC.Exts qualified as GHC
2525

2626
newtype UTxO era = UTxO {unUTxO :: Map TxIn (TxOut CtxUTxO era)}
2727
deriving stock (Eq, Show)
28-
deriving newtype (Semigroup, Monoid, IsList)
28+
deriving newtype (Semigroup, Monoid, GHC.IsList)
2929

3030
instance IsCardanoEra era => ToJSON (UTxO era) where
3131
toJSON (UTxO m) = toJSON m
@@ -36,7 +36,7 @@ instance
3636
=> FromJSON (UTxO era)
3737
where
3838
parseJSON = Aeson.withObject "UTxO" $ \hm -> do
39-
let l = toList $ KeyMap.toHashMapText hm
39+
let l = GHC.toList $ KeyMap.toHashMapText hm
4040
res <- mapM toTxIn l
4141
pure . UTxO $ Map.fromList res
4242
where
@@ -77,3 +77,11 @@ inputSet = Map.keysSet . unUTxO
7777
-- | Remove the right hand side from the left hand side.
7878
difference :: UTxO era -> UTxO era -> UTxO era
7979
difference a b = UTxO $ Map.difference (unUTxO a) (unUTxO b)
80+
81+
-- | Convert from a list of key/value pairs.
82+
fromList :: [(TxIn, TxOut CtxUTxO era)] -> UTxO era
83+
fromList = UTxO . Map.fromList
84+
85+
-- | Convert to a list of key/value pairs.
86+
toList :: UTxO era -> [(TxIn, TxOut CtxUTxO era)]
87+
toList (UTxO xs) = Map.toList xs

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Cardano.Api.Tx.UTxO
77
, UTxO.filterWithKey
88
, UTxO.inputSet
99
, UTxO.difference
10+
, UTxO.fromList
11+
, UTxO.toList
1012
)
1113
where
1214

0 commit comments

Comments
 (0)