"""Local (private) API for a lightning node. Currently this just collects and exposes methods in channel and lightning. A HTML GUI could also be provided here in the future. All requests require authentication. """ from serverutil import api_factory, authenticate_before_request import channel, lightning API, REMOTE, Model = api_factory('local') REMOTE(channel.create) REMOTE(lightning.send) REMOTE(channel.close) REMOTE(channel.getbalance) REMOTE(channel.getcommitmenttransactions) @REMOTE def alive(): """Test if the server is ready to handle requests.""" return True API.before_request(authenticate_before_request)
"""Local (private) API for a lightning node. Currently this just collects and exposes methods in channel and lightning. A HTML GUI could also be provided here in the future. All requests require authentication. """ from serverutil import api_factory, authenticate_before_request import channel, lightning API, REMOTE = api_factory('local') REMOTE(channel.create) REMOTE(lightning.send) REMOTE(channel.close) REMOTE(channel.getbalance) REMOTE(channel.getcommitmenttransactions) API.before_request(authenticate_before_request)
fees: how much we require as fees for relaying across this channel ROUTES is the routing table. It has one row for every other lightning node address: their url cost: total fees to route payment to that node nexthop: where should payment go next on the path to that node """ import os.path import sqlite3 from flask import g import jsonrpcproxy from serverutil import api_factory, requires_auth import channel API, REMOTE = api_factory('lightning') def init(conf): """Set up the database.""" conf['lit_data_path'] = os.path.join(conf['datadir'], 'lightning.dat') if not os.path.isfile(conf['lit_data_path']): dat = sqlite3.connect(conf['lit_data_path']) with dat: dat.execute("CREATE TABLE PEERS(address, fees)") dat.execute("CREATE TABLE ROUTES(address, cost, nexthop)") @API.before_app_request def before_request(): """Connect to database."""
from sqlalchemy import Column, Integer, String, LargeBinary from flask import g from blinker import Namespace from bitcoin.core import COutPoint, CMutableTxOut, CMutableTxIn from bitcoin.core import CMutableTransaction from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH from bitcoin.core.script import CScript, SignatureHash, SIGHASH_ALL from bitcoin.core.script import OP_CHECKMULTISIG, OP_PUBKEY from bitcoin.wallet import CBitcoinAddress import jsonrpcproxy from serverutil import api_factory from serverutil import database from serverutil import ImmutableSerializableType, Base58DataType API, REMOTE, Model = api_factory('channel') SIGNALS = Namespace() CHANNEL_OPENED = SIGNALS.signal('CHANNEL_OPENED') class AnchorScriptSig(object): """Class representing a scriptSig satisfying the anchor output. Uses OP_PUBKEY to hold the place of your signature. """ def __init__(self, my_index=0, sig=b'', redeem=b''): if my_index == b'': my_index = 0 if my_index not in [0, 1]: raise Exception("Unknown index", my_index)
address: their url fees: how much we require as fees for relaying across this channel ROUTES is the routing table. It has one row for every other lightning node address: their url cost: total fees to route payment to that node nexthop: where should payment go next on the path to that node """ from flask import g import jsonrpcproxy from serverutil import api_factory, database import channel from sqlalchemy import Column, Integer, String API, REMOTE, Model = api_factory('lightning') class Peer(Model): """Database model of a peer node.""" __tablename__ = "peers" address = Column(String, primary_key=True) fees = Column(Integer) class Route(Model): """Database model of a route.""" __tablename__ = "routes"
""" import os.path import sqlite3 from flask import g from blinker import Namespace from bitcoin.core import CMutableOutPoint, CMutableTxOut, CMutableTxIn from bitcoin.core import CMutableTransaction from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH from bitcoin.core.script import CScript, SignatureHash, SIGHASH_ALL from bitcoin.core.script import OP_CHECKMULTISIG, OP_PUBKEY from bitcoin.wallet import CBitcoinAddress import jsonrpcproxy from serverutil import api_factory, requires_auth API, REMOTE = api_factory('channel') SIGNALS = Namespace() CHANNEL_OPENED = SIGNALS.signal('CHANNEL_OPENED') class AnchorScriptSig(object): """Class representing a scriptSig satisfying the anchor output. Uses OP_PUBKEY to hold the place of your signature. """ def __init__(self, my_index=0, sig=b'', redeem=b''): if my_index == b'': my_index = 0 if my_index not in [0, 1]: raise Exception("Unknown index", my_index)
address: their url fees: how much we require as fees for relaying across this channel ROUTES is the routing table. It has one row for every other lightning node address: their url cost: total fees to route payment to that node nexthop: where should payment go next on the path to that node """ from flask import g import jsonrpcproxy from serverutil import api_factory, database import channel from sqlalchemy import Column, Integer, String API, REMOTE, Model = api_factory('lightning') class Peer(Model): """Database model of a peer node.""" __tablename__ = "peers" address = Column(String, primary_key=True) fees = Column(Integer) class Route(Model): """Database model of a route.""" __tablename__ = "routes" address = Column(String, primary_key=True)