This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
webap: Fix /api/blocks/txs/{blkHash} endpoint
- Loading branch information
Showing
9 changed files
with
271 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
cardano-explorer-webapi/app/Explorer/Web/Validate/BlockTx.hs
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
cardano-explorer-webapi/app/Explorer/Web/Validate/BlocksTxs.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TupleSections #-} | ||
|
||
module Explorer.Web.Validate.BlocksTxs | ||
( validateBlocksTxs | ||
) where | ||
|
||
import qualified Data.List as List | ||
import Data.Text (Text) | ||
import qualified Data.Text as Text | ||
import Data.Text.ANSI (green, red) | ||
import qualified Data.Text.IO as Text | ||
|
||
import Database.Persist.Sql (SqlBackend) | ||
|
||
import Explorer.Web (CTxBrief (..), CTxBrief (..), queryBlocksTxs, runQuery) | ||
import Explorer.Web.Api.Legacy.Util (bsBase16Encode) | ||
import Explorer.Web.Validate.Random (queryRandomBlockHash) | ||
import Explorer.Web.Validate.ErrorHandling (handleLookupFail, handleExplorerError) | ||
|
||
|
||
import System.Exit (exitFailure) | ||
|
||
validateBlocksTxs :: SqlBackend -> IO () | ||
validateBlocksTxs backend = do | ||
(blkHash, txs) <- runQuery backend $ do | ||
blkHash <- handleLookupFail =<< queryRandomBlockHash | ||
(blkHash,) <$> (handleExplorerError =<< queryBlocksTxs blkHash 100 0) | ||
|
||
validateInputsUnique (bsBase16Encode blkHash) txs | ||
validateOutputsUnique (bsBase16Encode blkHash) txs | ||
|
||
-- ------------------------------------------------------------------------------------------------- | ||
|
||
validateInputsUnique :: Text -> [CTxBrief] -> IO () | ||
validateInputsUnique blkHash tabs = do | ||
mapM_ Text.putStr [ " Inputs for block " , shortenTxHash blkHash, " are unique: " ] | ||
if length tabs == length (List.nub tabs) | ||
then Text.putStrLn $ green "ok" | ||
else do | ||
Text.putStrLn $ red "validateInputsUnique failed" | ||
exitFailure | ||
|
||
-- https://github.com/input-output-hk/cardano-explorer/issues/195 | ||
validateOutputsUnique :: Text -> [CTxBrief] -> IO () | ||
validateOutputsUnique blkHash tabs = do | ||
mapM_ Text.putStr [ " Outputs for block " , shortenTxHash blkHash, " are unique: " ] | ||
if length tabs == length (List.nub tabs) | ||
then Text.putStrLn $ green "ok" | ||
else do | ||
Text.putStrLn $ red "validateOutputsUnique failed" | ||
exitFailure | ||
|
||
|
||
-- ------------------------------------------------------------------------------------------------- | ||
|
||
shortenTxHash :: Text -> Text | ||
shortenTxHash txh = | ||
mconcat [Text.take 10 txh, "...", Text.drop (Text.length txh - 10) txh] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.