Skip to content

Commit

Permalink
Stub out deposit observation code
Browse files Browse the repository at this point in the history
Signed-off-by: Sasha Bogicevic <[email protected]>
  • Loading branch information
v0d1ch authored and locallycompact committed Sep 9, 2024
1 parent 3509d60 commit 122def3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hydra-chain-observer/src/Hydra/ChainObserver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ data ChainObserverLog
| HeadInitTx {headId :: HeadId}
| HeadCommitTx {headId :: HeadId}
| HeadCollectComTx {headId :: HeadId}
| HeadDepositTx {headId :: HeadId}
| HeadDecrementTx {headId :: HeadId}
| HeadCloseTx {headId :: HeadId}
| HeadFanoutTx {headId :: HeadId}
Expand Down Expand Up @@ -203,6 +204,7 @@ chainSyncClient tracer networkId startingPoint observerHandler =
OnInitTx{headId} -> HeadInitTx{headId}
OnCommitTx{headId} -> HeadCommitTx{headId}
OnCollectComTx{headId} -> HeadCollectComTx{headId}
OnDepositTx{headId} -> HeadDepositTx{headId}
OnDecrementTx{headId} -> HeadDecrementTx{headId}
OnCloseTx{headId} -> HeadCloseTx{headId}
OnFanoutTx{headId} -> HeadFanoutTx{headId}
Expand Down
4 changes: 4 additions & 0 deletions hydra-node/src/Hydra/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ data OnChainTx tx
}
| OnAbortTx {headId :: HeadId}
| OnCollectComTx {headId :: HeadId}
| OnDepositTx
{ headId :: HeadId
, utxo :: UTxOType tx
}
| OnDecrementTx
{ headId :: HeadId
, newVersion :: SnapshotVersion
Expand Down
4 changes: 3 additions & 1 deletion hydra-node/src/Hydra/Chain/Direct/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Hydra.Chain.Direct.Tx (
InitObservation (..),
headSeedToTxIn,
observeHeadTx,
txInToHeadSeed,
txInToHeadSeed, DepositObservation (..),
)
import Hydra.Chain.Direct.Wallet (
ErrCoverFee (..),
Expand Down Expand Up @@ -329,6 +329,8 @@ convertObservation = \case
pure OnCommitTx{headId, party, committed}
CollectCom CollectComObservation{headId} ->
pure OnCollectComTx{headId}
Deposit DepositObservation{headId, utxo} ->
pure OnDepositTx{headId, utxo}
Decrement DecrementObservation{headId, newVersion, distributedOutputs} ->
pure OnDecrementTx{headId, newVersion, distributedOutputs}
Close CloseObservation{headId, snapshotNumber, threadOutput = ClosedThreadOutput{closedContestationDeadline}} ->
Expand Down
1 change: 1 addition & 0 deletions hydra-node/src/Hydra/Chain/Direct/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ data ChainTransition
| Abort
| Commit
| Collect
| Deposit
| Decrement
| Close
| Contest
Expand Down
17 changes: 17 additions & 0 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ data HeadObservation
| Abort AbortObservation
| Commit CommitObservation
| CollectCom CollectComObservation
| Deposit DepositObservation
| Decrement DecrementObservation
| Close CloseObservation
| Contest ContestObservation
Expand All @@ -120,6 +121,7 @@ observeHeadTx networkId utxo tx =
<|> Abort <$> observeAbortTx utxo tx
<|> Commit <$> observeCommitTx networkId utxo tx
<|> CollectCom <$> observeCollectComTx utxo tx
<|> Deposit <$> observeDepositTx utxo tx
<|> Decrement <$> observeDecrementTx utxo tx
<|> Close <$> observeCloseTx utxo tx
<|> Contest <$> observeContestTx utxo tx
Expand Down Expand Up @@ -348,6 +350,21 @@ observeCollectComTx utxo tx = do
Just (Head.Open Head.OpenDatum{utxoHash}) -> Just $ fromBuiltin utxoHash
_ -> Nothing

data DepositObservation = DepositObservation
{ headId :: HeadId
, utxo :: UTxO
}
deriving stock (Show, Eq, Generic)

instance Arbitrary DepositObservation where
arbitrary = genericArbitrary

observeDepositTx ::
UTxO ->
Tx ->
Maybe DepositObservation
observeDepositTx utxo tx = error "not implemented yet"

data DecrementObservation = DecrementObservation
{ headId :: HeadId
, newVersion :: SnapshotVersion
Expand Down
1 change: 1 addition & 0 deletions hydra-node/test/Hydra/Chain/Direct/HandlersSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ spec = do
OnAbortTx{} -> Transition.Abort
OnCollectComTx{} -> Transition.Collect
OnDecrementTx{} -> Transition.Decrement
OnDepositTx{} -> Transition.Deposit
OnCloseTx{} -> Transition.Close
OnContestTx{} -> Transition.Contest
OnFanoutTx{} -> Transition.Fanout
Expand Down

0 comments on commit 122def3

Please sign in to comment.