Exemple #1
0
    def start(self):
        self.proc = subprocess.Popen([
            '{}/lightningd/lightningd'.format(
                LIGHTNING_SRC), '--lightning-dir={}'.format(
                    self.lightning_dir), '--funding-confirms=3',
            '--dev-force-tmp-channel-id=0000000000000000000000000000000000000000000000000000000000000000',
            '--dev-force-privkey=0000000000000000000000000000000000000000000000000000000000000001',
            '--dev-force-bip32-seed=0000000000000000000000000000000000000000000000000000000000000001',
            '--dev-force-channel-secrets=0000000000000000000000000000000000000000000000000000000000000010/0000000000000000000000000000000000000000000000000000000000000011/0000000000000000000000000000000000000000000000000000000000000012/0000000000000000000000000000000000000000000000000000000000000013/0000000000000000000000000000000000000000000000000000000000000014/FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
            '--dev-bitcoind-poll=1', '--dev-fast-gossip',
            '--dev-gossip-time=1565587763', '--bind-addr=127.0.0.1:{}'.format(
                self.lightning_port), '--network=regtest',
            '--bitcoin-rpcuser=rpcuser', '--bitcoin-rpcpassword=rpcpass',
            '--bitcoin-rpcport={}'.format(
                self.bitcoind.port), '--log-level=debug', '--log-file=log'
        ] + self.startup_flags)
        self.rpc = lightning.LightningRpc(
            os.path.join(self.lightning_dir, "regtest", "lightning-rpc"))

        def node_ready(rpc):
            try:
                rpc.getinfo()
                return True
            except Exception:
                return False

        if not wait_for(lambda: node_ready(self.rpc)):
            raise subprocess.TimeoutExpired(self.proc,
                                            "Could not contact lightningd")

        # Make sure that we see any funds that come to our wallet
        for i in range(5):
            self.rpc.newaddr()
Exemple #2
0
def main():
    for node in nodes:
        ln_dir = f"/tmp/l{node + 1}-regtest/regtest"
        ln = lightning.LightningRpc(f"{ln_dir}/lightning-rpc")
        pubkey = ln.getinfo()["id"]
        logger.info(f"Node {node +1}:")
        logger.info(f"privkey: {get_privkey(ln_dir, pubkey)}")
        logger.info(f"pubkey:  {pubkey}")
Exemple #3
0
from flask import Flask, render_template, jsonify, request
import os
import random
import string
import lightning

app = Flask(__name__)
lnClient = lightning.LightningRpc(os.path.expanduser("~/.lightning/lightning-rpc"))

@app.route("/")
def home():
    return render_template("lntips.html")
    
@app.route("/getinvoice")
def getInvoice():
    value = request.args.get("value")
    label = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16))
    invoice = lnClient.invoice(value, label, "Donation to aspinall.io")
    return jsonify({"payment_request": invoice["bolt11"], "payment_hash": invoice["payment_hash"]})

@app.route("/invoicestatus")
def getInvoiceStatus():
    rhash = request.args.get("rhash")
    if not rhash:
        return jsonify(False)
    invoices = lnClient.listinvoices()["invoices"]
    invMatch = [i for i in invoices if i["payment_hash"] == rhash]
    if invMatch:
        status = invMatch[0]["status"]
        if status == "paid":
            return jsonify(True)
import sys
import config
import graphene
import lightning

from pprint import pprint

cl = lightning.LightningRpc(sys.argv[1])


class Invoice(graphene.ObjectType):
    id = graphene.String()
    label = graphene.String()
    bolt11 = graphene.String()
    payment_hash = graphene.String()
    pay_index = graphene.Int()
    msatoshi = graphene.Int()
    amount_msat = graphene.String()
    msatoshi_received = graphene.Int()
    amount_sent_msat = graphene.String()
    msatoshi_sent = graphene.Int()
    amount_received_msat = graphene.String()
    status = graphene.String()
    paid_at = graphene.Int()
    expires_at = graphene.Int()
    created_at = graphene.Int()
    expiry = graphene.Int()
    description = graphene.String()
    payment_preimage = graphene.String()
    destination = graphene.String()
    # WTF
Exemple #5
0
from flask import Flask, render_template
import lightning
import os
from collections import defaultdict

sockPath = os.path.join(os.environ["HOME"], ".lightning", "lightning-rpc")
l = lightning.LightningRpc(sockPath)

app = Flask(__name__)

@app.route("/")
def channels():
    peers = l.listpeers()["peers"]
    channels = defaultdict(list)
    nodes = l.listnodes()["nodes"]
    for peer in peers:
        aliases = [n["alias"] for n in nodes if n["nodeid"] == peer["id"]]
        alias = aliases[0] if aliases else "Unknown"
        for channel in peer.get("channels", []):
            channel["alias"] = alias
            channels[channel["state"]].append(channel)
    return render_template("channels.html", channels=channels)

def main():
    app.run(port=8081, host="0.0.0.0")

if __name__ == "__main__":
    main()