feat: finalize RPC
This commit is contained in:
parent
d2c52508d1
commit
9c2d0aaf20
5 changed files with 51 additions and 23 deletions
|
@ -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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [0.7.0.0-beta]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,18 @@
|
||||||
module Server where
|
module Server where
|
||||||
|
|
||||||
import Control.Concurrent (forkIO, threadDelay)
|
import Control.Concurrent (forkIO, threadDelay)
|
||||||
import Control.Exception (throwIO, try)
|
import Control.Exception (throwIO, throwTo, try)
|
||||||
import Control.Monad (forever, when)
|
import Control.Monad (forever, when)
|
||||||
|
import Control.Monad.Logger (runNoLoggingT)
|
||||||
import Data.Configurator
|
import Data.Configurator
|
||||||
|
import qualified Data.Text as T
|
||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
import Servant
|
import Servant
|
||||||
|
import System.Exit
|
||||||
|
import System.Posix.Signals
|
||||||
import ZcashHaskell.Types (ZebraGetBlockChainInfo(..), ZebraGetInfo(..))
|
import ZcashHaskell.Types (ZebraGetBlockChainInfo(..), ZebraGetInfo(..))
|
||||||
import Zenith.Core (checkBlockChain, checkZebra)
|
import Zenith.Core (checkBlockChain, checkZebra)
|
||||||
import Zenith.DB (initDb)
|
import Zenith.DB (getWallets, initDb, initPool)
|
||||||
import Zenith.RPC
|
import Zenith.RPC
|
||||||
( State(..)
|
( State(..)
|
||||||
, ZenithRPC(..)
|
, ZenithRPC(..)
|
||||||
|
@ -46,12 +50,27 @@ main = do
|
||||||
Left e2 -> throwIO $ userError e2
|
Left e2 -> throwIO $ userError e2
|
||||||
Right x' -> do
|
Right x' -> do
|
||||||
when x' $ rescanZebra zebraHost zebraPort dbFilePath
|
when x' $ rescanZebra zebraHost zebraPort dbFilePath
|
||||||
_ <-
|
pool <- runNoLoggingT $ initPool dbFilePath
|
||||||
|
walList <- getWallets pool $ zgb_net chainInfo
|
||||||
|
if not (null walList)
|
||||||
|
then do
|
||||||
|
scanThread <-
|
||||||
forkIO $
|
forkIO $
|
||||||
forever $ do
|
forever $ do
|
||||||
_ <-
|
_ <-
|
||||||
scanZebra dbFilePath zebraHost zebraPort (zgb_net chainInfo)
|
scanZebra
|
||||||
|
dbFilePath
|
||||||
|
zebraHost
|
||||||
|
zebraPort
|
||||||
|
(zgb_net chainInfo)
|
||||||
threadDelay 90000000
|
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 =
|
let myState =
|
||||||
State
|
State
|
||||||
(zgb_net chainInfo)
|
(zgb_net chainInfo)
|
||||||
|
@ -65,3 +84,5 @@ main = do
|
||||||
(Proxy :: Proxy ZenithRPC)
|
(Proxy :: Proxy ZenithRPC)
|
||||||
ctx
|
ctx
|
||||||
(zenithServer myState)
|
(zenithServer myState)
|
||||||
|
else putStrLn
|
||||||
|
"No wallets available. Please start Zenith interactively to create a wallet"
|
||||||
|
|
|
@ -2683,7 +2683,7 @@ completeSync pool st = do
|
||||||
rewindWalletData :: ConnectionPool -> Int -> ZcashNetDB -> LoggingT IO ()
|
rewindWalletData :: ConnectionPool -> Int -> ZcashNetDB -> LoggingT IO ()
|
||||||
rewindWalletData pool b net = do
|
rewindWalletData pool b net = do
|
||||||
logDebugN "Starting transaction rewind"
|
logDebugN "Starting transaction rewind"
|
||||||
liftIO $ clearWalletTransactions pool
|
liftIO $ rewindWalletTransactions pool b
|
||||||
logDebugN "Completed transaction rewind"
|
logDebugN "Completed transaction rewind"
|
||||||
logDebugN "Starting data store rewind"
|
logDebugN "Starting data store rewind"
|
||||||
_ <-
|
_ <-
|
||||||
|
|
|
@ -52,6 +52,7 @@ import Zenith.Core
|
||||||
, createZcashAccount
|
, createZcashAccount
|
||||||
, prepareTxV2
|
, prepareTxV2
|
||||||
, syncWallet
|
, syncWallet
|
||||||
|
, updateCommitmentTrees
|
||||||
)
|
)
|
||||||
import Zenith.DB
|
import Zenith.DB
|
||||||
( Operation(..)
|
( Operation(..)
|
||||||
|
@ -910,6 +911,9 @@ scanZebra dbPath zHost zPort net = do
|
||||||
return ()
|
return ()
|
||||||
Right _ -> do
|
Right _ -> do
|
||||||
wals <- getWallets pool net
|
wals <- getWallets pool net
|
||||||
|
_ <-
|
||||||
|
runStderrLoggingT $
|
||||||
|
updateCommitmentTrees pool zHost zPort $ ZcashNetDB net
|
||||||
runStderrLoggingT $
|
runStderrLoggingT $
|
||||||
mapM_
|
mapM_
|
||||||
(syncWallet (Config dbPath zHost zPort "user" "pwd" 8080))
|
(syncWallet (Config dbPath zHost zPort "user" "pwd" 8080))
|
||||||
|
|
|
@ -127,9 +127,12 @@ executable zenithserver
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.12 && <5
|
base >=4.12 && <5
|
||||||
, configurator
|
, configurator
|
||||||
|
, monad-logger
|
||||||
, wai-extra
|
, wai-extra
|
||||||
, warp
|
, warp
|
||||||
, servant-server
|
, servant-server
|
||||||
|
, text
|
||||||
|
, unix
|
||||||
, zcash-haskell
|
, zcash-haskell
|
||||||
, zenith
|
, zenith
|
||||||
pkgconfig-depends: rustzcash_wrapper
|
pkgconfig-depends: rustzcash_wrapper
|
||||||
|
|
Loading…
Reference in a new issue