diff --git a/src/Zenith/Scanner.hs b/src/Zenith/Scanner.hs index dffa8f6..ccbd80f 100644 --- a/src/Zenith/Scanner.hs +++ b/src/Zenith/Scanner.hs @@ -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'