Skip to content

Commit

Permalink
Fix remaining deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Oct 16, 2024
1 parent ffef737 commit 69e18bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/base/lib/Convex/PlutusLedger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-deprecations #-} -- see https://github.com/j-mueller/sc-tools/issues/213
{-| Translating between cardano-api/cardano-ledger and plutus representations
-}
module Convex.PlutusLedger(
Expand Down Expand Up @@ -76,6 +75,7 @@ import Data.ByteString.Short (fromShort)
import qualified Data.ByteString.Short as Short
import Data.Functor ((<&>))
import Data.Time.Clock.POSIX (POSIXTime)
import GHC.IsList (IsList (fromList, toList))
import PlutusLedgerApi.Common (SerialisedScript)
import qualified PlutusLedgerApi.V1 as PV1
import qualified PlutusLedgerApi.V1.Scripts as P
Expand Down Expand Up @@ -221,7 +221,7 @@ unTransTxOutValue value = C.TxOutValueShelleyBased C.ShelleyBasedEraConway . C.t

unTransValue :: PV1.Value -> Either C.SerialiseAsRawBytesError C.Value
unTransValue =
fmap C.valueFromList . traverse toSingleton . Value.flattenValue
fmap fromList . traverse toSingleton . Value.flattenValue
where
toSingleton (cs, tn, q) =
unTransAssetId (Value.assetClass cs tn) <&> (, C.Quantity q)
Expand All @@ -231,7 +231,7 @@ transValue =
let t (assetId, C.Quantity quantity) =
let Value.AssetClass (sym, tn) = transAssetId assetId
in (sym, Map.singleton tn quantity)
in PV1.Value . Map.safeFromList . fmap t . C.valueToList
in PV1.Value . Map.safeFromList . fmap t . toList

unTransPlutusScript
:: C.SerialiseAsRawBytes plutusScript
Expand Down
20 changes: 10 additions & 10 deletions src/coin-selection/lib/Convex/CoinSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-deprecations #-} -- see https://github.com/j-mueller/sc-tools/issues/213
{-| Building cardano transactions from tx bodies
-}
module Convex.CoinSelection(
Expand Down Expand Up @@ -105,6 +104,7 @@ import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.Generics (Generic)
import GHC.IsList (IsList (fromList, toList))

type ERA = ConwayEra

Expand Down Expand Up @@ -221,7 +221,7 @@ balanceTransactionBody
TrailingChange -> txb & appendTxOut change

txbody0 <-
balancingError . first C.TxBodyError $ C.createAndValidateTransactionBody C.shelleyBasedEra $ csiTxBody & addChangeOutput changeOutputSmall
balancingError . first C.TxBodyError $ C.createTransactionBody C.shelleyBasedEra $ csiTxBody & addChangeOutput changeOutputSmall

exUnitsMap <- balancingError . first C.TxBodyErrorValidityInterval $
C.evaluateTransactionExecutionUnits C.cardanoEra
Expand All @@ -242,13 +242,13 @@ balanceTransactionBody
let txbodycontent1' = txbodycontent1 & set L.txFee (Coin (2^(32 :: Integer) - 1)) & over L.txOuts (|> changeOutputLarge)

-- append output instead of prepending
txbody1 <- balancingError . first C.TxBodyError $ C.createAndValidateTransactionBody C.shelleyBasedEra txbodycontent1'
txbody1 <- balancingError . first C.TxBodyError $ C.createTransactionBody C.shelleyBasedEra txbodycontent1'

let !t_fee = C.calculateMinTxFee C.shelleyBasedEra (C.unLedgerProtocolParameters protocolParams) csiUtxo txbody1 numWits
traceWith tracer Txfee{fee = C.lovelaceToQuantity t_fee}

let txbodycontent2 = txbodycontent1 & set L.txFee t_fee & appendTxOut csiChangeLatestEraOutput
txbody2 <- balancingError . first C.TxBodyError $ C.createAndValidateTransactionBody C.shelleyBasedEra txbodycontent2
txbody2 <- balancingError . first C.TxBodyError $ C.createTransactionBody C.shelleyBasedEra txbodycontent2

let unregPoolStakeBalance = C.maryEraOnwardsConstraints @era C.maryBasedEra unregBalance protocolParams txbodycontent2

Expand Down Expand Up @@ -669,7 +669,7 @@ addOwnInput builder allUtxos =
let availableUTxOs =
List.sortOn
( length
. (\(C.InAnyCardanoEra _ (C.TxOut _ txOutValue _ _)) -> C.valueToList (C.txOutValueToValue txOutValue))
. (\(C.InAnyCardanoEra _ (C.TxOut _ txOutValue _ _)) -> toList (C.txOutValueToValue txOutValue))
. fst
. snd
)
Expand Down Expand Up @@ -739,7 +739,7 @@ balancePositive
-> m (TxBuilder era, C.TxOut C.CtxTx era)
balancePositive dbg poolIds ledgerPPs utxo_ returnUTxO0 walletUtxo collateralUTxOs txBuilder0 = inMary @era $ do
let txBodyContent0 = BuildTx.buildTx txBuilder0
txb <- either (throwError . bodyError) pure (C.createAndValidateTransactionBody C.shelleyBasedEra txBodyContent0)
txb <- either (throwError . bodyError) pure (C.createTransactionBody C.shelleyBasedEra txBodyContent0)
let bal = C.evaluateTransactionBalance C.shelleyBasedEra (C.unLedgerProtocolParameters ledgerPPs) poolIds mempty mempty utxo_ txb & view L._TxOutValue
available = Utxos.removeUtxos (spentTxIns txBodyContent0) walletUtxo

Expand Down Expand Up @@ -779,12 +779,12 @@ addInputsForAssets dbg txBal availableUtxo collateralUtxo txBuilder =
return (txBuilder, mempty)
| otherwise -> do
let missingAssets = fmap (second abs) $ fst $ splitValue txBal
traceWith dbg (MissingAssets $ C.valueFromList missingAssets)
traceWith dbg (MissingAssets $ fromList missingAssets)
case Wallet.selectMixedInputsCovering availableUtxo missingAssets of
Nothing ->
let total = availableUtxo <> collateralUtxo in
case Wallet.selectMixedInputsCovering total missingAssets of
Nothing -> throwError (NotEnoughMixedOutputsFor (C.valueFromList missingAssets) (Utxos.totalBalance total) txBal)
Nothing -> throwError (NotEnoughMixedOutputsFor (fromList missingAssets) (Utxos.totalBalance total) txBal)
Just (total_, ins) -> pure (txBuilder <> BuildTx.liftTxBodyEndo (over L.txIns (<> fmap spendPubKeyTxIn ins)), total_)
Just (total, ins) -> pure (txBuilder <> BuildTx.liftTxBodyEndo (over L.txIns (<> fmap spendPubKeyTxIn ins)), total)

Expand All @@ -802,7 +802,7 @@ addOutputForNonAdaAssets ::
-- ^ The balance of the transaction
(C.TxOut C.CtxTx era, C.Quantity)
-- ^ The modified change output and the lovelace portion of the change output's value. If no output was added then the amount will be 0.
addOutputForNonAdaAssets pparams returnUTxO (C.valueFromList . snd . splitValue -> positives)
addOutputForNonAdaAssets pparams returnUTxO (fromList . snd . splitValue -> positives)
| isNothing (C.valueToLovelace positives) =
let (vlWithoutAda :: C.Value) = positives & set (L._Value . at C.AdaAssetId) Nothing
output =
Expand All @@ -815,7 +815,7 @@ splitValue :: C.Value -> ([(C.AssetId, C.Quantity)], [(C.AssetId, C.Quantity)])
splitValue =
let p (_, q) = q < 0
f (_, q) = q /= 0
in List.partition p . List.filter f . C.valueToList
in List.partition p . List.filter f . toList

{-| Take the tx body and produce a 'CSInputs' value for coin selection,
using the @MonadBlockchain@ effect to query any missing UTxO information.
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/lib/Convex/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-deprecations #-} -- see https://github.com/j-mueller/sc-tools/issues/213
{-| Primitive wallet
-}
module Convex.Wallet(
Expand Down Expand Up @@ -47,6 +46,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.IsList (IsList (toList))


newtype Wallet = Wallet { getWallet :: SigningKey PaymentKey }
Expand Down Expand Up @@ -153,7 +153,7 @@ selectMixedInputsCovering UtxoSet{_utxos} xs =
all (\(assetId, quantity) -> C.selectAsset candidateVl assetId >= quantity) xs
requiredAssets = foldMap (\(a, _) -> Set.singleton a) xs
relevantValue (txIn, C.InAnyCardanoEra _ (C.TxOut _ (C.txOutValueToValue -> value) _ _)) =
let providedAssets = foldMap (Set.singleton . fst) (C.valueToList value)
let providedAssets = foldMap (Set.singleton . fst) (toList value)
in if Set.null (Set.intersection requiredAssets providedAssets)
then Nothing
else Just (value, txIn)
Expand Down

0 comments on commit 69e18bf

Please sign in to comment.