diff --git a/src/Zenith/Core.hs b/src/Zenith/Core.hs index 2b7cf00..3d9fac6 100644 --- a/src/Zenith/Core.hs +++ b/src/Zenith/Core.hs @@ -161,8 +161,7 @@ createWalletAddress n i zNet scope za = do -- * Wallet -- | Sync the wallet with the data store syncWallet :: - T.Text -- ^ Wallet database - -> T.Text -- ^ Data store database + T.Text -- ^ The database path -> Entity ZcashWallet -> IO () -syncWallet walletDb dataDb w = undefined +syncWallet walletDb w = undefined diff --git a/src/Zenith/DB.hs b/src/Zenith/DB.hs index d59629c..496a353 100644 --- a/src/Zenith/DB.hs +++ b/src/Zenith/DB.hs @@ -79,19 +79,21 @@ share UniqueAddName accId name deriving Show Eq WalletTransaction - addrId WalletAddressId txId HexStringDB + block Int conf Int time Int deriving Show Eq WalletTrNote tx WalletTransactionId + addrId WalletAddressId value Int rawId TransparentNoteId spent Bool deriving Show Eq WalletSapNote tx WalletTransactionId + addrId WalletAddressId value Int recipient BS.ByteString memo T.Text @@ -100,6 +102,7 @@ share deriving Show Eq WalletOrchNote tx WalletTransactionId + addrId WalletAddressId value Int recipient BS.ByteString memo T.Text @@ -206,6 +209,18 @@ getMaxBlock dbPath = do Nothing -> return $ -1 Just x -> return $ zcashTransactionBlock $ entityVal x +-- | Returns the largest block in the wallet +getMaxWalletBlock :: + T.Text -- ^ The database path + -> IO Int +getMaxWalletBlock dbPath = do + b <- + runSqlite dbPath $ + selectFirst [WalletTransactionBlock >. 0] [Desc WalletTransactionBlock] + case b of + Nothing -> return $ -1 + Just x -> return $ walletTransactionBlock $ entityVal x + -- | Returns a list of addresses associated with the given account getAddresses :: T.Text -- ^ The database path diff --git a/src/Zenith/Scanner.hs b/src/Zenith/Scanner.hs index 5a92959..283387c 100644 --- a/src/Zenith/Scanner.hs +++ b/src/Zenith/Scanner.hs @@ -8,6 +8,7 @@ import Data.HexString import Data.Maybe import qualified Data.Text as T import GHC.Utils.Monad (concatMapM) +import System.Console.AsciiProgress import ZcashHaskell.Types ( BlockResponse(..) , RawZebraTx(..) @@ -39,26 +40,29 @@ scanZebra b host port dbFilePath = do Left e -> print e Right bStatus -> do dbBlock <- getMaxBlock dbFilePath - let sb = min dbBlock b + let sb = max dbBlock b if sb > zgb_blocks bStatus || sb < 1 then throwIO $ userError "Invalid starting block for scan" else do let bList = [sb .. (zgb_blocks bStatus)] - txList <- - try $ mapM_ (processBlock host port dbFilePath) bList :: IO - (Either IOError ()) - case txList of - Left e1 -> print e1 - Right txList' -> print txList' + displayConsoleRegions $ do + pg <- newProgressBar def {pgTotal = fromIntegral $ length bList} + txList <- + try $ mapM_ (processBlock host port dbFilePath pg) bList :: IO + (Either IOError ()) + case txList of + Left e1 -> print e1 + Right txList' -> print txList' -- | Function to process a raw block and extract the transaction information processBlock :: T.Text -- ^ Host name for `zebrad` -> Int -- ^ Port for `zebrad` -> T.Text -- ^ DB file path + -> ProgressBar -- ^ Progress bar -> Int -- ^ The block number to process -> IO () -processBlock host port dbFp b = do +processBlock host port dbFp pg b = do r <- makeZebraCall host @@ -80,6 +84,7 @@ processBlock host port dbFp b = do let blockTime = getBlockTime hb mapM_ (processTx host port blockTime dbFp) $ bl_txs $ addTime blk blockTime + tick pg where addTime :: BlockResponse -> Int -> BlockResponse addTime bl t = diff --git a/zenith.cabal b/zenith.cabal index bb5fc56..6691f3f 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -65,6 +65,7 @@ library , vector , vty , word-wrap + , ascii-progress , zcash-haskell --pkgconfig-depends: rustzcash_wrapper default-language: Haskell2010