Skip to content

Commit

Permalink
Preserve collected output in collectCom contract
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Jan 18, 2022
1 parent 2ff3488 commit c59d3f5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ instance Scripts.ValidatorTypes Head where
type DatumType Head = State
type RedeemerType Head = Input

-- TODO: Add state checkings as done previously by SM
{-# INLINEABLE headValidator #-}
headValidator ::
-- | Unique identifier for this particular Head
Expand All @@ -78,9 +79,8 @@ headValidator ::
headValidator _ commitAddress oldState input context =
case (oldState, input) of
(Initial{}, CollectCom{}) ->
-- TODO: check collected value is sent to own script output
-- TODO: check collected txouts are put as datum in own script output
let _collectedValue =
let collectedValue =
foldr
( \TxInInfo{txInInfoResolved} val ->
if txOutAddress txInInfoResolved == commitAddress
Expand All @@ -89,7 +89,14 @@ headValidator _ commitAddress oldState input context =
)
mempty
txInfoInputs
in True
headInputValue = maybe mempty (txOutValue . txInInfoResolved) $ findOwnInput context
in case findContinuingOutputs context of
[ix] ->
let headOutputValue = txOutValue $ txInfoOutputs !! ix
in traceIfFalse "committed value is not preserved in head" $
headOutputValue == collectedValue <> headInputValue
[] -> traceIfFalse "No continuing head output" False
_ -> traceIfFalse "More than one continuing head output" False
(Initial{}, Abort) -> True
(Open{parties}, Close{snapshotNumber, signature})
| snapshotNumber == 0 -> True
Expand Down

0 comments on commit c59d3f5

Please sign in to comment.