|
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
|
@@ -89,3 +101,19 @@ fromList = UTxO . Map.fromList
|
89 | 101 | -- | Convert to a list of key/value pairs.
|
90 | 102 | toList :: UTxO era -> [(TxIn, TxOut CtxUTxO era)]
|
91 | 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