Skip to content

Commit 302bc39

Browse files
committed
tmp
1 parent 205b35f commit 302bc39

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Data.Kind (Type)
4848
import Data.List qualified as List
4949
import Data.Map (Map)
5050
import Data.Map qualified as Map
51-
import Data.Maybe (fromMaybe, mapMaybe)
51+
import Data.Maybe (fromMaybe, isJust, mapMaybe)
5252
import Data.Set qualified as Set
5353
import Data.Text (Text)
5454
import Data.Text qualified as Text
@@ -322,6 +322,12 @@ getAdaChange utxos = lovelaceValue . getChange utxos
322322
getNonAdaChange :: Map TxOutRef TxOut -> Tx -> Value
323323
getNonAdaChange utxos = Ledger.noAdaValue . getChange utxos
324324

325+
hasDatum :: TxOut -> Bool
326+
hasDatum = isJust . txOutDatumHash
327+
328+
hasNoDatum :: TxOut -> Bool
329+
hasNoDatum = not . hasDatum
330+
325331
balanceTxIns ::
326332
forall (w :: Type) (effs :: [Type -> Type]).
327333
Member (PABEffect w) effs =>
@@ -377,8 +383,9 @@ handleNonAdaChange balanceCfg changeAddr utxos tx = runEitherT $ do
377383
( \txout ->
378384
Tx.txOutAddress txout == changeAddr
379385
&& not (justLovelace $ Tx.txOutValue txout)
386+
&& hasNoDatum txout
380387
)
381-
else (\txout -> Tx.txOutAddress txout == changeAddr)
388+
else (\txout -> Tx.txOutAddress txout == changeAddr && hasNoDatum txout)
382389

383390
newOutput :: TxOut
384391
newOutput =
@@ -415,15 +422,19 @@ addAdaChange balanceCfg changeAddr change tx
415422
{ txOutputs =
416423
List.reverse $
417424
modifyFirst
418-
(\txout -> Tx.txOutAddress txout == changeAddr && justLovelace (txOutValue txout))
425+
( \txout ->
426+
Tx.txOutAddress txout == changeAddr
427+
&& justLovelace (txOutValue txout)
428+
&& hasNoDatum txout
429+
)
419430
(fmap $ addValueToTxOut $ Ada.lovelaceValueOf change)
420431
(List.reverse $ txOutputs tx)
421432
}
422433
| otherwise =
423434
tx
424435
{ txOutputs =
425436
modifyFirst
426-
((== changeAddr) . Tx.txOutAddress)
437+
(\txout -> Tx.txOutAddress txout == changeAddr && hasNoDatum txout)
427438
(fmap $ addValueToTxOut $ Ada.lovelaceValueOf change)
428439
(txOutputs tx)
429440
}

0 commit comments

Comments
 (0)