module Network.Bitcoin.Api.Misc where
import Control.Applicative ((<$>), (<*>))
import Control.Lens.TH (makeLenses)
import Control.Monad (mzero)
import Data.Aeson
import Data.Aeson.Types (emptyArray)
import qualified Data.Text as T
import qualified Network.Bitcoin.Api.Internal as I
import qualified Network.Bitcoin.Api.Types as T
data BitcoinInfo = BitcoinInfo {
_bitcoinVersion :: Integer,
_protocolVersion :: Integer,
_walletVersion :: Integer,
_balance :: Integer,
_numBlocks :: Integer,
_numConnections :: Integer,
_proxy :: T.Text,
_generationDifficulty :: Double,
_onTestNetwork :: Bool,
_keyPoolOldest :: Integer,
_keyPoolSize :: Integer,
_transactionFeePaid :: Integer,
_unlockedUntil :: Maybe Integer,
_bitcoindErrors :: T.Text
} deriving ( Show )
makeLenses ''BitcoinInfo
instance FromJSON BitcoinInfo where
parseJSON (Object o) =
BitcoinInfo
<$> o .: "version"
<*> o .: "protocolversion"
<*> o .: "walletversion"
<*> o .: "balance"
<*> o .: "blocks"
<*> o .: "connections"
<*> o .: "proxy"
<*> o .: "difficulty"
<*> o .: "testnet"
<*> o .: "keypoololdest"
<*> o .: "keypoolsize"
<*> o .: "paytxfee"
<*> o .:? "unlocked_until"
<*> o .: "errors"
parseJSON _ = mzero
getInfo :: T.Client -> IO BitcoinInfo
getInfo client =
I.call client "getinfo" emptyArray