Skip to content

Commit

Permalink
Add links to visit future & past steps of a continuation (#77)
Browse files Browse the repository at this point in the history
This PR provides links on the transaction detail pages (/txdetail) to step both forward and backward between individual steps of a continuation. At any given step, the user should be able to traverse back to any step before the current AND traverse to the immediate next step (even if it is fails). We also display failed next steps (we stop at 10). This PR completes the work done in both chainweb-data and chainweb-api for supporting this endeavor.

* Add links to visit future & past steps of a continuation

At this, we can visit previous steps from the current one

* Make definition table for past steps & initial code

* Links to step immediately after in continuation

* simplify display of failed conts

* Don't make an unnecessary query on the last step

* don't check if step is the last

* Update frontend/src/Frontend/Page/Common.hs

Co-authored-by: Enis Bayramoğlu <[email protected]>

* ditch partial response from pactid endpoint

* Add line on page between failed and successful steps

* point to master on chainweb-api

* use span instead of partition b/c list is already sorted

---------

Co-authored-by: Enis Bayramoğlu <[email protected]>
  • Loading branch information
emmanueldenloye and enobayram authored May 3, 2023
1 parent 3e4a82d commit 200152a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 16 deletions.
4 changes: 2 additions & 2 deletions deps/chainweb-api/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"repo": "chainweb-api",
"branch": "master",
"private": false,
"rev": "6725d8490fcf43fd5f6b8b0ca731565a58f9c8e6",
"sha256": "B3swFmWuEajZ42gpdvHsF2MpWxHU4YiIx/nV+1ZCx30="
"rev": "b3e28d62c622ebda0d84e136ea6c995d5f97e46f",
"sha256": "1m9x9n5mwmv97fkv2z3hvlhlj59xm2mpsc816hzriw28pv1jb9zh"
}
5 changes: 3 additions & 2 deletions frontend/src/Frontend/ChainwebApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,12 @@ searchTxs
-> Dynamic t (Maybe Limit)
-> Dynamic t (Maybe Offset)
-> Dynamic t (QParam Text)
-> Dynamic t (QParam Text)
-> Dynamic t (QParam Int)
-> Dynamic t (QParam Int)
-> Event t ()
-> m (Event t (Either Text (Bool,[TxSummary])))
searchTxs nc lim off needle minHeight maxHeight evt = do
searchTxs nc lim off needle pactid minHeight maxHeight evt = do
case _netConfig_dataHost nc of
Nothing -> return never
Just dh -> do
Expand All @@ -489,7 +490,7 @@ searchTxs nc lim off needle minHeight maxHeight evt = do
(Proxy :: Proxy (LooperTag TxSummary ()))
(constDyn $ mkDataUrl dh)
nextHeaderOpts
txResp <- requestLooper (\limm offf nextToken evt' -> go limm offf needle minHeight maxHeight nextToken evt') lim off evt
txResp <- requestLooper (\limm offf nextToken evt' -> go limm offf needle pactid minHeight maxHeight nextToken evt') lim off evt
return $ handleLooperResults <$> txResp

handleLooperResults :: Either (ReqResult t [result]) (LooperTag result callerTag) -> Either Text (Bool, [result])
Expand Down
30 changes: 29 additions & 1 deletion frontend/src/Frontend/Page/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Frontend.Page.Common

------------------------------------------------------------------------------
import Control.Lens
import Control.Monad (unless, when)
------------------------------------------------------------------------------
import Data.Aeson as A
import Data.Foldable
Expand All @@ -47,6 +48,7 @@ import Pact.Types.Pretty
import Chainweb.Api.ChainId
import Chainweb.Api.Hash
import Chainweb.Api.Payload
import ChainwebData.TxSummary

-- ------------------------------------------------------------------------ --
-- Reflex modules
Expand Down Expand Up @@ -170,9 +172,14 @@ renderPayload = \case
--
renderPactExec
:: MonadApp r t m
=> RouteToUrl (R FrontendRoute) m
=> SetRoute t (R FrontendRoute) m
=> Prerender js t m
=> PactExec
-> NetId
-> Either Text [TxSummary]
-> m ()
renderPactExec (PactExec stepCount y x step (PactId pid) pcont rb) =
renderPactExec (PactExec stepCount y x step (PactId pid) pcont rb) netId res =
detailsSection $ do
tfield "Step Count" $ text $ tshow stepCount
voidMaybe (tfield "Yield" . renderYield) y
Expand All @@ -181,6 +188,27 @@ renderPactExec (PactExec stepCount y x step (PactId pid) pcont rb) =
tfield "Pact Id" $ text pid
tfield "Continuation" $ renderContinuation pcont
tfield "Rollback" $ text $ tshow rb
tfield "Next Step" $ case res of
Left err -> tfield "Error" $ text err
Right xs -> case span ((== TxSucceeded) . _txSummary_result) xs of
(ys,zs) -> do
unless (null ys) $ do
text "Successful:"
el "br" blank
iforM_ ys $ \i next -> do
txDetailLink $ _txSummary_requestKey next
when (i < length ys - 1) $ el "br" blank
el "br" blank
unless (null zs) $ do
text $ "Failed:"
el "br" blank
iforM_ (take 10 zs) $ \i z -> do
txDetailLink $ _txSummary_requestKey z
when (i < length zs - 1) $ el "br" blank
when (not $ null $ drop 10 zs) $ text "...and more"
where
txDetailLink rk = routeLink (mkTxDetailRoute rk) $ text rk
mkTxDetailRoute rk = mkNetRoute netId $ NetRoute_TxDetail :/ rk

-- | Render the 'Provenance' pact type
--
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Frontend/Page/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ transactionPage netId netConfig cid bp hash = do
Chain_BlockHash :/ (hashB64U hash, Block_Header :/ ())) $ text $ hashB64U hash

