diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ee291..80d13ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.7.0.0-beta] ### Added diff --git a/app/Server.hs b/app/Server.hs index feee0d7..68d1661 100644 --- a/app/Server.hs +++ b/app/Server.hs @@ -3,14 +3,18 @@ module Server where import Control.Concurrent (forkIO, threadDelay) -import Control.Exception (throwIO, try) +import Control.Exception (throwIO, throwTo, try) import Control.Monad (forever, when) +import Control.Monad.Logger (runNoLoggingT) import Data.Configurator +import qualified Data.Text as T import Network.Wai.Handler.Warp (run) import Servant +import System.Exit +import System.Posix.Signals import ZcashHaskell.Types (ZebraGetBlockChainInfo(..), ZebraGetInfo(..)) import Zenith.Core (checkBlockChain, checkZebra) -import Zenith.DB (initDb) +import Zenith.DB (getWallets, initDb, initPool) import Zenith.RPC ( State(..) , ZenithRPC(..) @@ -46,22 +50,39 @@ main = do Left e2 -> throwIO $ userError e2 Right x' -> do when x' $ rescanZebra zebraHost zebraPort dbFilePath - _ <- - forkIO $ - forever $ do - _ <- - scanZebra dbFilePath zebraHost zebraPort (zgb_net chainInfo) - threadDelay 90000000 - let myState = - State - (zgb_net chainInfo) - zebraHost - zebraPort - dbFilePath - (zgi_build zebra) - (zgb_blocks chainInfo) - run nodePort $ - serveWithContext - (Proxy :: Proxy ZenithRPC) - ctx - (zenithServer myState) + pool <- runNoLoggingT $ initPool dbFilePath + walList <- getWallets pool $ zgb_net chainInfo + if not (null walList) + then do + scanThread <- + forkIO $ + forever $ do + _ <- + scanZebra + dbFilePath + zebraHost + zebraPort + (zgb_net chainInfo) + threadDelay 90000000 + putStrLn "Zenith RPC Server 0.7.0.0-beta" + putStrLn "------------------------------" + putStrLn $ + "Connected to " ++ + show (zgb_net chainInfo) ++ + " Zebra " ++ + T.unpack (zgi_build zebra) ++ " on port " ++ show zebraPort + let myState = + State + (zgb_net chainInfo) + zebraHost + zebraPort + dbFilePath + (zgi_build zebra) + (zgb_blocks chainInfo) + run nodePort $ + serveWithContext + (Proxy :: Proxy ZenithRPC) + ctx + (zenithServer myState) + else putStrLn + "No wallets available. Please start Zenith interactively to create a wallet" diff --git a/src/Zenith/DB.hs b/src/Zenith/DB.hs index b2ca122..4c9e7bf 100644 --- a/src/Zenith/DB.hs +++ b/src/Zenith/DB.hs @@ -2683,7 +2683,7 @@ completeSync pool st = do rewindWalletData :: ConnectionPool -> Int -> ZcashNetDB -> LoggingT IO () rewindWalletData pool b net = do logDebugN "Starting transaction rewind" - liftIO $ clearWalletTransactions pool + liftIO $ rewindWalletTransactions pool b logDebugN "Completed transaction rewind" logDebugN "Starting data store rewind" _ <- diff --git a/src/Zenith/RPC.hs b/src/Zenith/RPC.hs index 66cf773..286521e 100644 --- a/src/Zenith/RPC.hs +++ b/src/Zenith/RPC.hs @@ -52,6 +52,7 @@ import Zenith.Core , createZcashAccount , prepareTxV2 , syncWallet + , updateCommitmentTrees ) import Zenith.DB ( Operation(..) @@ -910,6 +911,9 @@ scanZebra dbPath zHost zPort net = do return () Right _ -> do wals <- getWallets pool net + _ <- + runStderrLoggingT $ + updateCommitmentTrees pool zHost zPort $ ZcashNetDB net runStderrLoggingT $ mapM_ (syncWallet (Config dbPath zHost zPort "user" "pwd" 8080)) diff --git a/zenith.cabal b/zenith.cabal index c97e222..5ee487b 100644 --- a/zenith.cabal +++ b/zenith.cabal @@ -127,9 +127,12 @@ executable zenithserver build-depends: base >=4.12 && <5 , configurator + , monad-logger , wai-extra , warp , servant-server + , text + , unix , zcash-haskell , zenith pkgconfig-depends: rustzcash_wrapper