From 5421e9f6f2f61be28d8fa495ca72e51feae8c752 Mon Sep 17 00:00:00 2001 From: alaniz Date: Mon, 22 Jan 2018 21:44:37 +0000 Subject: [PATCH] pylightning: Add and move example to README --- contrib/pylightning/README.md | 34 ++++++++++++++++++++++ contrib/pylightning/lightning/lightning.py | 16 ---------- 2 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 contrib/pylightning/README.md diff --git a/contrib/pylightning/README.md b/contrib/pylightning/README.md new file mode 100644 index 000000000..66ace058c --- /dev/null +++ b/contrib/pylightning/README.md @@ -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'])) +``` diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index a6f050fc5..b59c82ecc 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -99,19 +99,3 @@ class LightningRpc(UnixDomainSocketRpc): msatoshi, {delay} blocks delay and {minblocks} minimum timeout """ 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']))