Skip to content

Commit

Permalink
Use toWalletTokenBundle in Primitive.Tx.Features.CollateralOutputs.
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 205bdb4 commit 893ece8
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import Prelude
import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromCardanoValue, fromShelleyAddress )
( fromShelleyAddress )
import Cardano.Wallet.Read.Tx.CollateralOutputs
( CollateralOutputs (..) )
import Cardano.Wallet.Shelley.Compatibility.Ledger
( toWalletTokenBundle )
import Data.Maybe.Strict
( strictMaybeToMaybe )
import Ouroboros.Consensus.Shelley.Eras
( StandardBabbage, StandardConway )

import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Ledger.Babbage as Babbage
import qualified Cardano.Ledger.Babbage.TxBody as Babbage
import qualified Cardano.Wallet.Primitive.Types.Tx.TxOut as W
Expand All @@ -40,12 +41,10 @@ fromBabbageTxOut
:: Babbage.BabbageTxOut StandardBabbage
-> W.TxOut
fromBabbageTxOut (Babbage.BabbageTxOut addr value _datum _refScript) =
W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)

fromConwayTxOut
:: Babbage.BabbageTxOut StandardConway
-> W.TxOut
fromConwayTxOut (Babbage.BabbageTxOut addr value _datum _refScript) =
W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value
W.TxOut (fromShelleyAddress addr) (toWalletTokenBundle value)

0 comments on commit 893ece8

Please sign in to comment.