@@ -80,7 +80,6 @@ import Hydra.Chain.Direct.Tx (
80
80
NotAnInit (.. ),
81
81
OpenThreadOutput (.. ),
82
82
UTxOHash (UTxOHash ),
83
- UTxOWithScript ,
84
83
abortTx ,
85
84
closeTx ,
86
85
collectComTx ,
@@ -241,8 +240,8 @@ allVerificationKeys ChainContext{peerVerificationKeys, ownVerificationKey} =
241
240
242
241
data InitialState = InitialState
243
242
{ initialThreadOutput :: InitialThreadOutput
244
- , initialInitials :: [UTxOWithScript ]
245
- , initialCommits :: [UTxOWithScript ]
243
+ , initialInitials :: [( TxIn , TxOut CtxUTxO ) ]
244
+ , initialCommits :: [( TxIn , TxOut CtxUTxO ) ]
246
245
, headId :: HeadId
247
246
, seedTxIn :: TxIn
248
247
}
@@ -253,10 +252,8 @@ instance HasKnownUTxO InitialState where
253
252
getKnownUTxO st =
254
253
UTxO $
255
254
Map. fromList $
256
- take2Of3 initialThreadUTxO : (take2Of3 <$> ( initialInitials <> initialCommits))
255
+ initialThreadUTxO : initialCommits <> initialInitials
257
256
where
258
- take2Of3 (a, b, _c) = (a, b)
259
-
260
257
InitialState
261
258
{ initialThreadOutput = InitialThreadOutput {initialThreadUTxO}
262
259
, initialInitials
@@ -274,10 +271,10 @@ data OpenState = OpenState
274
271
275
272
instance HasKnownUTxO OpenState where
276
273
getKnownUTxO st =
277
- UTxO. singleton (i, o)
274
+ UTxO. singleton openThreadUTxO
278
275
where
279
276
OpenState
280
- { openThreadOutput = OpenThreadOutput {openThreadUTxO = (i, o, _) }
277
+ { openThreadOutput = OpenThreadOutput {openThreadUTxO}
281
278
} = st
282
279
283
280
data ClosedState = ClosedState
@@ -290,10 +287,10 @@ data ClosedState = ClosedState
290
287
291
288
instance HasKnownUTxO ClosedState where
292
289
getKnownUTxO st =
293
- UTxO. singleton (i, o)
290
+ UTxO. singleton closedThreadUTxO
294
291
where
295
292
ClosedState
296
- { closedThreadOutput = ClosedThreadOutput {closedThreadUTxO = (i, o, _) }
293
+ { closedThreadOutput = ClosedThreadOutput {closedThreadUTxO}
297
294
} = st
298
295
299
296
-- * Constructing transactions
@@ -354,7 +351,7 @@ ownInitial ChainContext{ownVerificationKey} st@InitialState{initialInitials} =
354
351
foldl' go Nothing initialInitials
355
352
where
356
353
go (Just x) _ = Just x
357
- go Nothing (i, out, _ ) = do
354
+ go Nothing (i, out) = do
358
355
let vkh = verificationKeyHash ownVerificationKey
359
356
guard $ hasMatchingPT st vkh (txOutValue out)
360
357
pure (i, out, vkh)
@@ -403,10 +400,10 @@ abort ::
403
400
UTxO ->
404
401
Tx
405
402
abort ctx st committedUTxO = do
406
- let InitialThreadOutput {initialThreadUTxO = (i, o, dat )} = initialThreadOutput
407
- initials = Map. fromList $ map tripleToPair initialInitials
408
- commits = Map. fromList $ map tripleToPair initialCommits
409
- in case abortTx committedUTxO scriptRegistry ownVerificationKey (i, o, dat ) headTokenScript initials commits of
403
+ let InitialThreadOutput {initialThreadUTxO = (i, o)} = initialThreadOutput
404
+ initials = Map. fromList initialInitials
405
+ commits = Map. fromList initialCommits
406
+ in case abortTx committedUTxO scriptRegistry ownVerificationKey (i, o) headTokenScript initials commits of
410
407
Left OverlappingInputs ->
411
408
-- FIXME: This is a "should not happen" error. We should try to fix
412
409
-- the arguments of abortTx to make it impossible of having
@@ -426,16 +423,14 @@ abort ctx st committedUTxO = do
426
423
, seedTxIn
427
424
} = st
428
425
429
- tripleToPair (a, b, c) = (a, (b, c))
430
-
431
426
-- | Construct a collect transaction based on the 'InitialState'. This will know
432
427
-- collect all the committed outputs.
433
428
collect ::
434
429
ChainContext ->
435
430
InitialState ->
436
431
Tx
437
432
collect ctx st = do
438
- let commits = Map. fromList $ fmap tripleToPair initialCommits
433
+ let commits = Map. fromList initialCommits
439
434
in collectComTx networkId scriptRegistry ownVerificationKey initialThreadOutput commits headId
440
435
where
441
436
ChainContext {networkId, ownVerificationKey, scriptRegistry} = ctx
@@ -446,8 +441,6 @@ collect ctx st = do
446
441
, headId
447
442
} = st
448
443
449
- tripleToPair (a, b, c) = (a, (b, c))
450
-
451
444
-- | Construct a close transaction based on the 'OpenState' and a confirmed
452
445
-- snapshot.
453
446
-- - 'SlotNo' parameter will be used as the 'Tx' lower bound.
@@ -519,15 +512,15 @@ fanout ::
519
512
SlotNo ->
520
513
Tx
521
514
fanout ctx st utxo deadlineSlotNo = do
522
- fanoutTx scriptRegistry utxo (i, o, dat) deadlineSlotNo headTokenScript
515
+ fanoutTx scriptRegistry utxo closedThreadUTxO deadlineSlotNo headTokenScript
523
516
where
524
517
headTokenScript = mkHeadTokenScript seedTxIn
525
518
526
519
ChainContext {scriptRegistry} = ctx
527
520
528
521
ClosedState {closedThreadOutput, seedTxIn} = st
529
522
530
- ClosedThreadOutput {closedThreadUTxO = (i, o, dat) } = closedThreadOutput
523
+ ClosedThreadOutput {closedThreadUTxO} = closedThreadOutput
531
524
532
525
-- * Observing Transitions
533
526
@@ -617,7 +610,7 @@ observeCommit ctx st tx = do
617
610
{ initialInitials =
618
611
-- NOTE: A commit tx has been observed and thus we can
619
612
-- remove all it's inputs from our tracked initials
620
- filter ((`notElem` txIns' tx) . fst3 ) initialInitials
613
+ filter ((`notElem` txIns' tx) . fst ) initialInitials
621
614
, initialCommits =
622
615
commitOutput : initialCommits
623
616
}
@@ -631,8 +624,6 @@ observeCommit ctx st tx = do
631
624
, headId
632
625
} = st
633
626
634
- fst3 (a, _b, _c) = a
635
-
636
627
-- | Observe an collect transition using a 'InitialState' and 'observeCollectComTx'.
637
628
-- This function checks the head id and ignores if not relevant.
638
629
observeCollect ::
0 commit comments