zenith/src/Zenith/Core.hs

50 lines
1.5 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
2024-02-13 20:19:05 +00:00
-> ZcashNet -- ^ The network the wallet is running
-> IO [Entity ZcashWallet]
2024-02-13 20:19:05 +00:00
checkWallets dbName znet = do
runSqlite dbName $ do runMigration migrateAll
2024-02-13 20:19:05 +00:00
runSqlite dbName $ selectList [ZcashWalletNetwork ==. znet] []
-- * 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