Skip to content

Commit

Permalink
Document and re-order arguments of 'decrement'
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jul 15, 2024
1 parent aa928f5 commit 09e94c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Chain/Direct/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ prepareTxToPost timeHandle wallet ctx spendableUTxO tx =
Left _ -> throwIO (FailedToConstructCollectTx @Tx)
Right collectTx -> pure collectTx
DecrementTx{headId, headParameters, snapshot, signatures} ->
case decrement ctx headId headParameters spendableUTxO snapshot signatures of
case decrement ctx spendableUTxO headId headParameters snapshot signatures of
Left _ -> throwIO (FailedToConstructDecrementTx @Tx)
Right decrementTx' -> pure decrementTx'
CloseTx{headId, headParameters, confirmedSnapshot, version, closeUTxOToDecommit} -> do
Expand Down
18 changes: 10 additions & 8 deletions hydra-node/src/Hydra/Chain/Direct/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,19 @@ data DecrementTxError
| SnapshotDecrementUTxOIsNull
deriving stock (Show)

-- | Construct a decrement transaction spending the head output in given 'UTxO',
-- and producing outputs for all pending 'utxoToDecommit' of given 'Snapshot'.
decrement ::
ChainContext ->
HeadId ->
HeadParameters ->
-- | Spendable UTxO containing head, initial and commit outputs
UTxO ->
HeadId ->
HeadParameters ->
-- | Confirmed Snapshot
Snapshot Tx ->
MultiSignature (Snapshot Tx) ->
Either DecrementTxError Tx
decrement ctx headId headParameters spendableUTxO snapshot signatures = do
decrement ctx spendableUTxO headId headParameters snapshot signatures = do
pid <- headIdToPolicyId headId ?> InvalidHeadIdInDecrement{headId}
let utxoOfThisHead' = utxoOfThisHead pid spendableUTxO
headUTxO <- UTxO.find (isScriptTxOut headScript) utxoOfThisHead' ?> CannotFindHeadOutputInDecrement
Expand Down Expand Up @@ -1044,7 +1046,7 @@ genDecrementTx numParties = do
( cctx
, maybe mempty toList (utxoToDecommit snapshot)
, stOpen
, unsafeDecrement cctx headId (ctxHeadParameters ctx) openUTxO snapshot signatures
, unsafeDecrement cctx openUTxO headId (ctxHeadParameters ctx) snapshot signatures
)

splitUTxO :: UTxO -> (UTxO, UTxO)
Expand Down Expand Up @@ -1180,15 +1182,15 @@ unsafeAbort ctx seedTxIn spendableUTxO committedUTxO =
unsafeDecrement ::
HasCallStack =>
ChainContext ->
HeadId ->
HeadParameters ->
-- | Spendable 'UTxO'
UTxO ->
HeadId ->
HeadParameters ->
Snapshot Tx ->
MultiSignature (Snapshot Tx) ->
Tx
unsafeDecrement ctx headId parameters spendableUTxO snapshot signatures =
either (error . show) id $ decrement ctx headId parameters spendableUTxO snapshot signatures
unsafeDecrement ctx spendableUTxO headId parameters snapshot signatures =
either (error . show) id $ decrement ctx spendableUTxO headId parameters snapshot signatures

unsafeClose ::
HasCallStack =>
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ produceDecrement ::
([Bool], UTxO, Snapshot Tx, MultiSignature (Snapshot Tx)) ->
([Bool], UTxO, Snapshot Tx, MultiSignature (Snapshot Tx))
produceDecrement ctx scriptRegistry headId parameters (p, spendableUTxO, snapshot, signatures) = do
case decrement ctx headId parameters spendableUTxO snapshot signatures of
case decrement ctx spendableUTxO headId parameters snapshot signatures of
Left _ -> (p <> [False], spendableUTxO, snapshot, signatures)
Right tx -> do
case utxoToDecommit snapshot of
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,9 @@ newDecrementTx actor (snapshot, signatures) = do
pure $
decrement
(actorChainContext actor)
spendableUTxO
(mkHeadId Fixture.testPolicyId)
Fixture.testHeadParameters
spendableUTxO
snapshot
signatures

Expand Down

0 comments on commit 09e94c1

Please sign in to comment.