Skip to content

Commit

Permalink
Use toWalletTokenBundle in Primitive.Tx.Features.Outputs.
Browse files Browse the repository at this point in the history
In particular, we simplify expressions of the following form:

- `fromCardanoValue . Cardano.fromMaryValue`

The above expression peforms the following two-step conversion:

- From a ledger MA value (nested map) to a cardano-api MA value (flat map)
- From a cardano-api MA value (flat map) to a wallet MA value (nested map)

The `toWalletTokenBundle` function performs this conversion in a single step.
  • Loading branch information
jonathanknowles committed Sep 13, 2023
1 parent ba21ca0 commit 205bdb4
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Tx.Outputs
( Outputs (..) )
import Cardano.Wallet.Shelley.Compatibility.Ledger
( toWalletTokenBundle )
import Cardano.Wallet.Util
( internalError )
import Data.Foldable
Expand Down Expand Up @@ -89,22 +91,19 @@ fromAllegraTxOut (SL.ShelleyTxOut addr amount) = W.TxOut

fromMaryTxOut :: SL.ShelleyTxOut StandardMary -> W.TxOut
fromMaryTxOut (SL.ShelleyTxOut addr value) =
W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)

fromAlonzoTxOut
:: Alonzo.AlonzoTxOut StandardAlonzo
-> W.TxOut
fromAlonzoTxOut (Alonzo.AlonzoTxOut addr value _) =
W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)

fromBabbageTxOut
:: Babbage.BabbageTxOut StandardBabbage
-> (W.TxOut, Maybe (AlonzoScript (Babbage.BabbageEra SL.StandardCrypto)))
fromBabbageTxOut (Babbage.BabbageTxOut addr value _datum refScript) =
( W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
( W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)
, case refScript of
SJust s -> Just s
SNothing -> Nothing
Expand All @@ -114,8 +113,7 @@ fromConwayTxOut
:: Babbage.BabbageTxOut StandardConway
-> (W.TxOut, Maybe (AlonzoScript (Conway.ConwayEra SL.StandardCrypto)))
fromConwayTxOut (Babbage.BabbageTxOut addr value _datum refScript) =
( W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
( W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)
, case refScript of
SJust s -> Just s
SNothing -> Nothing
Expand Down

0 comments on commit 205bdb4

Please sign in to comment.