{-# LANGUAGE OverloadedRecordDot #-}
{-# OPTIONS_GHC -Wno-ambiguous-fields #-}
module Hydra.HeadLogic.IncrementalWorkflowSpec (spec) where
import Data.Map.Strict qualified as Map
import Hydra.API.ServerOutput (DecommitInvalidReason (..))
import Hydra.Agda.OffChainReference qualified as Agda
import Hydra.HeadLogic.Interpreter qualified as Interpreter
import Hydra.HeadLogic.Rules.Client.Recover qualified as Recover
import Hydra.HeadLogic.Rules.Network.ReqDec qualified as ReqDec
import Hydra.HeadLogic.Trace qualified as Trace
import Hydra.HeadLogic.Workflow qualified as Workflow
import Hydra.Ledger (Ledger (..), ValidationError (..))
import Hydra.Ledger.Simple (SimpleTx (..), simpleLedger)
import Hydra.Network.Message (Message (..))
import Hydra.Node.HeadLogic (
CoordinatedHeadState (
confirmedSnapshot,
currentDepositTxId,
decommitTx,
localUTxO,
seenSnapshot
),
Effect (NetworkEffect, OnChainEffect),
LogicError (RequireFailed),
OpenState (coordinatedHeadState),
Outcome (Continue, Error, Wait),
RequirementFailure (
NoMatchingDeposit,
RecoverBlockedByFinalizedCommit
),
SeenSnapshot (NoSeenSnapshot, RequestedSnapshot),
StateChanged (
DecommitInvalid,
DecommitRecorded,
decommitInvalidReason
),
WaitReason (WaitOnNotApplicableDecommitTx, WaitOnUnresolvedCommit),
ruleEnvironment,
)
import Hydra.Node.HeadLogic.Configuration qualified as Configuration
import Hydra.Node.State (Deposit (..), DepositStatus (..), NodeState (..), initialChainTime)
import Hydra.Prelude
import Hydra.Tx.Accumulator qualified as Accumulator
import Hydra.Tx.Crypto (aggregateInOrder, sign)
import Hydra.Tx.Snapshot (ConfirmedSnapshot (ConfirmedSnapshot), Snapshot (..))
import Test.Hydra.HeadLogic.DecommitDependency qualified as DecommitDependency
import Test.Hydra.HeadLogic.Interpreter (testInterpreterConfig)
import Test.Hydra.HeadLogic.Scenario qualified as Scenario
import Test.Hydra.HeadLogic.State ()
import Test.Hydra.Ledger.Simple (utxoRef)
import Test.Hydra.Node.State ()
import Test.Hydra.Prelude (
Spec,
it,
shouldBe,
shouldSatisfy,
)
import Test.Hydra.Tx.Fixture (alice, aliceSk, bob, bobSk, carol, carolSk, testHeadId)
spec :: Spec
spec :: Spec
spec = do
String -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"confirms the dependent decommit while preserving every reservation" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
Either Text ()
DecommitDependency.decommitDependencyRegression Either Text () -> (Either Text () -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` Either Text () -> Bool
forall a b. Either a b -> Bool
isRight
String -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"an authorised decommit takes precedence over a stale selected deposit" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$ do
let base :: OpenState SimpleTx
base = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
Scenario.initialNode
c :: CoordinatedHeadState SimpleTx
c = OpenState SimpleTx
base.coordinatedHeadState
tx :: SimpleTx
tx = SimpleTx
Scenario.transactionOne
utxo :: UTxOType SimpleTx
utxo = SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
3
accumulator :: HydraAccumulator
accumulator = forall tx. IsTx tx => UTxOType tx -> HydraAccumulator
Accumulator.buildFromUTxO @SimpleTx Set SimpleTxOut
UTxOType SimpleTx
utxo
snapshot :: Snapshot SimpleTx
snapshot = Snapshot SimpleTx
Scenario.initialSnapshot{number = 1, utxo, accumulator, appliedAccumulator = accumulator, utxoToDecommit = Just tx.txOutputs}
signatures :: MultiSignature (Snapshot SimpleTx)
signatures = Map Party (Signature (Snapshot SimpleTx))
-> [Party] -> MultiSignature (Snapshot SimpleTx)
forall k a. Ord k => Map k (Signature a) -> [k] -> MultiSignature a
aggregateInOrder ([(Party, Signature (Snapshot SimpleTx))]
-> Map Party (Signature (Snapshot SimpleTx))
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Party
alice, Secret (SigningKey HydraKey)
-> Snapshot SimpleTx -> Signature (Snapshot SimpleTx)
forall a.
SignableRepresentation a =>
Secret (SigningKey HydraKey) -> a -> Signature a
sign Secret (SigningKey HydraKey)
aliceSk Snapshot SimpleTx
snapshot), (Party
bob, Secret (SigningKey HydraKey)
-> Snapshot SimpleTx -> Signature (Snapshot SimpleTx)
forall a.
SignableRepresentation a =>
Secret (SigningKey HydraKey) -> a -> Signature a
sign Secret (SigningKey HydraKey)
bobSk Snapshot SimpleTx
snapshot), (Party
carol, Secret (SigningKey HydraKey)
-> Snapshot SimpleTx -> Signature (Snapshot SimpleTx)
forall a.
SignableRepresentation a =>
Secret (SigningKey HydraKey) -> a -> Signature a
sign Secret (SigningKey HydraKey)
carolSk Snapshot SimpleTx
snapshot)]) [Party]
Scenario.scenarioParties
st :: OpenState SimpleTx
st = OpenState SimpleTx
base{coordinatedHeadState = c{localUTxO = utxo, confirmedSnapshot = ConfirmedSnapshot snapshot signatures, decommitTx = Just tx, currentDepositTxId = Just 7}}
pending :: Map SimpleId (Deposit SimpleTx)
pending = SimpleId -> Deposit SimpleTx -> Map SimpleId (Deposit SimpleTx)
forall k a. k -> a -> Map k a
Map.singleton SimpleId
7 (DepositStatus -> Deposit SimpleTx
deposit DepositStatus
Active)
receive :: Outcome SimpleTx
receive =
InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig Environment
env Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$
Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqDecTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqDecTopology ()
ReqDec.workflow
ReqDec.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment Environment
env
, $sel:ttl:Args :: TTL
ttl = TTL
1
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
Scenario.initialNode.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
st
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
Scenario.transactionTwo
}
Outcome SimpleTx
receive Outcome SimpleTx -> Outcome SimpleTx -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` WaitReason SimpleTx -> [StateChanged SimpleTx] -> Outcome SimpleTx
forall tx. WaitReason tx -> [StateChanged tx] -> Outcome tx
Wait (DecommitInvalidReason SimpleTx -> WaitReason SimpleTx
forall tx. DecommitInvalidReason tx -> WaitReason tx
WaitOnNotApplicableDecommitTx (DecommitInvalidReason SimpleTx -> WaitReason SimpleTx)
-> DecommitInvalidReason SimpleTx -> WaitReason SimpleTx
forall a b. (a -> b) -> a -> b
$ TxIdType SimpleTx -> DecommitInvalidReason SimpleTx
forall tx. TxIdType tx -> DecommitInvalidReason tx
DecommitAlreadyInFlight SimpleId
TxIdType SimpleTx
1) []
String -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"ReqDec with confirmed inputs agrees with bounded Agda outcomes and guard priority" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
[(Bool, Bool, Bool, Bool, TTL, Bool, Int)]
-> ((Bool, Bool, Bool, Bool, TTL, Bool, Int) -> Expectation)
-> Expectation
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Bool
commit, Bool
existing, Bool
applies, Bool
outputs, TTL
ttl, Bool
inFlight, Int
actor) | Bool
commit <- [Bool
False, Bool
True], Bool
existing <- [Bool
False, Bool
True], Bool
applies <- [Bool
False, Bool
True], Bool
outputs <- [Bool
False, Bool
True], TTL
ttl <- [TTL
0, TTL
1], Bool
inFlight <- [Bool
False, Bool
True], Int
actor <- [Int
0, Int
1, Int
2]] (((Bool, Bool, Bool, Bool, TTL, Bool, Int) -> Expectation)
-> Expectation)
-> ((Bool, Bool, Bool, Bool, TTL, Bool, Int) -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$ \(Bool
commit, Bool
existing, Bool
applies, Bool
outputs, TTL
ttl, Bool
inFlight, Int
actor) -> do
let base :: OpenState SimpleTx
base = NodeState SimpleTx -> OpenState SimpleTx
Scenario.openState NodeState SimpleTx
Scenario.initialNode
c :: CoordinatedHeadState SimpleTx
c = OpenState SimpleTx
base.coordinatedHeadState
pending :: Map SimpleId (Deposit SimpleTx)
pending = if Bool
commit then SimpleId -> Deposit SimpleTx -> Map SimpleId (Deposit SimpleTx)
forall k a. k -> a -> Map k a
Map.singleton SimpleId
7 (DepositStatus -> Deposit SimpleTx
deposit DepositStatus
Active) else Map SimpleId (Deposit SimpleTx)
forall a. Monoid a => a
mempty
st :: OpenState SimpleTx
st = OpenState SimpleTx
base{coordinatedHeadState = c{currentDepositTxId = if commit then Just 7 else Nothing, decommitTx = if existing then Just Scenario.transactionTwo else Nothing, seenSnapshot = if inFlight then RequestedSnapshot 0 1 else NoSeenSnapshot}}
tx :: SimpleTx
tx = if Bool
outputs then SimpleTx
Scenario.transactionOne else SimpleTx
Scenario.transactionOne{txOutputs = mempty}
ledger :: Ledger SimpleTx
ledger = (ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx
forall tx.
(ChainSlot
-> UTxOType tx
-> [tx]
-> Either (tx, ValidationError) (UTxOType tx))
-> Ledger tx
Ledger ((ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx)
-> (ChainSlot
-> UTxOType SimpleTx
-> [SimpleTx]
-> Either (SimpleTx, ValidationError) (UTxOType SimpleTx))
-> Ledger SimpleTx
forall a b. (a -> b) -> a -> b
$ \ChainSlot
slot UTxOType SimpleTx
utxo [SimpleTx]
txs ->
if ChainSlot
slot ChainSlot -> ChainSlot -> Bool
forall a. Eq a => a -> a -> Bool
/= ChainSlot
0 Bool -> Bool -> Bool
|| Set SimpleTxOut
UTxOType SimpleTx
utxo Set SimpleTxOut -> Set SimpleTxOut -> Bool
forall a. Eq a => a -> a -> Bool
/= CoordinatedHeadState SimpleTx
c.localUTxO Bool -> Bool -> Bool
|| [SimpleTx]
txs [SimpleTx] -> [SimpleTx] -> Bool
forall a. Eq a => a -> a -> Bool
/= [SimpleTx
tx]
then Text -> Either (SimpleTx, ValidationError) (Set SimpleTxOut)
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"ReqDec changes the ledger query arguments"
else if Bool
applies then Set SimpleTxOut
-> Either (SimpleTx, ValidationError) (Set SimpleTxOut)
forall a b. b -> Either a b
Right Set SimpleTxOut
UTxOType SimpleTx
utxo else (SimpleTx, ValidationError)
-> Either (SimpleTx, ValidationError) (Set SimpleTxOut)
forall a b. a -> Either a b
Left (SimpleTx
tx, ValidationError
controlledFailure)
environment :: Environment
environment = Int -> Environment
Scenario.environment Int
actor
program :: Program SimpleTx ()
program =
Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqDecTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqDecTopology ()
ReqDec.workflow
ReqDec.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
ruleEnvironment Environment
environment
, $sel:ttl:Args :: TTL
ttl = TTL
ttl
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
Scenario.initialNode.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
st
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
tx
}
(Outcome SimpleTx
outcome, [TraceStep]
observations) = InterpreterConfig SimpleTx
-> Program SimpleTx () -> (Outcome SimpleTx, [TraceStep])
forall tx.
InterpreterConfig tx -> Program tx () -> (Outcome tx, [TraceStep])
Interpreter.traceProgram (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
ledger) Program SimpleTx ()
program
expected :: HsReqDecOutcome
expected = Bool
-> Bool
-> Bool
-> Bool
-> SimpleId
-> Bool
-> SimpleId
-> SimpleId
-> SimpleId
-> HsReqDecOutcome
Agda.reqDecOutcomeRef Bool
commit Bool
existing Bool
applies Bool
outputs (TTL -> SimpleId
forall a. Integral a => a -> SimpleId
toInteger TTL
ttl) Bool
inFlight SimpleId
2 SimpleId
1 (Int -> SimpleId
forall a. Integral a => a -> SimpleId
toInteger Int
actor)
Outcome SimpleTx -> HsReqDecOutcome
projectDecommit Outcome SimpleTx
outcome HsReqDecOutcome -> HsReqDecOutcome -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` HsReqDecOutcome
expected
Outcome SimpleTx
outcome
Outcome SimpleTx -> Outcome SimpleTx -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram
(Environment -> Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx.
IsTx tx =>
Environment -> Ledger tx -> InterpreterConfig tx
Configuration.interpreterConfig Environment
environment Ledger SimpleTx
ledger)
( Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall {vertex} tx (topology :: Topology vertex) result.
Workflow tx topology result -> Program tx result
Workflow.run (Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ())
-> Workflow SimpleTx ReqDecTopology () -> Program SimpleTx ()
forall a b. (a -> b) -> a -> b
$
Args SimpleTx -> Workflow SimpleTx ReqDecTopology ()
forall tx.
IsChainState tx =>
Args tx -> Workflow tx ReqDecTopology ()
ReqDec.workflow
ReqDec.Args
{ $sel:env:Args :: RuleEnvironment
env = Environment -> RuleEnvironment
Configuration.ruleEnvironment Environment
environment
, $sel:ttl:Args :: TTL
ttl = TTL
ttl
, $sel:chainPointTime:Args :: ChainPointTime
chainPointTime = NodeState SimpleTx
Scenario.initialNode.chainPointTime
, $sel:pendingDeposits:Args :: PendingDeposits SimpleTx
pendingDeposits = Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending
, $sel:openState:Args :: OpenState SimpleTx
openState = OpenState SimpleTx
st
, $sel:transaction:Args :: SimpleTx
transaction = SimpleTx
tx
}
)
[()] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [() | Trace.LedgerApplied{} <- [TraceStep]
observations] Int -> Int -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` if Bool
commit Bool -> Bool -> Bool
|| Bool
existing then Int
0 else Int
1
String -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"Recover preserves missing/blocked/post outcomes across status and slot" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
[(Bool, Bool, DepositStatus, ChainSlot)]
-> ((Bool, Bool, DepositStatus, ChainSlot) -> Expectation)
-> Expectation
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Bool
registered, Bool
blocked, DepositStatus
status, ChainSlot
slot) | Bool
registered <- [Bool
False, Bool
True], Bool
blocked <- [Bool
False, Bool
True], DepositStatus
status <- [DepositStatus
Inactive, DepositStatus
Active, DepositStatus
Expired], ChainSlot
slot <- [ChainSlot
0, ChainSlot
100]] (((Bool, Bool, DepositStatus, ChainSlot) -> Expectation)
-> Expectation)
-> ((Bool, Bool, DepositStatus, ChainSlot) -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$ \(Bool
registered, Bool
blocked, DepositStatus
status, ChainSlot
slot) -> do
let pending :: Map SimpleId (Deposit SimpleTx)
pending = if Bool
registered then SimpleId -> Deposit SimpleTx -> Map SimpleId (Deposit SimpleTx)
forall k a. k -> a -> Map k a
Map.singleton SimpleId
7 (DepositStatus -> Deposit SimpleTx
deposit DepositStatus
status) else Map SimpleId (Deposit SimpleTx)
forall a. Monoid a => a
mempty
finalized :: Maybe SimpleId
finalized = if Bool
blocked then SimpleId -> Maybe SimpleId
forall a. a -> Maybe a
Just SimpleId
7 else Maybe SimpleId
forall a. Maybe a
Nothing
result :: Outcome SimpleTx
result = InterpreterConfig SimpleTx
-> Program SimpleTx () -> Outcome SimpleTx
forall tx. InterpreterConfig tx -> Program tx () -> Outcome tx
Interpreter.runProgram (Ledger SimpleTx -> InterpreterConfig SimpleTx
forall tx. IsTx tx => Ledger tx -> InterpreterConfig tx
testInterpreterConfig Ledger SimpleTx
simpleLedger) (Program SimpleTx () -> Outcome SimpleTx)
-> Program SimpleTx () -> Outcome SimpleTx
forall a b. (a -> b) -> a -> b
$ ChainSlot
-> PendingDeposits SimpleTx
-> Maybe (TxIdType SimpleTx)
-> TxIdType SimpleTx
-> Program SimpleTx ()
forall tx.
IsTx tx =>
ChainSlot
-> PendingDeposits tx
-> Maybe (TxIdType tx)
-> TxIdType tx
-> Program tx ()
Recover.handleRecover ChainSlot
slot Map SimpleId (Deposit SimpleTx)
PendingDeposits SimpleTx
pending Maybe SimpleId
Maybe (TxIdType SimpleTx)
finalized SimpleId
TxIdType SimpleTx
7
Outcome SimpleTx -> HsRecoverOutcome
projectRecover Outcome SimpleTx
result HsRecoverOutcome -> HsRecoverOutcome -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Bool -> Bool -> HsRecoverOutcome
Agda.recoverOutcomeRef Bool
registered Bool
blocked
where
env :: Environment
env = Int -> Environment
Scenario.environment Int
0
deposit :: DepositStatus -> Deposit SimpleTx
deposit :: DepositStatus -> Deposit SimpleTx
deposit = HeadId
-> UTxOType SimpleTx
-> UTCTime
-> UTCTime
-> DepositStatus
-> Deposit SimpleTx
forall tx.
HeadId
-> UTxOType tx -> UTCTime -> UTCTime -> DepositStatus -> Deposit tx
Deposit HeadId
testHeadId (SimpleId -> UTxOType SimpleTx
utxoRef SimpleId
99) UTCTime
initialChainTime (NominalDiffTime -> UTCTime -> UTCTime
addUTCTime NominalDiffTime
3600 UTCTime
initialChainTime)
controlledFailure :: ValidationError
controlledFailure :: ValidationError
controlledFailure = Text -> ValidationError
ValidationError Text
"controlled decommit rejection"
projectDecommit :: Outcome SimpleTx -> Agda.HsReqDecOutcome
projectDecommit :: Outcome SimpleTx -> HsReqDecOutcome
projectDecommit = \case
Wait WaitOnUnresolvedCommit{} [] -> HsReqDecOutcome
Agda.ReqDecWaitCommit
Wait (WaitOnNotApplicableDecommitTx DecommitAlreadyInFlight{}) [] -> HsReqDecOutcome
Agda.ReqDecWaitExisting
Wait (WaitOnNotApplicableDecommitTx DecommitTxInvalid{ValidationError
validationError :: ValidationError
$sel:validationError:DecommitTxInvalid :: forall tx. DecommitInvalidReason tx -> ValidationError
validationError}) [] | ValidationError
validationError ValidationError -> ValidationError -> Bool
forall a. Eq a => a -> a -> Bool
== ValidationError
controlledFailure -> HsReqDecOutcome
Agda.ReqDecWaitLedger
Continue [DecommitInvalid{$sel:decommitInvalidReason:NetworkConnected :: forall tx. StateChanged tx -> DecommitInvalidReason tx
decommitInvalidReason = DepositInFlight{}}] [] -> HsReqDecOutcome
Agda.ReqDecInvalidCommit
Continue [DecommitInvalid{$sel:decommitInvalidReason:NetworkConnected :: forall tx. StateChanged tx -> DecommitInvalidReason tx
decommitInvalidReason = DecommitAlreadyInFlight{}}] [] -> HsReqDecOutcome
Agda.ReqDecInvalidExisting
Continue [DecommitInvalid{$sel:decommitInvalidReason:NetworkConnected :: forall tx. StateChanged tx -> DecommitInvalidReason tx
decommitInvalidReason = DecommitTxInvalid{ValidationError
$sel:validationError:DecommitTxInvalid :: forall tx. DecommitInvalidReason tx -> ValidationError
validationError :: ValidationError
validationError}}] []
| ValidationError
validationError ValidationError -> ValidationError -> Bool
forall a. Eq a => a -> a -> Bool
== ValidationError
controlledFailure -> HsReqDecOutcome
Agda.ReqDecInvalidLedger
| ValidationError
validationError ValidationError -> ValidationError -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> ValidationError
ValidationError Text
"decommit transaction has no outputs" -> HsReqDecOutcome
Agda.ReqDecEmptyOutputs
Continue [DecommitRecorded{}] [] -> HsReqDecOutcome
Agda.ReqDecRecorded
Continue [DecommitRecorded{}] [NetworkEffect ReqSn{}] -> HsReqDecOutcome
Agda.ReqDecRequested
Outcome SimpleTx
other -> Text -> HsReqDecOutcome
forall a t. (HasCallStack, IsText t) => t -> a
error (Text -> HsReqDecOutcome) -> Text -> HsReqDecOutcome
forall a b. (a -> b) -> a -> b
$ Text
"outside bounded ReqDec model: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Outcome SimpleTx -> Text
forall b a. (Show a, IsString b) => a -> b
show Outcome SimpleTx
other
projectRecover :: Outcome SimpleTx -> Agda.HsRecoverOutcome
projectRecover :: Outcome SimpleTx -> HsRecoverOutcome
projectRecover = \case
Error (RequireFailed RequirementFailure SimpleTx
NoMatchingDeposit) -> HsRecoverOutcome
Agda.RecoveryMissing
Error (RequireFailed RecoverBlockedByFinalizedCommit{}) -> HsRecoverOutcome
Agda.RecoveryBlocked
Continue [] [OnChainEffect{}] -> HsRecoverOutcome
Agda.RecoveryPosted
Outcome SimpleTx
other -> Text -> HsRecoverOutcome
forall a t. (HasCallStack, IsText t) => t -> a
error (Text -> HsRecoverOutcome) -> Text -> HsRecoverOutcome
forall a b. (a -> b) -> a -> b
$ Text
"outside bounded Recover model: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Outcome SimpleTx -> Text
forall b a. (Show a, IsString b) => a -> b
show Outcome SimpleTx
other