2024-02-12 21:09:36 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
-- Core wallet functionality for Zenith
|
2024-02-09 22:18:48 +00:00
|
|
|
module Zenith.Core where
|
|
|
|
|
2024-02-12 21:09:36 +00:00
|
|
|
import Data.Aeson
|
2024-02-09 22:18:48 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import Database.Persist
|
|
|
|
import Database.Persist.Sqlite
|
2024-02-12 21:09:36 +00:00
|
|
|
import Network.HTTP.Client
|
|
|
|
import ZcashHaskell.Types
|
|
|
|
import ZcashHaskell.Utils
|
2024-02-09 22:18:48 +00:00
|
|
|
import Zenith.DB
|
|
|
|
|
2024-02-12 21:09:36 +00:00
|
|
|
-- * Database functions
|
|
|
|
-- | Returns the list of wallets available in the given database
|
|
|
|
checkWallets ::
|
|
|
|
T.Text -- ^ The database name to check
|
|
|
|
-> IO [Entity ZcashWallet]
|
2024-02-09 22:18:48 +00:00
|
|
|
checkWallets dbName = do
|
|
|
|
runSqlite dbName $ do runMigration migrateAll
|
2024-02-12 21:09:36 +00:00
|
|
|
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
|