lightningd客户端库

pyln-client的Python项目详细描述


pyln客户机:一个用于lightningd的python客户机库

这个包实现了基于Unix套接字的JSON-RPC协议 lightningd向世界其他地方公开。它可以用来打电话 RPC接口上的任意函数,并作为插件的基础 用python编写。在

安装

pyln-clientpip上可用:

pip install pyln-client

或者,您也可以安装开发版本以访问 通过检查c-lightning源代码和 安装到python3环境中:

^{pr2}$

这将向您的环境中添加指向库的链接,以便更改 签出的源代码也会导致环境获取这些代码 变化。但是请注意,未发布的版本可能会在没有 警告,请使用发布的版本进行彻底测试。在

示例

使用JSON-RPC客户端

"""Generate invoice on one daemon and pay it on the other"""frompyln.clientimportLightningRpcimportrandom# Create two instances of the LightningRpc object using two different c-lightning daemons on your computerl1=LightningRpc("/tmp/lightning1/lightning-rpc")l5=LightningRpc("/tmp/lightning5/lightning-rpc")info5=l5.getinfo()print(info5)# Create invoice for test paymentinvoice=l5.invoice(100,"lbl{}".format(random.random()),"testpayment")print(invoice)# Get route to l1route=l1.getroute(info5['id'],100,1)print(route)# Pay invoiceprint(l1.sendpay(route['route'],invoice['payment_hash']))

编写插件

插件是lightningd可以配置为同时执行的程序 主守护程序。它们允许高级交互和自定义 守护进程。在

#!/usr/bin/env python3frompyln.clientimportPluginplugin=Plugin()@plugin.method("hello")defhello(plugin,name="world"):"""This is the documentation string for the hello-function.    It gets reported as the description when registering the function    as a method with `lightningd`.    """greeting=plugin.get_option('greeting')s='{}{}'.format(greeting,name)plugin.log(s)returns@plugin.init()definit(options,configuration,plugin):plugin.log("Plugin helloworld.py initialized")@plugin.subscribe("connect")defon_connect(plugin,id,address):plugin.log("Received connect event for peer {}".format(id))plugin.add_option('greeting','Hello','The greeting I should use.')plugin.run()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
关于持久性框架的java查询   java My JComponents占用了太多像素   来自保存结构化JSON对象的java错误请求   java一个面板上的鼠标侦听器如何使用另一个面板上对象的值?   java openGL在psuedo3d透视图中绘制扭曲的精灵(图像)   java更改行跨度   java如何在NatTable单元格中插入两个文本(每个文本具有不同的字体)和一个图像?设定利润率?   Objective和Java、iPhone和Android之间有什么巨大的区别吗?   JavaVLCJ在eclipse中播放rtsp流视频,但不是在制作可执行JAR之后   java如何访问原始图像数据   java如何检查未扩展的Ant属性   安卓如何从中获取文本视图。xml到Java文件   java Hibernate仅检索一列,另一列为null   使用java更新json对象   Android中带有networksecurityconfig的java SSL固定   面向对象Java对象拆卸模式   刷新期间java阻止对HashMap的访问   数组BufferedReader和流行Java 8