Skip to content

Commit

Permalink
Change 'executed' output to 'Maybe Bool' to indicate private exec (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Popejoy committed Jun 25, 2019
1 parent b6c5d4a commit f42a48f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/Pact/Eval.hs
Expand Up @@ -696,23 +696,22 @@ applyPact i app (TList steps _ _) PactStep {..} = do
t -> evalError (_tInfo t) "expected step"

-- determine if step is skipped (for private execution)
(executing,private) <- traverse reduce (_sEntity step) >>= \stepEntity -> case stepEntity of
Nothing -> return (True,False)
Just (TLitString se) -> view eeEntity >>= \envEnt -> case envEnt of
Just (EntityName en) -> return (se == en,True) -- execute if req entity matches context entity
executePrivate <- traverse reduce (_sEntity step) >>= traverse (\stepEntity -> case stepEntity of
(TLitString se) -> view eeEntity >>= \envEnt -> case envEnt of
Just (EntityName en) -> return $ (se == en) -- execute if req entity matches context entity
Nothing -> evalError' step "applyPact: private step executed against non-private environment"
Just t -> evalError' t "applyPact: step entity must be String value"
t -> evalError' t "applyPact: step entity must be String value")

let stepCount = length steps
isLastStep = _psStep == pred stepCount

-- init pact state
evalPactExec .=
Just (PactExec stepCount Nothing executing _psStep _psPactId app)
Just (PactExec stepCount Nothing executePrivate _psStep _psPactId app)

-- evaluate
result <- if not executing then return $ tStr "skip step" else
case (_psRollback,_sRollback step) of
result <- case executePrivate of
Just False -> return $ tStr "skip step"
_ -> case (_psRollback,_sRollback step) of
(False,_) -> reduce $ _sExec step
(True,Just rexp) -> reduce rexp
(True,Nothing) -> evalError' step $ "Rollback requested but none in step"
Expand All @@ -721,7 +720,9 @@ applyPact i app (TList steps _ _) PactStep {..} = do
(evalError i "Internal error, pact exec state not found after execution")

-- update database, determine if done
let done =
let isLastStep = _psStep == pred stepCount
private = isJust executePrivate
done =
(not _psRollback && isLastStep) -- done if normal exec of last step
|| (not private && _psRollback) -- done if public rollback
|| (private && _psRollback && _psStep == 0) -- done if private and rolled back to step 0
Expand Down
2 changes: 1 addition & 1 deletion src/Pact/Repl/Lib.hs
Expand Up @@ -354,7 +354,7 @@ pactState i as = case as of
Nothing -> evalError' i "pact-state: no pact exec in context"
Just PactExec{..} -> return $ toTObject TyAny def $
[("yield",maybe (toTerm False) (toTObjectMap TyAny def . fmap fromPactValue . _yData) _peYield)
,("executed",toTerm _peExecuted)
,("executed",toTerm (_peExecuted /= Just False))
,("step",toTerm _peStep)
,("pactId",toTerm _pePactId)]

Expand Down
4 changes: 2 additions & 2 deletions src/Pact/Types/Continuation.hs
Expand Up @@ -110,8 +110,8 @@ data PactExec = PactExec
-- ^ Count of steps in pact (discovered when code is executed)
, _peYield :: !(Maybe Yield)
-- ^ Yield value if invoked
, _peExecuted :: Bool
-- ^ Whether step was executed (in private cases, it can be skipped)
, _peExecuted :: Maybe Bool
-- ^ Only populated for private pacts, indicates if step was executed or skipped.
, _peStep :: Int
-- ^ Step that was executed or skipped
, _pePactId :: PactId
Expand Down

0 comments on commit f42a48f

Please sign in to comment.