{-# LANGUAGE OverloadedStrings #-} -- Core wallet functionality for Zenith module Zenith.Core where import Data.Aeson import qualified Data.Text as T import Database.Persist import Database.Persist.Sqlite import Network.HTTP.Client import ZcashHaskell.Types import ZcashHaskell.Utils import Zenith.DB -- * Database functions -- | Returns the list of wallets available in the given database checkWallets :: T.Text -- ^ The database name to check -> ZcashNet -- ^ The network the wallet is running -> IO [Entity ZcashWallet] checkWallets dbName znet = do runSqlite dbName $ do runMigration migrateAll runSqlite dbName $ selectList [ZcashWalletNetwork ==. znet] [] -- * Zebra Node interaction -- | Checks the status of the `zebrad` node checkZebra :: T.Text -- ^ Host where `zebrad` is available -> Int -- ^ Port where `zebrad` is available -> IO (Maybe ZebraGetInfo) checkZebra host port = do res <- makeZebraCall host port "getinfo" [] let body = responseBody (res :: Response (RpcResponse ZebraGetInfo)) return $ result body -- | Checks the status of the Zcash blockchain checkBlockChain :: T.Text -- ^ Host where `zebrad` is available -> Int -- ^ Port where `zebrad` is available -> IO (Maybe ZebraGetBlockChainInfo) checkBlockChain host port = do let f = makeZebraCall host port result <$> (responseBody <$> f "getblockchaininfo" []) -- | Generic RPC call function connectZebra :: FromJSON a => T.Text -> Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a) connectZebra host port m params = do res <- makeZebraCall host port m params let body = responseBody res return $ result body