diff --git a/src/Zenith/Scanner.hs b/src/Zenith/Scanner.hs new file mode 100644 index 0000000..dffa8f6 --- /dev/null +++ b/src/Zenith/Scanner.hs @@ -0,0 +1,22 @@ +module Zenith.Scanner where + +import Control.Monad (when) +import qualified Data.Text as T +import Zenith.Core (checkBlockChain) + +-- | Function to scan the Zcash blockchain through the Zebra node and populate the Zenith database +scanZebra :: + Int -- ^ Starting block + -> T.Text -- ^ Host + -> Int -- ^ Port + -> T.Text -- ^ Path to database file + -> IO () +scanZebra b host port dbFilePath = do + bc <- checkBlockChain host port + case bc of + Nothing -> throwIO $ userError "Failed to determine blockchain status" + Just bStatus -> do + if b > zgb_blocks bStatus + then throwIO $ userError "Invalid starting block for scan" + else do + let bList = [b .. (zgb_blocks bStatus)] diff --git a/zenith.cabal b/zenith.cabal index 081df74..596e730 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -32,6 +32,7 @@ library Zenith.Types Zenith.Utils Zenith.Zcashd + Zenith.Scanner hs-source-dirs: src build-depends: