Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch authored Oct 30, 2024
2 parents 6dd1201 + 357ed03 commit 46fe933
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 226 deletions.
21 changes: 10 additions & 11 deletions hydra-node/src/Hydra/Chain/Direct/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Hydra.Cardano.Api (
getTxId,
isScriptTxOut,
modifyTxOutValue,
negateValue,
networkIdToNetwork,
selectAsset,
selectLovelace,
Expand Down Expand Up @@ -535,7 +536,7 @@ increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTx
data DecrementTxError
= InvalidHeadIdInDecrement {headId :: HeadId}
| CannotFindHeadOutputInDecrement
| SnapshotMissingDecrementUTxO
| DecrementValueNegative
| SnapshotDecrementUTxOIsNull
deriving stock (Show)

Expand All @@ -553,19 +554,17 @@ decrement ::
decrement ctx spendableUTxO headId headParameters decrementingSnapshot = do
pid <- headIdToPolicyId headId ?> InvalidHeadIdInDecrement{headId}
let utxoOfThisHead' = utxoOfThisHead pid spendableUTxO
headUTxO <- UTxO.find (isScriptTxOut headScript) utxoOfThisHead' ?> CannotFindHeadOutputInDecrement
case utxoToDecommit of
Nothing ->
Left SnapshotMissingDecrementUTxO
Just decrementUTxO
| null decrementUTxO ->
Left SnapshotDecrementUTxOIsNull
_ ->
Right $ decrementTx scriptRegistry ownVerificationKey headId headParameters headUTxO sn sigs
headUTxO@(_, headOut) <- UTxO.find (isScriptTxOut headScript) utxoOfThisHead' ?> CannotFindHeadOutputInDecrement
let balance = txOutValue headOut <> negateValue decommitValue
when (isNegative balance) $
Left DecrementValueNegative
Right $ decrementTx scriptRegistry ownVerificationKey headId headParameters headUTxO sn sigs
where
headScript = fromPlutusScript @PlutusScriptV2 Head.validatorScript

Snapshot{utxoToDecommit} = sn
decommitValue = foldMap txOutValue $ fromMaybe mempty $ utxoToDecommit sn

isNegative = any ((< 0) . snd) . IsList.toList

(sn, sigs) =
case decrementingSnapshot of
Expand Down
Loading

0 comments on commit 46fe933

Please sign in to comment.