zenith/src/Zenith/Core.hs

49 lines
1.4 KiB
Haskell
Raw Normal View History

{-# 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
-> IO [Entity ZcashWallet]
checkWallets dbName = do
runSqlite dbName $ do runMigration migrateAll
runSqlite dbName $ selectList [ZcashWalletBirthdayHeight >. 0] []
-- * Zebra Node interaction
-- | Checks the status of the `zebrad` node
checkZebra ::
Int -- ^ Port where `zebrad` is available
-> IO (Maybe ZebraGetInfo)
checkZebra port = do
res <- makeZebraCall port "getinfo" []
let body = responseBody (res :: Response (RpcResponse ZebraGetInfo))
return $ result body
-- | Checks the status of the Zcash blockchain
checkBlockChain ::
Int -- ^ Port where `zebrad` is available
-> IO (Maybe ZebraGetBlockChainInfo)
checkBlockChain port = do
let f = makeZebraCall port
result <$> (responseBody <$> f "getblockchaininfo" [])
-- | Generic RPC call function
connectZebra ::
FromJSON a => Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a)
connectZebra port m params = do
res <- makeZebraCall port m params
let body = responseBody res
return $ result body