Skip to content

Commit

Permalink
capitalize adt for convinience
Browse files Browse the repository at this point in the history
  • Loading branch information
sigrlami committed Dec 19, 2020
1 parent 0729c57 commit e6cc1f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 50 deletions.
30 changes: 16 additions & 14 deletions src/Factom/RPC/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

module Factom.RPC.Api
( runTCPClient
, reqHeights
, reqCurrentMinute
) where

import Control.Concurrent
import Control.Exception (bracket)
import Control.Exception (bracket)
import Control.Monad.IO.Class
import Control.Remote.Monad.JSON
import Control.Remote.Monad.JSON.Client
Expand All @@ -23,25 +25,25 @@ import Control.Remote.Monad.JSON.Trace
import Data.Aeson
import Data.Aeson.Types
import Data.Text
import Network.Socket (HostName, ServiceName,
SocketType (Stream),
addrAddress, addrFamily,
addrProtocol, addrSocketType,
close, connect, defaultHints,
getAddrInfo, socket)

import Factom.RPC.JsonRpc (JsonRpcT, runJsonRpcT)
import Network.Socket (HostName, ServiceName,
SocketType (Stream),
addrAddress, addrFamily,
addrProtocol,
addrSocketType, close,
connect, defaultHints,
getAddrInfo, socket)

import Factom.RPC.JsonRpc (JsonRpcT, runJsonRpcT)
import Factom.RPC.Types.AdminBlock
import Factom.RPC.Types.Heights
import Factom.RPC.Types.DirectoryBlockHeader
import Factom.RPC.Types.DirectoryBlock
import Factom.RPC.Types.DirectoryBlockHeader
import Factom.RPC.Types.Heights

--------------------------------------------------------------------------------

endpoint = "http://192.168.0.182:8088/v2"
endpoint = "http://51.158.171.20:8088/v2"
endpointRemote = "https://api.factomd.net/v2" -- "http://dev.factomd.net/v2"


runTCPClient :: HostName -> ServiceName -> JsonRpcT IO a -> IO a
runTCPClient host port f = do
addr <- resolve host port
Expand Down Expand Up @@ -216,7 +218,7 @@ reqHeights =
--------------------------------------------------------------------------------

main = do
let s = weakSession (traceSendAPI "" $ clientSendAPI endpoint)
let s = weakSession (traceSendAPI "" $ clientSendAPI endpointRemote)
h <- send s $ do
h <- reqHeights --ablockByHeight 1000
return h
Expand Down
57 changes: 21 additions & 36 deletions src/Factom/RPC/Types/Heights.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@
module Factom.RPC.Types.Heights where

import Control.Applicative
import Control.Monad ( forM_
, join
, mzero
)
import Data.Aeson ( FromJSON(..)
, ToJSON(..)
, Value(..)
, decode
, object
, pairs
, (.:)
, (.:?)
, (.=)
)
import Control.Monad (forM_, join, mzero)
import Data.Aeson (FromJSON (..), ToJSON (..),
Value (..), decode, object,
pairs, (.:), (.:?), (.=))
import Data.Aeson.AutoType.Alternative
import qualified Data.ByteString.Lazy.Char8 as BSL
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Monoid
import Data.Text ( Text )
import Data.Text (Text)
import qualified GHC.Generics
import System.Environment ( getArgs )
import System.Exit ( exitFailure
, exitSuccess
)
import System.IO ( hPutStrLn
, stderr
)
import System.Environment (getArgs)
import System.Exit (exitFailure, exitSuccess)
import System.IO (hPutStrLn, stderr)

--------------------------------------------------------------------------------

Expand All @@ -42,13 +28,12 @@ o .:?? val = fmap join (o .:? val)

data Heights =
Heights
{ hLeaderheight :: Double
, hDirectoryblockheight :: Double
, hEntryblockheight :: Double
, hEntryheight :: Double
{ hLeaderHeight :: Double
, hDirectoryBlockHeight :: Double
, hEntryBlockHeight :: Double
, hEntryHeight :: Double
} deriving (Show, Eq, GHC.Generics.Generic)


instance FromJSON Heights where
parseJSON (Object v) =
Heights
Expand All @@ -64,18 +49,18 @@ instance FromJSON Heights where

instance ToJSON Heights where
toJSON (Heights {..}) = object
[ "leaderheight" .= hLeaderheight
, "directoryblockheight" .= hDirectoryblockheight
, "entryblockheight" .= hEntryblockheight
, "entryheight" .= hEntryheight
[ "leaderheight" .= hLeaderHeight
, "directoryblockheight" .= hDirectoryBlockHeight
, "entryblockheight" .= hEntryBlockHeight
, "entryheight" .= hEntryHeight
]
toEncoding (Heights {..}) = pairs
( "leaderheight"
.= hLeaderheight
.= hLeaderHeight
<> "directoryblockheight"
.= hDirectoryblockheight
.= hDirectoryBlockHeight
<> "entryblockheight"
.= hEntryblockheight
.= hEntryBlockHeight
<> "entryheight"
.= hEntryheight
.= hEntryHeight
)

0 comments on commit e6cc1f7

Please sign in to comment.