|
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 (IsShelleyBasedEra, ShelleyBasedEra, ShelleyLedgerEra) |
10 | 10 | import Cardano.Api.Internal.Eras.Core (IsCardanoEra) |
11 | | -import Cardano.Api.Internal.Tx.Body (CtxUTxO, TxOut (..)) |
| 11 | +import Cardano.Api.Internal.Tx.Body |
| 12 | + ( CtxUTxO, |
| 13 | + TxOut(..), |
| 14 | + toShelleyTxOut, |
| 15 | + fromShelleyTxIn, |
| 16 | + fromShelleyTxOut, |
| 17 | + toShelleyTxIn ) |
12 | 18 | import Cardano.Api.Internal.TxIn (TxIn (..)) |
13 | 19 |
|
14 | 20 | import Cardano.Ledger.Babbage () |
| 21 | +import Cardano.Ledger.Shelley.UTxO qualified as Ledger |
15 | 22 |
|
16 | 23 | import Data.Aeson (FromJSON (..), ToJSON (..)) |
17 | 24 | import Data.Aeson qualified as Aeson |
@@ -89,3 +96,19 @@ fromList = UTxO . Map.fromList |
89 | 96 | -- | Convert to a list of key/value pairs. |
90 | 97 | toList :: UTxO era -> [(TxIn, TxOut CtxUTxO era)] |
91 | 98 | toList (UTxO xs) = Map.toList xs |
| 99 | + |
| 100 | +-- | Convert from a `cardano-api` `UTxO` to a `cardano-ledger` UTxO. |
| 101 | +toShelleyUTxO :: ShelleyBasedEra era -> UTxO era -> Ledger.UTxO (ShelleyLedgerEra era) |
| 102 | +toShelleyUTxO sbe = |
| 103 | + Ledger.UTxO . Map.foldMapWithKey f . unUTxO |
| 104 | + where |
| 105 | + f i o = |
| 106 | + Map.singleton (toShelleyTxIn i) (toShelleyTxOut sbe o) |
| 107 | + |
| 108 | +-- | Convert from a `cardano-ledger` `UTxO` to a `cardano-api` UTxO. |
| 109 | +fromShelleyUTxO :: ShelleyBasedEra era -> Ledger.UTxO (ShelleyLedgerEra era) -> UTxO era |
| 110 | +fromShelleyUTxO sbe = |
| 111 | + UTxO . Map.foldMapWithKey f . Ledger.unUTxO |
| 112 | + where |
| 113 | + f i o = |
| 114 | + Map.singleton (fromShelleyTxIn i) (fromShelleyTxOut sbe o) |
0 commit comments