lightning-network: A Haskell interface for the Lightning Network

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Tools for working with payments on the Lightning Netowrk and interacting with a Lightning Network node through its REST API.


[Skip to Readme]

Properties

Versions 1.0.0.0
Change log CHANGELOG.md
Dependencies aeson (>=1.3 && <1.5), base (>=4.7 && <4.15), base64-bytestring (>=0.1 && <1.1), bytestring (>=0.9 && <0.11), containers (>=0.5 && <0.7), http-client (>=0.5 && <0.7), lightning-network, random (>=1.0 && <1.2), servant (>=0.14 && <0.17), servant-auth (>=0.3 && <0.4), servant-client (>=0.14 && <0.17), servant-client-core (>=0.14 && <0.17), text (>=0.1 && <1.3), time (>=1.8 && <1.9) [details]
License MPL-2.0
Copyright 2020 Serokell
Author Kirill Elagin <kirelagin@serokell.io>
Maintainer Kirill Elagin <kirelagin@serokell.io>
Category Bitcoin, Finance, Network
Home page https://github.com/serokell/lightning-network#readme
Bug tracker https://github.com/serokell/lightning-network/issues
Source repo head: git clone https://github.com/serokell/lightning-network
Uploaded by kirelagin at 2020-05-04T19:50:15Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for lightning-network-1.0.0.0

[back to package description]

Lightning Network (lightning-network)

A Haskell interface for the Lightning Network.

Tools for working with payments on the Lightning Netowrk and interacting with a Lightning Network node through its REST API.

Use

Overview

  1. Use Authorization.Macaroon.load to read a macaroon from a file.
  2. Import servant Api from Lightning.Node.Api.
  3. Generate a servant client for this Api.
  4. Use the client to talk to a node.

Macaroon

import qualified Authorization.Macaroon as Mac

And then use Mac.load to read your macaroon from a file.

Generic client

A generic client will give you back a record whose fields will contain functions for accessing the API.

You will have to add these to your dependencies:

Here is how to get a top-level generic client:

import Servant.API.Generic (fromServant)
import Servant.Client (Client, ClientM)
import Servant.Client.Generic (AsClientT, genericClient)

import Lightning.Node.Api (Api (_v1), ApiV1 (..))

import qualified Lightning.Node.Api as L


api :: Api (AsClientT ClientM)
api = genericClient

Digging deeper to get actual endpoints is a little tricky (for example, see this issue). In order to unwrap the next level of the API, you will already need your macaroon (see the previous section).

TODO: Come up with a better way.

_getInfo :: ClientM L.NodeInfo
_genInvoice :: L.InvoiceReq -> ClientM L.InvoiceRep
_pay :: L.PayReq -> ClientM L.PayRep

ApiV1
  { _getInfo
  , _genInvoice
  , _pay
  } = fromServant @_ @(AsClientT ClientM) (_v1 api macaroon)

Non-generic client

Alternatively, you can generate a plain non-generic servant client.

You will have to add these to your dependencies:

import Data.Proxy (Proxy (Proxy))
import Servant.API ((:<|>) ((:<|>)))
import Servant.API.Generic (ToServantApi)
import Servant.Client (Client, ClientM, client)
import Lightning.Node.Api (Api)

import Authorization.Macaroon (Macaroon)
import qualified Lightning.Node.Api as L


api :: Client ClientM (ToServantApi Api)
api = client (Proxy :: Proxy (ToServantApi Api))

_getInfo :: ClientM L.NodeInfo
_genInvoice :: L.InvoiceReq -> ClientM L.InvoiceRep
_pay :: L.PayReq -> ClientM L.PayRep

_getInfo :<|> _genInvoice :<|> _pay = api macaroon

Contributing

If you encounter any issues when using this library or have improvement ideas, please open report in issue on GitHub. You are also very welcome to submit pull request, if you feel like doing so.

License

MPL-2.0 © Serokell