From f9feeef3b988d952f41bcd08ed38e3877127b1fd Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Thu, 7 Oct 2021 20:03:04 +0200 Subject: [PATCH] do not use collaterals and clean the code hlint --- lib/core/src/Cardano/Wallet.hs | 16 +++++++--------- lib/core/src/Cardano/Wallet/Api/Server.hs | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/core/src/Cardano/Wallet.hs b/lib/core/src/Cardano/Wallet.hs index 7afcfcd509a..9f7c2de3045 100644 --- a/lib/core/src/Cardano/Wallet.hs +++ b/lib/core/src/Cardano/Wallet.hs @@ -1668,16 +1668,15 @@ constructTxMeta -> WalletId -> TransactionCtx -> [(TxIn, Coin)] - -> [(TxIn, Coin)] -> [TxOut] -> ExceptT ErrSubmitPayment IO TxMeta -constructTxMeta ctx wid txCtx colls inps outs = db & \DBLayer{..} -> do +constructTxMeta ctx wid txCtx inps outs = db & \DBLayer{..} -> do mapExceptT atomically $ do cp <- withExceptT ErrSubmitPaymentNoSuchWallet $ withNoSuchWallet wid $ readCheckpoint wid liftIO $ - mkTxMetaWithoutSel (currentTip cp) (getState cp) txCtx colls inps outs + mkTxMetaWithoutSel (currentTip cp) (getState cp) txCtx inps outs where db = ctx ^. dbLayer @IO @s @k @@ -1687,22 +1686,21 @@ mkTxMetaWithoutSel -> s -> TransactionCtx -> [(TxIn, Coin)] - -> [(TxIn, Coin)] -> [TxOut] -> IO TxMeta -mkTxMetaWithoutSel blockHeader wState txCtx colls inps outs = +mkTxMetaWithoutSel blockHeader wState txCtx inps outs = let - amtOuts = sumCoins $ mapMaybe (flip ourCoin wState) outs + amtOuts = sumCoins $ mapMaybe (`ourCoin` wState) outs amtInps - = sumCoins (map snd colls ++ map snd inps ) -- here we need to remove overlapping txins between collateral and normal inputs + = sumCoins (map snd inps) & case txWithdrawal txCtx of w@WithdrawalSelf{} -> addCoin (withdrawalToCoin w) WithdrawalExternal{} -> Prelude.id NoWithdrawal -> Prelude.id in return TxMeta { status = Pending - , direction = if amtInps > amtOuts then Outgoing else Incoming + , direction = Outgoing , slotNo = blockHeader ^. #slotNo , blockHeight = blockHeader ^. #blockHeight , amount = Coin.distance amtInps amtOuts @@ -1737,7 +1735,7 @@ mkTxMeta ti' blockHeader wState txCtx sel = amtOuts = sumCoins $ (txOutCoin <$> view #change sel) ++ - mapMaybe (flip ourCoin wState) (view #outputs sel) + mapMaybe (`ourCoin` wState) (view #outputs sel) amtInps = sumCoins (txOutCoin . snd <$> view #inputs sel) diff --git a/lib/core/src/Cardano/Wallet/Api/Server.hs b/lib/core/src/Cardano/Wallet/Api/Server.hs index ad2e29fcd32..5475cc4084f 100644 --- a/lib/core/src/Cardano/Wallet/Api/Server.hs +++ b/lib/core/src/Cardano/Wallet/Api/Server.hs @@ -2369,7 +2369,7 @@ submitTransaction -> Handler ApiTxId submitTransaction ctx (ApiT wid) (ApiT sealedTx) = do ttl <- liftIO $ W.getTxExpiry ti Nothing - let (Tx txId _ colls inps outs wdrlMap _ _) = tx + let (Tx txId _ _ inps outs wdrlMap _ _) = tx _ <- withWorkerCtx ctx wid liftE liftE $ \wrk -> do (acct, _, _) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid @@ -2381,7 +2381,7 @@ submitTransaction ctx (ApiT wid) (ApiT sealedTx) = do { txTimeToLive = ttl , txWithdrawal = wdrl } - txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx colls inps outs + txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx inps outs liftHandler $ W.submitTx @_ @s @k wrk wid (tx, txMeta, sealedTx) return $ ApiTxId (ApiT txId)