Skip to content

Commit

Permalink
make sure to count user-specified outputs that are ours when construc…
Browse files Browse the repository at this point in the history
…ting tx meta
  • Loading branch information
KtorZ committed Jan 28, 2021
1 parent cca6231 commit 6afcf1d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -1366,7 +1366,7 @@ signTransaction ctx wid argChange mkRwdAcct pwd txCtx sel = db & \DBLayer{..} ->
(tx, sealedTx) <- withExceptT ErrSignPaymentMkTx $ ExceptT $ pure $
mkTransaction tl era rewardAcnt keyFrom pp txCtx sel'

(time, meta) <- liftIO $ mkTxMeta ti (currentTip cp) txCtx sel'
(time, meta) <- liftIO $ mkTxMeta ti (currentTip cp) s' txCtx sel'
return (tx, meta, time, sealedTx)
where
db = ctx ^. dbLayer @s @k
Expand Down Expand Up @@ -1400,15 +1400,19 @@ getTxExpiry ti maybeTTL = do
-- FIXME: There's a logic duplication regarding the calculation of the transaction
-- amount between right here, and the Primitive.Model (see prefilterBlocks).
mkTxMeta
:: TimeInterpreter (ExceptT PastHorizonException IO)
:: IsOurs s Address
=> TimeInterpreter (ExceptT PastHorizonException IO)
-> BlockHeader
-> s
-> TransactionCtx
-> SelectionResult TxOut
-> IO (UTCTime, TxMeta)
mkTxMeta ti' blockHeader txCtx sel =
mkTxMeta ti' blockHeader wState txCtx sel =
let
amtOuts =
sumCoins (txOutCoin <$> changeGenerated sel)
amtOuts = sumCoins $
(txOutCoin <$> NE.toList (changeGenerated sel))
++
mapMaybe ourCoins (outputsCovered sel)

amtInps
= sumCoins (txOutCoin . snd <$> (inputsSelected sel))
Expand Down Expand Up @@ -1440,6 +1444,12 @@ mkTxMeta ti' blockHeader txCtx sel =
where
ti = neverFails "mkTxMeta slots should never be ahead of the node tip" ti'

ourCoins :: TxOut -> Maybe Coin
ourCoins (TxOut addr tokens) =
case fst (isOurs addr wState) of
Just{} -> Just (TokenBundle.getCoin tokens)
Nothing -> Nothing

-- | Broadcast a (signed) transaction to the network.
submitTx
:: forall ctx s k.
Expand Down

0 comments on commit 6afcf1d

Please sign in to comment.