-
Notifications
You must be signed in to change notification settings - Fork 2
/
Api.hs
114 lines (95 loc) · 3.32 KB
/
Api.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeOperators #-}
module ChainwebData.Api where
------------------------------------------------------------------------------
import Data.Aeson
import Data.Proxy
import Data.Text (Text)
import GHC.Generics
import Servant.API
------------------------------------------------------------------------------
import Chainweb.Api.ChainId
import Chainweb.Api.Common
import ChainwebData.EventDetail
import ChainwebData.TransferDetail
import ChainwebData.Pagination
import ChainwebData.TxSummary
import ChainwebData.TxDetail
------------------------------------------------------------------------------
chainwebDataApi :: Proxy ChainwebDataApi
chainwebDataApi = Proxy
type ChainwebDataApi = ("txs" :> TxApi)
:<|> ("stats" :> Get '[JSON] ChainwebDataStats)
:<|> ("coins" :> Get '[PlainText] Text)
type TxApi
= RecentTxsApi
:<|> TxSearchApi
:<|> EventsApi
:<|> TxDetailApi
:<|> TxsDetailApi
:<|> AccountApi
type RecentTxsApi = "recent"
:> Get '[JSON] [TxSummary]
type TxSearchApi = "search"
:> LimitParam
:> OffsetParam
:> SearchParam
:> PactIdParam
:> QueryParam "minheight" BlockHeight
:> QueryParam "maxheight" BlockHeight
:> NextTokenParam
:> Get '[JSON] (NextHeaders [TxSummary])
newtype RequestKey = RequestKey Text
deriving instance FromHttpApiData RequestKey
deriving instance ToHttpApiData RequestKey
type TxDetailApi = "tx"
:> QueryParam "requestkey" RequestKey
:> Get '[JSON] TxDetail
type TxsDetailApi = "txs"
:> QueryParam "requestkey" RequestKey
:> Get '[JSON] [TxDetail]
newtype EventParam = EventParam Text
deriving instance FromHttpApiData EventParam
deriving instance ToHttpApiData EventParam
newtype EventName = EventName Text
deriving instance FromHttpApiData EventName
deriving instance ToHttpApiData EventName
newtype EventModuleName = EventModuleName Text
deriving instance FromHttpApiData EventModuleName
deriving instance ToHttpApiData EventModuleName
type EventsApi = "events"
:> LimitParam
:> OffsetParam
:> SearchParam
:> QueryParam "param" EventParam
:> QueryParam "name" EventName
:> QueryParam "modulename" EventModuleName
:> QueryParam "minheight" BlockHeight
:> QueryParam "maxheight" BlockHeight
:> NextTokenParam
:> Get '[JSON] (NextHeaders [EventDetail])
type AccountApi = "account"
:> Capture "account-name" Text
:> QueryParam "token" Text
:> QueryParam "chain" ChainId
:> QueryParam "minheight" BlockHeight
:> QueryParam "maxheight" BlockHeight
:> LimitParam
:> OffsetParam
:> NextTokenParam
:> Get '[JSON] (NextHeaders [TransferDetail])
data ChainwebDataStats = ChainwebDataStats
{ _cds_transactionCount :: Maybe Int
, _cds_coinsInCirculation :: Maybe Double
} deriving (Eq,Ord,Show,Generic)
jsonOpts :: Options
jsonOpts = defaultOptions { fieldLabelModifier = drop 5 }
instance ToJSON ChainwebDataStats where
toEncoding = genericToEncoding jsonOpts
toJSON = genericToJSON jsonOpts
instance FromJSON ChainwebDataStats where
parseJSON = genericParseJSON jsonOpts