From 6e6cec309787d672ffac8b8fe6dbbace2132b668 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 11 Apr 2018 11:02:10 +0200 Subject: [PATCH] integrate lnbase with network --- electrum/commands.py | 3 ++- lib/lnbase.py | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index a3b918091..9cfa7d3e6 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -935,7 +935,8 @@ def add_global_options(parser): group.add_argument("--testnet", action="store_true", dest="testnet", default=False, help="Use Testnet") group.add_argument("--regtest", action="store_true", dest="regtest", default=False, help="Use Regtest") group.add_argument("--simnet", action="store_true", dest="simnet", default=False, help="Use Simnet") - group.add_argument("--lightning", action="store_true", dest="lightning", default=False, help="Enable Lightning support") + group.add_argument("--lightning", action="store_true", dest="lightning", default=False, help="Enable Lightning support via hub") + group.add_argument("--lnbase", action="store_true", dest="lnbase", default=False, help="Enable Lightning support") def get_parser(): # create main parser diff --git a/lib/lnbase.py b/lib/lnbase.py index 9b84560f1..cafdb9706 100644 --- a/lib/lnbase.py +++ b/lib/lnbase.py @@ -18,6 +18,7 @@ import cryptography.hazmat.primitives.ciphers.aead as AEAD from electrum.bitcoin import public_key_from_private_key, ser_to_point, point_to_ser, string_to_number from electrum.bitcoin import int_to_hex, bfh, rev_hex from electrum.util import PrintError +from electrum.wallet import Wallet tcp_socket_timeout = 10 server_response_timeout = 60 @@ -111,7 +112,6 @@ def gen_msg(msg_type, **kwargs): data += param return data -############################### def decode(string): @@ -309,6 +309,9 @@ class Peer(PrintError): elif message == 'channel_update': pass + def open_channel(self): + pass + async def main_loop(self, loop): self.reader, self.writer = await asyncio.open_connection(self.host, self.port, loop=loop) await self.handshake() @@ -323,12 +326,20 @@ class Peer(PrintError): msg = await self.read_message() self.process_message(msg) # close socket + self.print_error('closing lnbase') self.writer.close() + + +# replacement for lightningCall +class LNWallet(Wallet): - def run(self): - loop = asyncio.get_event_loop() - loop.run_until_complete(self.main_loop(loop)) - loop.close() + def __init__(self, wallet, peer): + self.wallet = wallet + self.peer = peer + + def openchannel(self): + # todo: get utxo from wallet + self.peer.open_channel() node_list = [ @@ -346,4 +357,7 @@ if __name__ == "__main__": port = int(port) privkey = b"\x21"*32 + b"\x01" peer = Peer(privkey, host, port, pubkey) - peer.run() + loop = asyncio.get_event_loop() + loop.run_until_complete(peer.main_loop(loop)) + loop.close() +