Skip to content

Commit 7add868

Browse files
committed
feat: introduce 'serve' and 'query' commands
only 'serve' is implemented for now
1 parent a55c6bf commit 7add868

8 files changed

Lines changed: 185 additions & 185 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To run `db-server` over a `preprod` network database:
3636
Then from the source directory of `db-server`, starts the server with the following command:
3737

3838
```
39-
cabal run db-server -- --db db --config config/config.json
39+
cabal run db-server -- serve --db db --config config/config.json
4040
```
4141

4242
In the terminal, one should start seeing JSON-formatted log entries like:
@@ -55,7 +55,7 @@ The last entry above with the `HttpServerListening` signals the database is open
5555

5656
#### Retrieve header bytes
5757

58-
* `GET /:slot/:hash/header`: Retrieves raw hex-encoded bytes of a block header at given `:slot` and with given `:hash` (aka. _point_)
58+
* `GET /blocks/:slot/:hash/header`: Retrieves raw hex-encoded bytes of a block header at given `:slot` and with given `:hash` (aka. _point_)
5959
* `200` : Returns the raw hex-encoded bytes for header
6060
* `400` : Wrongly formatted `:slot` or `:hash` paths
6161
* `404` : No block exists at given point
@@ -69,7 +69,7 @@ The last entry above with the `HttpServerListening` signals the database is open
6969

7070
#### Retrieve block bytes
7171

72-
* `GET /:slot/:hash`: Retrieves raw hex-encoded CBOR bytes of a block at given `:slot` and with given `:hash` (aka. _point_)
72+
* `GET /blocks/:slot/:hash`: Retrieves raw hex-encoded CBOR bytes of a block at given `:slot` and with given `:hash` (aka. _point_)
7373
* `200` : Returns hex-encoded bytes for the block serialised as CBOR
7474
* `400` : Wrongly formatted `:slot` or `:hash` paths
7575
* `404` : No block exists at given point

app/DBServer/Options.hs

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/db-server.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
{-# LANGUAGE ApplicativeDo #-}
1+
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE NamedFieldPuns #-}
34

45
module Main (main) where
56

67
import Cardano.Crypto.Init (cryptoInit)
8+
import qualified Cardano.Tools.DBQuery as DBQuery
79
import qualified Cardano.Tools.DBServer as DBServer
8-
import DBServer.Options (Options (..), optsParser)
10+
import Cardano.Tools.DBServer.Options (Options (..), QueryOptions (..), ServeOptions (..), optsParser)
11+
import Control.Tracer (nullTracer)
912
import Main.Utf8 (withStdTerminalHandles)
1013
import Options.Applicative
1114
import System.IO (stdout)
@@ -14,5 +17,8 @@ main :: IO ()
1417
main = withStdTerminalHandles $
1518
DBServer.withLog stdout $ \tracer -> do
1619
cryptoInit
17-
Options{configurationFile, host, port, databaseDirectory} <- execParser optsParser
18-
DBServer.run tracer port host configurationFile databaseDirectory
20+
execParser optsParser >>= \case
21+
Serve ServeOptions {configurationFile, host, port, databaseDirectory} ->
22+
DBServer.run tracer port host configurationFile databaseDirectory
23+
Query QueryOptions {configurationFile, databaseDirectory, query} ->
24+
DBQuery.runQuery nullTracer configurationFile databaseDirectory query

db-server.cabal

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ library
5353
import: common-lib
5454
hs-source-dirs: src
5555
exposed-modules:
56+
Cardano.Tools.DBQuery
5657
Cardano.Tools.DBServer
5758
Cardano.Tools.DBServer.Options
5859

@@ -62,60 +63,24 @@ library
6263
base16-bytestring >=1.0,
6364
base64-bytestring,
6465
bytestring >=0.10 && <0.13,
65-
cardano-crypto,
6666
cardano-crypto-class,
67-
cardano-crypto-wrapper,
68-
cardano-git-rev ^>=0.2.1,
69-
cardano-ledger-allegra,
70-
cardano-ledger-alonzo,
7167
cardano-ledger-api,
72-
cardano-ledger-babbage,
7368
cardano-ledger-binary,
74-
cardano-ledger-byron,
75-
cardano-ledger-conway,
76-
cardano-ledger-core,
77-
cardano-ledger-mary,
78-
cardano-ledger-shelley,
79-
cardano-prelude,
80-
cardano-protocol-tpraos,
8169
cardano-slotting,
82-
cardano-strict-containers,
83-
cborg ^>=0.2.2,
84-
compact,
85-
containers >=0.5 && <0.8,
8670
contra-tracer,
87-
directory,
88-
filepath,
89-
fs-api,
90-
githash,
9171
http-types,
92-
microlens,
93-
mtl,
9472
network,
95-
network-mux,
96-
nothunks,
9773
optparse-applicative,
9874
ouroboros-consensus ^>= 0.21,
9975
ouroboros-consensus-cardano,
10076
ouroboros-consensus-diffusion,
101-
ouroboros-consensus-protocol:unstable-protocol-testlib,
10277
ouroboros-consensus-cardano:unstable-cardano-tools,
103-
ouroboros-consensus-protocol,
104-
ouroboros-network,
10578
ouroboros-network-api,
106-
ouroboros-network-framework,
107-
ouroboros-network-protocols,
108-
resource-registry,
109-
serialise,
110-
singletons,
79+
QuickCheck,
11180
sop-core,
11281
sop-extras,
113-
strict-sop-core,
11482
text,
115-
text-builder,
11683
time,
117-
transformers,
118-
transformers-except,
11984
wai,
12085
warp
12186

@@ -151,7 +116,6 @@ test-suite db-server-test
151116
filepath,
152117
hspec,
153118
http-types,
154-
mtl,
155119
temporary,
156120
text,
157121
unix,

src/Cardano/Tools/DBQuery.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE DerivingStrategies #-}
5+
module Cardano.Tools.DBQuery (runQuery) where
6+
7+
import Ouroboros.Consensus.Storage.ChainDB (TraceEvent)
8+
import Cardano.Tools.DBServer (StandardBlock)
9+
import GHC.Generics (Generic)
10+
import Data.Aeson (ToJSON (..), (.=), object)
11+
import Data.Text (Text)
12+
import Control.Tracer (Tracer)
13+
14+
data DBQueryLog = DBLog (TraceEvent StandardBlock)
15+
deriving stock (Eq, Show, Generic)
16+
17+
instance ToJSON DBQueryLog where
18+
toJSON = \case
19+
DBLog l -> object ["tag" .= ("ChainDB" :: Text), "log" .= show l]
20+
21+
runQuery :: Tracer IO DBQueryLog -> FilePath -> FilePath -> String -> IO ()
22+
runQuery tracer configurationFile databaseDirectory query =
23+
undefined

src/Cardano/Tools/DBServer.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Cardano.Tools.DBServer (
2020
run,
2121
DBServerLog (..),
2222
StandardPoint,
23+
StandardBlock,
2324
asInteger,
2425
pattern StandardPoint,
2526
withLog,

0 commit comments

Comments
 (0)