let cutText = elAttr "div" ("class" =: "cut-text")
let lastMay = foldl (const Just) Nothing
let lastMay :: [a] -> Maybe a
lastMay = foldl (const Just) Nothing
pb <- getPostBuild

el "h2" $ text $ "Block Transactions"
Expand Down
48 changes: 39 additions & 9 deletions frontend/src/Frontend/Page/TxDetail.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Frontend.Page.TxDetail where

import Control.Monad
import Control.Monad.Reader
import Control.Lens (iforM_)
import Data.Aeson as A
import qualified Data.Text as T
import GHCJS.DOM.Types (MonadJSM)
Expand All @@ -23,7 +24,7 @@ import Reflex.Dom.Core hiding (Value)
import Reflex.Network
import Servant.Reflex

import Pact.Types.Continuation (PactExec)
import Pact.Types.Continuation (PactExec(..))

import Chainweb.Api.BlockHeader
import Chainweb.Api.ChainId
Expand Down Expand Up @@ -64,7 +65,7 @@ txDetailWidget netId = do
(leftmost [pb, () <$ updated reqKey])
void
$ networkHold (inlineLoader "Querying blockchain ...")
$ fmap (either text (txDetailPage netId (_siChainwebVer si))) res
$ fmap (either text (txDetailPage nc netId (_siChainwebVer si))) res



Expand All @@ -76,11 +77,12 @@ txDetailPage
, MonadJSM (Performable m)
, Prerender js t m
)
=> NetId
=> NetConfig
-> NetId
-> ChainwebVersion
-> [TxDetail]
-> m ()
txDetailPage netId cwVer txDetails = do
txDetailPage nc netId cwVer txDetails = do
el "h2" $ text $ "Transaction Detail"
elClass "table" "ui definition table" $ do
el "tbody" $ do
Expand All @@ -100,7 +102,22 @@ txDetailPage netId cwVer txDetails = do
tagIfOrphan (ChainId $ _txDetail_chain tx) (_txDetail_height tx) (_txDetail_blockHash tx)
tfield "Code" $ case (_txDetail_code $ head txDetails) of
Just c -> elAttr "pre" ("style" =: "white-space: pre-wrap;") $ text c
Nothing -> text "Continuation"
Nothing -> do
let previousSteps = _txDetail_previousSteps $ head txDetails
initialCode = _txDetail_initialCode $ head txDetails
mkTxDetailRoute rk = mkNetRoute netId (NetRoute_TxDetail :/ rk)
txDetailLink rk = do
text "Continuation of "
routeLink (mkTxDetailRoute rk) $ text rk
elClass "table" "ui definition table" $ el "tbody" $ do
case previousSteps of
Just steps -> tfield "Past Steps" $ do
let l = length steps
iforM_ steps $ \i step -> do
txDetailLink step
unless (i >= l - 1) $ el "br" blank
Nothing -> text "No previous steps?"
forM_ initialCode $ \c -> tfield "Initial Code" $ elAttr "pre" ("style" =: "white-space: pre-wrap;") $ text c
tfield "Transaction Output" $ do
elClass "table" "ui definition table" $ el "tbody" $ do
tfield "Gas" $ text $ tshow $ (_txDetail_gas $ head txDetails)
Expand All @@ -112,7 +129,21 @@ txDetailPage netId cwVer txDetails = do
text $ pactValueJSON (_txDetail_result $ head txDetails)
tfield "Logs" $ text (_txDetail_logs $ head txDetails)
tfield "Metadata" $ renderMetaData netId (ChainId (_txDetail_chain $ head txDetails)) (Just (_txDetail_metadata $ head txDetails))
tfield "Continuation" $ voidMaybe renderCont $ (_txDetail_continuation $ head txDetails)
tfield "Continuation" $ do
pb <- getPostBuild
let cont = _txDetail_continuation $ head txDetails
let ditchPartialResult = \case
Left t -> Left t
Right (False,_) -> Left "A partial response is impossible!"
Right (True,r) -> Right r
forM_ cont $ \c -> do
res <- searchTxs nc
(constDyn Nothing)
(constDyn Nothing)
(constDyn QNone)
(constDyn (QParamSome $ _txDetail_requestKey $ head txDetails))
(constDyn QNone) (constDyn QNone) pb
widgetHold_ (inlineLoader "Querying continuation info...") (renderCont c . ditchPartialResult <$> res)
tfield "Transaction ID" $ text $ tshow (_txDetail_txid $ head txDetails)
tfield "Events" $ elClass "table" "ui definition table" $ el "tbody" $
forM_ (_txDetail_events $ head txDetails) $ \ ev -> el "tr" $ do
Expand Down Expand Up @@ -158,7 +189,6 @@ txDetailPage netId cwVer txDetails = do
-- forM_ (_transaction_sigs t) $ \s -> do
-- el "div" $ text $ unSig s
where

renderCont v = case fromJSON v of
Success (pe :: PactExec) -> renderPactExec pe
renderCont v res = case fromJSON v of
Success (pe :: PactExec) -> renderPactExec pe netId res
A.Error e -> text $ T.pack $ "Unable to render continuation" <> e
2 changes: 1 addition & 1 deletion frontend/src/Frontend/Transactions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ transactionSearch = do
res <- searchTxs nc
(constDyn $ Just $ Limit itemsPerPage)
(Just . Offset . (*itemsPerPage) . pred <$> page)
(QParamSome <$> needle) (constDyn QNone) (constDyn QNone) newSearch
(QParamSome <$> needle) (constDyn QNone) (constDyn QNone) (constDyn QNone) newSearch

divClass "ui pagination menu" $ do
let setSearchRoute f e = setRoute $
Expand Down

0 comments on commit 200152a

Please sign in to comment.