Milestone 3: RPC server, ZIP-320 #104

Merged
pitmutt merged 152 commits from milestone3 into master 2024-11-21 15:39:19 +00:00
4 changed files with 26 additions and 7 deletions
Showing only changes of commit b66d0d9563 - Show all commits

View file

@ -205,11 +205,12 @@ main = do
config <- load ["$(HOME)/Zenith/zenith.cfg"] config <- load ["$(HOME)/Zenith/zenith.cfg"]
args <- getArgs args <- getArgs
dbFilePath <- require config "dbFilePath" dbFilePath <- require config "dbFilePath"
{-nodeUser <- require config "nodeUser"-} nodeUser <- require config "nodeUser"
{-nodePwd <- require config "nodePwd"-} nodePwd <- require config "nodePwd"
zebraPort <- require config "zebraPort" zebraPort <- require config "zebraPort"
zebraHost <- require config "zebraHost" zebraHost <- require config "zebraHost"
let myConfig = Config dbFilePath zebraHost zebraPort nodePort <- require config "nodePort"
let myConfig = Config dbFilePath zebraHost zebraPort nodeUser nodePwd nodePort
if not (null args) if not (null args)
then do then do
case head args case head args

View file

@ -827,7 +827,13 @@ appEvent (BT.AppEvent t) = do
_ <- _ <-
liftIO $ liftIO $
syncWallet syncWallet
(Config (s ^. dbPath) (s ^. zebraHost) (s ^. zebraPort)) (Config
(s ^. dbPath)
(s ^. zebraHost)
(s ^. zebraPort)
"user"
"pwd"
8080)
selWallet selWallet
BT.modify $ set displayBox BlankDisplay BT.modify $ set displayBox BlankDisplay
BT.modify $ set barValue 0.0 BT.modify $ set barValue 0.0

View file

@ -92,12 +92,16 @@ data Config = Config
{ c_dbPath :: !T.Text { c_dbPath :: !T.Text
, c_zebraHost :: !T.Text , c_zebraHost :: !T.Text
, c_zebraPort :: !Int , c_zebraPort :: !Int
, c_zenithUser :: !BS.ByteString
, c_zenithPwd :: !BS.ByteString
, c_zenithPort :: !Int
} deriving (Eq, Prelude.Show) } deriving (Eq, Prelude.Show)
-- ** Zenith methods -- ** Zenith methods
data ZenithMethod data ZenithMethod
= GetInfo = GetInfo
| Test | Test
| UnknownMethod
deriving (Eq, Prelude.Show) deriving (Eq, Prelude.Show)
instance FromJSON ZenithMethod where instance FromJSON ZenithMethod where
@ -105,10 +109,11 @@ instance FromJSON ZenithMethod where
withText "ZenithMethod" $ \case withText "ZenithMethod" $ \case
"getinfo" -> pure GetInfo "getinfo" -> pure GetInfo
"test" -> pure Test "test" -> pure Test
_ -> fail "Invalid method" _ -> pure UnknownMethod
data ZenithParams data ZenithParams
= GetInfoParams = BlankParams
| BadParams
| TestParams !T.Text | TestParams !T.Text
deriving (Eq, Prelude.Show) deriving (Eq, Prelude.Show)
@ -127,7 +132,12 @@ instance FromJSON RpcCall where
i <- obj .: "id" i <- obj .: "id"
m <- obj .: "method" m <- obj .: "method"
case m of case m of
GetInfo -> pure $ RpcCall v i GetInfo GetInfoParams UnknownMethod -> pure $ RpcCall v i UnknownMethod BlankParams
GetInfo -> do
p <- obj .: "params"
if null (p :: [Value])
then pure $ RpcCall v i GetInfo BlankParams
else pure $ RpcCall v i GetInfo BadParams
Test -> do Test -> do
p <- obj .: "params" p <- obj .: "params"
pure $ RpcCall v i Test (TestParams $ head p) pure $ RpcCall v i Test (TestParams $ head p)

View file

@ -47,6 +47,7 @@ library
, base64-bytestring , base64-bytestring
, brick , brick
, bytestring , bytestring
, configurator
, data-default , data-default
, directory , directory
, filepath , filepath
@ -132,6 +133,7 @@ executable zenithserver
app app
build-depends: build-depends:
base >=4.12 && <5 base >=4.12 && <5
, configurator
, wai-extra , wai-extra
, warp , warp
, servant-server , servant-server