f-o-a-m / kepler

A Haskell framework that facilitates writing ABCI applications
https://kepler.dev
Apache License 2.0
34 stars 10 forks source link

Error when building RPC query client which contains module with EmptyQueryServer #259

Closed UnitylChaos closed 3 years ago

UnitylChaos commented 3 years ago

I'm trying to build the RPC client interfaces for my project by following pattern in the tutorial and running into an error.

Some of the relevant code:

type NodeModules =
  '[ V.Validators
   , Assets.Assets
   , Signals.Signals
   , Context.Context
   ]

-- Validators
getPowerOf :: QueryArgs PubKey_ -> RPC.TendermintM (QueryClientResponse Word64)
getValidatorsKeys :: QueryArgs () -> RPC.TendermintM (QueryClientResponse KeySet)
getValidators :: RPC.TendermintM (QueryClientResponse (Map.Map PubKey_ Word64))

-- Assets
getAsset :: QueryArgs Hash -> RPC.TendermintM (QueryClientResponse Asset)

-- Context
getHeight :: QueryArgs () -> RPC.TendermintM (QueryClientResponse Height)
getRealTime :: QueryArgs () -> RPC.TendermintM (QueryClientResponse RealTime)

(getPowerOf :<|> getValidatorsKeys :<|> getValidators) :<|> getAsset :<|> _ :<|> (getHeight :<|> getRealTime) =
  genClientQ (Proxy :: Proxy m) queryApiP def
  where
    queryApiP :: Proxy (M.ApplicationQ NodeModules)
    queryApiP = Proxy

Validators, Assets, and Context have actual query interfaces, but Signals moduleQuerier is EmptyQueryServer.

    • No instance for (HasQueryClient
                         (ReaderT RPC.Config IO)
                         Tendermint.SDK.BaseApp.Query.Types.EmptyQueryServer)
        arising from a use of ‘genClientQ’
    • In the expression: genClientQ (Proxy :: Proxy m) queryApiP def
      In a pattern binding:
        (getPowerOf :<|> getValidatorsKeys :<|> getValidators) :<|> getAsset :<|> _ :<|> (getHeight :<|> getRealTime)
          = genClientQ (Proxy :: Proxy m) queryApiP def
          where
              queryApiP :: Proxy (M.ApplicationQ NodeModules)
              queryApiP = Proxy
   |
51 |   genClientQ (Proxy :: Proxy m) queryApiP def

Not sure if this is a bug or if I'm doing the construction wrong. (The tutorial didn't address modules without a query server)

P.S. It seems like this code may be intended to deal with this? https://github.com/f-o-a-m/kepler/blob/9bf5781786101541af04c843af2b949c9f770b40/hs-abci-test-utils/src/Tendermint/Utils/QueryClient/Class.hs#L155

martyall commented 3 years ago

Yes that code is meant to deal with that, does your project import that module ? Even an empty import list is ok.

UnitylChaos commented 3 years ago

Yeah, I was importing it through Tendermint.Utils.Client, but switching it to a direct import of Tendermint.Utils.QueryClient.Class gives the same error.

It seems like there's nothing linking this to EmptyQueryServer. Is it possible this is just a typo and it's supposed to be:

instance HasQueryClient m EmptyQueryServer where
  type ClientQ m EmptyQueryServer = EmptyQueryClient

  genClientQ _ _ _ = EmptyQueryClient
UnitylChaos commented 3 years ago

Adding that code to my file fixes the build error, so I think that should fix it. Will PR

martyall commented 3 years ago

Yes, that's definitely a typo. Nice catching that!