Skip to content

Commit

Permalink
Work on observeInitTx
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Oct 28, 2021
1 parent 1cdb2a5 commit e675adb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ runOnChainTxs party headState = fmap reverse . atomically . foldM runOnChainTx [

observeInitTx :: Party -> ValidatedTx Era -> Maybe (OnChainTx tx, OnChainHeadState)
observeInitTx party ValidatedTx{wits, body} = do
(dh, Head.Initial cp ps) <- getFirst $ foldMap (First . decodeInitDatum) datums
(dh, Head.Initial cp ps) <- getFirst $ foldMap (First . decodeHeadDatum) datumsList
let parties = map convertParty ps
let cperiod = contestationPeriodToDiffTime cp
guard $ party `elem` parties
Expand All @@ -329,24 +329,33 @@ observeInitTx party ValidatedTx{wits, body} = do
}
)
where
decodeInitDatum (dh, d) =
decodeHeadDatum (dh, d) =
(dh,) <$> fromData (getPlutusData d)

findSmOutput dh (ix, o@(TxOut _ _ dh')) =
guard (SJust dh == dh') $> (i, o)
where
i = TxIn (TxId $ SafeHash.hashAnnotated body) ix

datums =
Map.toList . unTxDats $ txdats wits
datumsList = Map.toList datums

datums = unTxDats $ txdats wits

indexedOutputs =
zip [0 ..] (toList (outputs body))

initials =
let initialOutputs = filter (isInitial . snd) indexedOutputs
txId = TxId $ SafeHash.hashAnnotated body
in undefined
in mapMaybe mkInitial initialOutputs

mkInitial (ix, txOut) =
(mkTxIn ix,) <$> decodeInitialDatum txOut

mkTxIn ix = TxIn (TxId $ SafeHash.hashAnnotated body) ix

decodeInitialDatum = \case
(TxOut _ _ (SJust dh)) -> Map.lookup dh datums >>= fromData . getPlutusData
_ -> Nothing

isInitial (TxOut addr _ _) =
addr == scriptAddr initialScript
Expand Down
1 change: 1 addition & 0 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ spec =
.&&. length initials === length cardanoKeys
_ -> property False
& counterexample ("Result: " <> show res)
& counterexample ("Tx: " <> show tx)

describe "commitTx" $ do
prop ("transaction size below limit (" <> show maxTxSize <> ")") $
Expand Down

0 comments on commit e675adb

Please sign in to comment.