Skip to content

Commit

Permalink
Validate balances are positive
Browse files Browse the repository at this point in the history
  • Loading branch information
nau committed Oct 17, 2019
1 parent 657adcd commit cd1a651
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions marlowe/src/Language/Marlowe3/Semantics.hs
Expand Up @@ -719,6 +719,13 @@ validatePayments pendingTx txOutPayments = let
in all checkValidPayment listOfPayments


{-|
Check that all accounts have positive balance.
-}
validateBalances :: State -> Bool
validateBalances State{..} = all (\(_, balance) -> balance > 0) (Map.toList accounts)


{-|
Marlowe Interpreter ValidatorScript generator.
-}
Expand All @@ -740,6 +747,9 @@ mkValidator creator MarloweData{..} inputs pendingTx@PendingTx{..} = let
Interval (LowerBound (Finite l) True) (UpperBound (Finite h) True) -> (l, h)
_ -> traceErrorH "Tx valid slot must have lower bound and upper bounds"

positiveBalances = if validateBalances marloweState then True
else traceErrorH "Invalid contract state. There exists an account with non positive balance"

validSignatures = let
requiredSignatures = getSignatures inputs
in checkSignatures pendingTx requiredSignatures
Expand All @@ -756,6 +766,7 @@ mkValidator creator MarloweData{..} inputs pendingTx@PendingTx{..} = let
deposit = scriptInAmount - inputBalance

preconditionsOk = checkCreator
&& positiveBalances
&& validSignatures
&& balancesOk

Expand Down

0 comments on commit cd1a651

Please sign in to comment.