Add function process a block

This commit is contained in:
Rene Vergara 2024-03-19 15:48:50 -05:00
parent 25c6baeec1
commit 6b48f49760
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -1,7 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}
module Zenith.Scanner where
import Control.Monad (when)
import Control.Exception (throwIO)
import Data.HexString
import qualified Data.Text as T
import Network.HTTP.Simple (getResponseBody)
import ZcashHaskell.Types
( BlockResponse(..)
, RpcResponse(..)
, ZebraGetBlockChainInfo(..)
)
import ZcashHaskell.Utils (makeZebraCall)
import Zenith.Core (checkBlockChain)
-- | Function to scan the Zcash blockchain through the Zebra node and populate the Zenith database
@ -16,7 +26,22 @@ scanZebra b host port dbFilePath = do
case bc of
Nothing -> throwIO $ userError "Failed to determine blockchain status"
Just bStatus -> do
if b > zgb_blocks bStatus
if b > zgb_blocks bStatus || b < 1
then throwIO $ userError "Invalid starting block for scan"
else do
let bList = [b .. (zgb_blocks bStatus)]
print bList
-- | Function to process a raw block and extract the transaction information
processBlock ::
Int -- ^ The block number to process
-> T.Text -- ^ Host name for `zebrad`
-> Int -- ^ Port for `zebrad`
-> IO [HexString]
processBlock b host port = do
r <-
result . getResponseBody <$>
makeZebraCall host port "getblock" [fromIntegral b, 1]
case r of
Nothing -> throwIO $ userError "Unable to get block data from Zebra"
Just b' -> return $ bl_txs b'