Commit 47695b37 authored by Pawan Dhananjay's avatar Pawan Dhananjay

Rpc handlers return a Maybe msg

parent 429cbe59
Pipeline #31230454 failed with stage
in 0 seconds
......@@ -19,10 +19,13 @@ rpcHandler ::
, HasRpc env r msg, MonadIO m)
=> Request 'Rpc (RpcPayload r msg)
-> m (Response 'Rpc (RpcPayload r msg))
rpcHandler (RpcRequest (RpcPayload resource msg)) = RpcResponse <$> do
rpcHandler (RpcRequest (RpcPayload resource msg)) = do
rpcRecord <- asks rpcEnv
let ResourceHandler h = rpcHandlers rpcRecord
RpcPayload resource <$> h msg
resp <- h msg
case resp of
Just response -> return (RpcResponse (RpcPayload resource response))
Nothing -> return (RpcResponse (RpcError ResourceNotFound))
rpcHandler (RpcRequest (RpcError _)) = error "Shouldn't get an error message as request"
......
......@@ -17,7 +17,7 @@ import GHC.Generics (Generic)
newtype Resourcers r = Resourcers (HM.HashMap r (TVar (Set NodeId)))
newtype ResourceHandler msg = ResourceHandler (forall m. (MonadIO m) => msg -> m msg)
newtype ResourceHandler msg = ResourceHandler (forall m. (MonadIO m) => msg -> m (Maybe msg))
data Options r = Options deriving (Eq, Ord, Show, Generic, Serialise)
......
......@@ -42,10 +42,10 @@ globalHandlerPubSub msg =
return Ok
else liftIO (Prelude.putStrLn "Error") >> return Error
globalHandlerRpc :: (MonadIO m) => String -> m String
globalHandlerRpc :: (MonadIO m) => String -> m (Maybe String)
globalHandlerRpc msg =
if msg == "HelloWorld" then return (msg ++ "Praise Satoshi")
else return ("msg" ++ "Fake satoshi")
if msg == "HelloWorld" then return (Just (msg ++ " Praise Satoshi"))
else return Nothing
getHelloWorld :: (HasP2PEnv env m ServiceResource ServiceTopic String String) => String -> m ()
getHelloWorld msg = do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment