packages feed

clplug 0.3.3.0 → 0.4.0.0

raw patch · 3 files changed

+25/−20 lines, 3 filesdep +clplugdep −blitzPVP ok

version bump matches the API change (PVP)

Dependencies added: clplug

Dependencies removed: blitz

API changes (from Hackage documentation)

Files

README.md view
@@ -1,18 +1,21 @@  ## Core Lightning Plug -Create core lightning ([lightningd](https://lightning.readthedocs.io/PLUGINS.html)) plugins in haskell. +Create [Core Lightning](https://lightning.readthedocs.io/PLUGINS.html) plugins in haskell.  -To get started you need to import the Library. It is on hackage as [clplug](https://hackage.haskell.org/package/clplug) or you can load it from github in the stack.yaml: +To get started import the Library by adding it to your projects stack.yaml:  ``` extra-deps:-- git: https://github.com/autonomousorganization/blitz.git-  commit: a916dd3d74780e1023b161b4e85773ccc06051d4+- clplug-0.4.0.0 ```-Once the library is imported there are two external modules. Data.Lightning is all of the data types for the manifest, the notification and the hooks. Control.Plugin contains the monadic context and interface to your node. +Once the library is imported there are two main imports. +- Data.Lightning is all of the data types for the manifest, the notification and the hooks. +- Control.Plugin contains the monadic context and interface to your node.  -A [manifest](https://lightning.readthedocs.io/PLUGINS.html#the-getmanifest-method) defines the interface your plugin will have with core lightning. +The steps to create a plugin are:  +- A [manifest](https://lightning.readthedocs.io/PLUGINS.html#the-getmanifest-method) defines the interface your plugin will have with core lightning. + ``` import Data.Aeson import Data.Lightning@@ -29,8 +32,7 @@      ] ``` -A start function runs in the InitMonad, it has access to a reader (ask) and to lightningCli. The data that returns from this function will initialize the state that is shared in the PluginMonad. If you want to run a service fork a thread within this function. -The lightningCli function interfaces to core lightnings rpc. The available functions depend on your version of core lightning and the set of plugins you have installed. You need to pass a Command that defines the data you want returned in a [filter](https://lightning.readthedocs.io/lightningd-rpc.7.html?highlight=filter#field-filtering). +- A start function that returns the initial state.  ``` import Control.Plugin @@ -42,7 +44,7 @@     return < state > ``` -An app function runs every time data comes in from the plugin. You define handlers that processes the data. If an id is present that means that core lightning is expecting a response and default node operation or the operation of other plugins may be pending your response. Use release to allow default to continue, reject to abort default behavior, and respond to send a custom response which in the case of custom rpcmethods will pass through back to the user. +- An app function runs every time data comes in from the plugin. You define handlers that processes the data. If an id is present that means that core lightning is expecting a response and default node operation or the operation of other plugins may be pending your response. Use release to allow default to continue, reject to abort default behavior, and respond to send a custom response which in the case of custom rpcmethods will pass through back to the user.   ``` app :: (Maybe Id, Method, Params) -> PluginMonad a b@@ -52,7 +54,7 @@         else reject i       ```  -Finally use the plugin function to create an executable that can be installed as a plugin! +- Finally use the plugin function to create an executable that can be installed as a plugin!   ``` main :: IO ()
clplug.cabal view
@@ -1,13 +1,13 @@ cabal-version:      1.12 name:               clplug-version:            0.3.3.0+version:            0.4.0.0 license:            BSD3 license-file:       LICENSE copyright:          2023 maintainer:         taylorsingletonfookes@live.com author:             Taylor Singleton-Fookes-homepage:           https://github.com/AutonomousOrganization/blitz#readme-bug-reports:        https://github.com/AutonomousOrganization/blitz/issues+homepage:           https://github.com/AutonomousOrganization/clplug#readme+bug-reports:        https://github.com/AutonomousOrganization/clplug/issues synopsis:           Create Core Lightning Plugins description:     Library to create plugins to extend the functionality of Core Lightning daemon.@@ -20,7 +20,7 @@  source-repository head     type:     git-    location: https://github.com/AutonomousOrganization/blitz+    location: https://github.com/AutonomousOrganization/clplug  library     exposed-modules:@@ -68,8 +68,8 @@         aeson <2.1,         attoparsec <0.15,         base >=4.7 && <5,-        blitz,         bytestring <0.12,+        clplug,         conduit <1.4,         mtl <2.3,         network <3.2,
src/Control/Plugin.hs view
@@ -36,7 +36,6 @@ import Control.Concurrent hiding (yield)  import Network.Socket as N import System.IO-import Data.Conduit.Combinators (sinkNull)   -- | Function called on every event subscribed to in the manifest. type PluginApp a = PluginReq -> PluginMonad a ()@@ -58,6 +57,9 @@ data StartErr = ExpectManifest | ExpectInit deriving (Show, Exception)   -- | Create main executable that can be installed as core lightning plugin. +-- 1st arg is the manifest that configures the interface, 2nd arg is a function+-- with Plug reader that returns initial state, and 3rd arg is a function+-- that is called each time data is received.  plugin :: Value -> InitMonad s -> PluginApp s -> IO () plugin manifest start app = do      liftIO $ mapM_ (`hSetBuffering` LineBuffering) [stdin,stdout] @@ -83,7 +85,7 @@ runPlugin :: Plug -> s -> PluginApp s -> IO ()  runPlugin re st = (`evalStateT` st) . (`runReaderT` re) . forever . runConduit . runner     where-    runner app = sourceHandle stdin .| inConduit .| entry .| appInsert app -- .| _ -- sinkNull-- .| exit .| sinkHandle stdout +    runner app = sourceHandle stdin .| inConduit .| entry .| appInsert app  runOnce :: ConduitT (Either (Res Value) PluginReq) (Res Value) IO () -> IO ()  runOnce = runConduit.runner@@ -98,7 +100,9 @@  appInsert :: PluginApp a -> ConduitT (Either (Res Value) PluginReq) Void (PluginMonad a) ()  appInsert app = await >>= maybe mempty \case  -    Left fail -> pure () +    Left failed -> do+        Plug _ out _ <- ask+        liftIO $ runRes out failed      Right req -> lift (app req) >> pure ()   runRes :: Handle -> Res Value -> IO ()@@ -131,6 +135,5 @@     Plug _ out _ <- ask     liftIO $ runRes out $ Res v i  +getRpcPath :: InitConfig -> Text getRpcPath conf = lightning5dir conf <> "/" <> rpc5file conf--