Add function process a block
This commit is contained in:
parent
25c6baeec1
commit
6b48f49760
1 changed files with 27 additions and 2 deletions
|
@ -1,7 +1,17 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Zenith.Scanner where
|
module Zenith.Scanner where
|
||||||
|
|
||||||
import Control.Monad (when)
|
import Control.Exception (throwIO)
|
||||||
|
import Data.HexString
|
||||||
import qualified Data.Text as T
|
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)
|
import Zenith.Core (checkBlockChain)
|
||||||
|
|
||||||
-- | Function to scan the Zcash blockchain through the Zebra node and populate the Zenith database
|
-- | 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
|
case bc of
|
||||||
Nothing -> throwIO $ userError "Failed to determine blockchain status"
|
Nothing -> throwIO $ userError "Failed to determine blockchain status"
|
||||||
Just bStatus -> do
|
Just bStatus -> do
|
||||||
if b > zgb_blocks bStatus
|
if b > zgb_blocks bStatus || b < 1
|
||||||
then throwIO $ userError "Invalid starting block for scan"
|
then throwIO $ userError "Invalid starting block for scan"
|
||||||
else do
|
else do
|
||||||
let bList = [b .. (zgb_blocks bStatus)]
|
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'
|
||||||
|
|
Loading…
Reference in a new issue