Skip to content

Commit

Permalink
Naively use tail since head output is the first one
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Feb 1, 2023
1 parent 8709255 commit 2fabbad
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Expand Up @@ -185,24 +185,20 @@ checkCollectCom ctx@ScriptContext{scriptContextTxInfo = txInfo} (contestationPer
(expectedChangeValue, collectedCommits, nTotalCommits) =
traverseInputs
(negate (txInfoAdaFee txInfo), [], 0)
(txInfoInputs txInfo)
-- we assume head output is always the first one so it is ok to use 'tail' here
(tail $ txInfoInputs txInfo)

expectedOutputDatum :: Datum
expectedOutputDatum =
let utxoHash = hashPreSerializedCommits collectedCommits
in Datum $ toBuiltinData Open{parties, utxoHash, contestationPeriod, headId = headId}

-- Collect fuel and commits from resolved inputs. Any output containing a PT
-- is treated as a commit, "our" output is the head output and all remaining
-- will be accumulated as 'fuel'.
-- is treated as a commit and all remaining will be accumulated as 'fuel'.
traverseInputs (fuel, commits, nCommits) = \case
[] ->
(fuel, commits, nCommits)
TxInInfo{txInInfoResolved} : rest
| isHeadOutput txInInfoResolved ->
traverseInputs
(fuel, commits, nCommits)
rest
| hasPT headId txInInfoResolved ->
case commitDatum txInfo txInInfoResolved of
Just commit@Commit{} ->
Expand All @@ -217,8 +213,6 @@ checkCollectCom ctx@ScriptContext{scriptContextTxInfo = txInfo} (contestationPer
traverseInputs
(fuel + txOutAdaValue txInInfoResolved, commits, nCommits)
rest

isHeadOutput txOut = txOutAddress txOut == headAddress
{-# INLINEABLE checkCollectCom #-}

-- | Try to find the commit datum in the input and
Expand Down

0 comments on commit 2fabbad

Please sign in to comment.