clplug 0.3.1.0 → 0.3.2.0
raw patch · 2 files changed
+22/−7 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Client: [____id] :: Command -> Value
- Control.Client: [method] :: Command -> Text
- Control.Client: [params] :: Command -> Value
- Control.Client: [reqFilter] :: Command -> Value
+ Control.Client: [$sel:____id:Command] :: Command -> Value
+ Control.Client: [$sel:method:Command] :: Command -> Text
+ Control.Client: [$sel:params:Command] :: Command -> Value
+ Control.Client: [$sel:reqFilter:Command] :: Command -> Maybe Value
+ Control.Client: instance GHC.Show.Show Control.Client.PartialCommand
- Control.Client: Command :: Text -> Value -> Value -> Value -> Command
+ Control.Client: Command :: Text -> Maybe Value -> Value -> Value -> Command
- Control.Client: lightningCliDebug :: (String -> IO ()) -> PartialCommand -> PluginMonad a (Maybe (Res Value))
+ Control.Client: lightningCliDebug :: (MonadReader PlugInfo m, MonadIO m) => (String -> IO ()) -> PartialCommand -> m (Maybe (Res Value))
Files
- clplug.cabal +1/−1
- src/Control/Client.hs +21/−6
clplug.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: clplug-version: 0.3.1.0+version: 0.3.2.0 license: BSD3 license-file: LICENSE copyright: 2023
src/Control/Client.hs view
@@ -5,6 +5,9 @@ , DeriveAnyClass , GeneralizedNewtypeDeriving , FlexibleContexts+ , DuplicateRecordFields+ , TypeSynonymInstances+ , FlexibleInstances #-} module Control.Client (@@ -29,7 +32,10 @@ import Data.Text type PartialCommand = Id -> Command +instance Show PartialCommand where + show x = show $ (x "") + {-# NOINLINE idref #-} idref :: IORef Int idref = unsafePerformIO $ newIORef 1@@ -37,21 +43,28 @@ -- | commands to core lightning are defined by the set of plugins and version of core lightning so this is generic and you should refer to lightning-cli help <command> for the details of the command you are interested in. A filter object is used to specify the data you desire returned (i.e. {"id":True}) and params are the named fields of the command. data Command = Command { method :: Text- , reqFilter :: Value+ , reqFilter :: Maybe Value , params :: Value , ____id :: Value } deriving (Show) instance ToJSON Command where - toJSON (Command m f p i) = + toJSON (Command m Nothing p i) = object [ "jsonrpc" .= ("2.0" :: Text) , "id" .= i+ , "method" .= m + , "params" .= toJSON p+ ]+ toJSON (Command m (Just f) p i) = + object [ "jsonrpc" .= ("2.0" :: Text)+ , "id" .= i , "filter" .= toJSON f , "method" .= m , "params" .= toJSON p ] -- | interface with lightning-rpc. -lightningCli :: (MonadReader PlugInfo m, MonadIO m) => PartialCommand -> m (Maybe (Res Value))+lightningCli :: (MonadReader PlugInfo m, MonadIO m) => + PartialCommand -> m (Maybe (Res Value)) lightningCli v = do (h, _) <- ask i <- liftIO $ atomicModifyIORef idref $ (\x -> (x,x)).(+1)@@ -61,9 +74,11 @@ _ -> pure Nothing -- | log wrapper for easier debugging during development.-lightningCliDebug :: (String -> IO ()) -> PartialCommand -> PluginMonad a (Maybe (Res Value))+lightningCliDebug :: (MonadReader PlugInfo m, MonadIO m) => + (String -> IO ()) -> PartialCommand -> m (Maybe (Res Value)) lightningCliDebug logger v = do - res@(Just (Res x _)) <- lightningCli v - liftIO . logger . show $ x + liftIO . logger . show $ v+ res <- lightningCli v + liftIO . logger . show $ res pure res