Skip to content

Commit

Permalink
Search related continuations in tx search
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Popejoy committed Aug 18, 2021
1 parent 80d86ec commit 6a3bae3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion exec/Chainweb/Lookups.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mkTransaction b (tx,txo) = Transaction
, _tx_sender = _chainwebMeta_sender mta
, _tx_nonce = _pactCommand_nonce cmd
, _tx_code = _exec_code <$> exc
, _tx_pactId = _cont_pactId <$> cnt
, _tx_pactId = DbHash . _cont_pactId <$> cnt
, _tx_rollback = _cont_rollback <$> cnt
, _tx_step = fromIntegral . _cont_step <$> cnt
, _tx_data = (PgJSONB . _cont_data <$> cnt)
Expand Down
45 changes: 26 additions & 19 deletions exec/Chainweb/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -286,31 +286,38 @@ searchTxs
searchTxs _ _ _ _ _ Nothing = throw404 "You must specify a search string"
searchTxs logger pool req limit offset (Just search) = do
liftIO $ logger Info $ fromString $ printf "Transaction search from %s: %s" (show $ remoteHost req) (T.unpack search)
liftIO $ P.withResource pool $ \c -> do
res <- runBeamPostgresDebug (logger Debug . fromString) c $
runSelectReturningList $ select $ do
limit_ lim $ offset_ off $ orderBy_ (desc_ . getHeight) $ do
liftIO $ P.withResource pool $ \c ->
fmap (fmap mkSummary)
$ runBeamPostgresDebug (logger Debug . fromString) c
$ runSelectReturningList
$ select
$ limit_ lim
$ offset_ off
$ orderBy_ (desc_ . _block_height . view _2)
$ do
tx <- all_ (_cddb_transactions database)
tx2 <- leftJoin_
(all_ $ _cddb_transactions database)
(\tx2 -> (_tx_pactId tx2 ==. just_ (_tx_requestKey tx)) &&.
(_tx_code tx2 `like_` val_ (Just searchString)))
blk <- all_ (_cddb_blocks database)
guard_ (_tx_block tx `references_` blk)
guard_ (_tx_code tx `like_` val_ (Just searchString))
return
( (_tx_chainId tx)
, (_block_height blk)
, (unBlockId $ _tx_block tx)
, (_tx_creationTime tx)
, (_tx_requestKey tx)
, (_tx_sender tx)
, ((_tx_code tx)
, (_tx_continuation tx)
, (_tx_goodResult tx)
))
return $ mkSummary <$> res
return (tx,blk,tx2)
where
lim = maybe 10 (min 100 . unLimit) limit
off = maybe 0 unOffset offset
getHeight (_,a,_,_,_,_,_) = a
mkSummary (a,b,c,d,e,f,(g,h,i)) = TxSummary (fromIntegral a) (fromIntegral b) (unDbHash c) d (unDbHash e) f g (unPgJsonb <$> h) (maybe TxFailed (const TxSucceeded) i)
mkSummary (tx,blk,tx2) = TxSummary
{ _txSummary_chain = fromIntegral (_tx_chainId tx)
, _txSummary_height = fromIntegral (_block_height blk)
, _txSummary_blockHash = unDbHash (unBlockId $ _tx_block tx)
, _txSummary_creationTime = (_tx_creationTime tx)
, _txSummary_requestKey = unDbHash (_tx_requestKey tx)
, _txSummary_sender = (_tx_sender tx)
, _txSummary_code = maybe (maybe Nothing _tx_code tx2) Just $ _tx_code tx
, _txSummary_continuation = unPgJsonb <$> (_tx_continuation tx)
, _txSummary_result = maybe TxFailed (const TxSucceeded) (_tx_goodResult tx)
}
searchString = "%" <> search <> "%"

throw404 :: MonadError ServerError m => ByteString -> m a
Expand Down Expand Up @@ -340,7 +347,7 @@ txHandler logger pool (Just (RequestKey rk)) =
, _txDetail_gasLimit = fromIntegral $ _tx_gasLimit tx
, _txDetail_gasPrice = _tx_gasPrice tx
, _txDetail_nonce = _tx_nonce tx
, _txDetail_pactId = _tx_pactId tx
, _txDetail_pactId = unDbHash <$> _tx_pactId tx
, _txDetail_rollback = _tx_rollback tx
, _txDetail_step = fromIntegral <$> _tx_step tx
, _txDetail_data = unMaybeValue $ _tx_data tx
Expand Down
2 changes: 1 addition & 1 deletion lib/ChainwebDb/Types/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data TransactionT f = Transaction
, _tx_sender :: C f Text
, _tx_nonce :: C f Text
, _tx_code :: C f (Maybe Text)
, _tx_pactId :: C f (Maybe Text)
, _tx_pactId :: C f (Maybe (DbHash TxHash))
, _tx_rollback :: C f (Maybe Bool)
, _tx_step :: C f (Maybe Int64)
, _tx_data :: C f (Maybe (PgJSONB Value))
Expand Down

0 comments on commit 6a3bae3

Please sign in to comment.