Skip to content

Commit

Permalink
do not use collaterals and clean the code
Browse files Browse the repository at this point in the history
hlint
  • Loading branch information
paweljakubas committed Oct 12, 2021
1 parent ed555ea commit f9feeef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f9feeef

Please sign in to comment.