mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-12 10:30:29 +01:00
pylightning: Add and move example to README
This commit is contained in:
parent
96d093fb30
commit
5421e9f6f2
2 changed files with 34 additions and 16 deletions
34
contrib/pylightning/README.md
Normal file
34
contrib/pylightning/README.md
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# pylightning: A python client library for lightningd
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
You need to have the futures python library installed to be able to use pylightning:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install futures
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```py
|
||||||
|
from pylightning import LightningRpc
|
||||||
|
import random
|
||||||
|
|
||||||
|
# Create two instances of the LightningRpc object using two different c-lightning daemons on your computer
|
||||||
|
l1 = LightningRpc("/tmp/lightning1/lightning-rpc")
|
||||||
|
l5 = LightningRpc("/tmp/lightning5/lightning-rpc")
|
||||||
|
|
||||||
|
info5 = l5.getinfo()
|
||||||
|
print(info5)
|
||||||
|
|
||||||
|
# Create invoice for test payment
|
||||||
|
invoice = l5.invoice(100, "lbl{}".format(random.random()), "testpayment")
|
||||||
|
print(invoice)
|
||||||
|
|
||||||
|
# Get route to l1
|
||||||
|
route = l1.getroute(info5['id'], 100, 1)
|
||||||
|
print(route)
|
||||||
|
|
||||||
|
# Pay invoice
|
||||||
|
print(l1.sendpay(route['route'], invoice['payment_hash']))
|
||||||
|
```
|
|
@ -99,19 +99,3 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||||
msatoshi, {delay} blocks delay and {minblocks} minimum timeout
|
msatoshi, {delay} blocks delay and {minblocks} minimum timeout
|
||||||
"""
|
"""
|
||||||
return self._call("dev-add-route", [src, dst, base, var, delay, minblocks])
|
return self._call("dev-add-route", [src, dst, base, var, delay, minblocks])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
l1 = LightningRpc("/tmp/lightning1/lightning-rpc")
|
|
||||||
l5 = LightningRpc("/tmp/lightning5/lightning-rpc")
|
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
info5 = l5.getinfo()
|
|
||||||
print(info5)
|
|
||||||
invoice = l5.invoice(100, "lbl{}".format(random.random()), "testpayment")
|
|
||||||
print(invoice)
|
|
||||||
route = l1.getroute(info5['id'], 100, 1)
|
|
||||||
print(route)
|
|
||||||
print(l1.sendpay(route['route'], invoice['payment_hash']))
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue