commit 9617447a0f9c5e850bd198134eef25bb42311d38
parent 70dd4d123569b0978086104e2275fd57aa49751f
Author: Janus <ysangkok@gmail.com>
Date: Thu, 12 Apr 2018 14:14:41 +0200
lnbase: add lnbase_test
Diffstat:
4 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -21,6 +21,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+import asyncio
import threading
import asyncio
import itertools
diff --git a/electrum/commands.py b/electrum/commands.py
@@ -779,6 +779,11 @@ class Commands:
lightning.lightningCall(self.wallet.network.lightningrpc, lcmd)(*lightningargs)
return q.get(block=True, timeout=600)
+ @command("wn")
+ def lnbase_test(self):
+ if not self.network.config.get("lnbase", False):
+ return "You need to pass --lnbase to the daemon starting command to run the lnbase test"
+ return self.wallet.lnworker.blocking_test_run()
def eval_bool(x: str) -> bool:
if x == 'false': return False
@@ -788,7 +793,6 @@ def eval_bool(x: str) -> bool:
except:
return bool(x)
-
param_descriptions = {
'privkey': 'Private key. Type \'?\' to get a prompt.',
'destination': 'Bitcoin address, contact or alias',
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -26,7 +26,7 @@
# - Standard_Wallet: one keystore, P2PKH
# - Multisig_Wallet: several keystores, P2SH
-
+import asyncio
import os
import sys
import random
diff --git a/lib/lnbase.py b/lib/lnbase.py
@@ -331,8 +331,8 @@ class Peer(PrintError):
#def open_channel(self, funding_sat, push_msat):
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))
- async def main_loop(self, loop):
- self.reader, self.writer = await asyncio.open_connection(self.host, self.port, loop=loop)
+ async def main_loop(self):
+ self.reader, self.writer = await asyncio.open_connection(self.host, self.port)
await self.handshake()
# send init
self.send_message(gen_msg("init", gflen=0, lflen=0))
@@ -350,7 +350,7 @@ class Peer(PrintError):
self.print_error('closing lnbase')
self.writer.close()
- async def channel_establishment_flow(self):
+ async def channel_establishment_flow(self, wallet):
await self.init_message_received_future
pubkeys = get_unused_public_keys()
temp_channel_id = os.urandom(32)
@@ -359,11 +359,11 @@ class Peer(PrintError):
self.send_message(msg)
try:
accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
- except LightningError:
- return
finally:
del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
+ raise Exception("TODO: create funding transaction using wallet")
+
# replacement for lightningCall
class LNWorker:
@@ -371,19 +371,29 @@ class LNWorker:
def __init__(self, wallet, network):
self.wallet = wallet
self.network = network
- self.loop = network.asyncio_loop
host, port, pubkey = ('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff')
pubkey = binascii.unhexlify(pubkey)
port = int(port)
privkey = b"\x21"*32 + b"\x01"
self.peer = Peer(privkey, host, port, pubkey)
- self.network.futures.append(asyncio.run_coroutine_threadsafe(self.peer.main_loop(self.loop), self.loop))
+ self.network.futures.append(asyncio.run_coroutine_threadsafe(self.peer.main_loop(), asyncio.get_event_loop()))
def openchannel(self):
# todo: get utxo from wallet
# submit coro to asyncio main loop
self.peer.open_channel()
+ def blocking_test_run(self):
+ start = time.time()
+ fut = asyncio.ensure_future(self._test())
+ asyncio.get_event_loop().run_until_complete(fut)
+ fut.exception()
+ return "blocking test run took: " + str(time.time() - start)
+
+ async def _test(self):
+ await self.peer.channel_establishment_flow(self.wallet)
+
+
node_list = [
('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff'),
@@ -405,8 +415,5 @@ if __name__ == "__main__":
port = int(port)
privkey = b"\x21"*32 + b"\x01"
peer = Peer(privkey, host, port, pubkey)
- loop = asyncio.get_event_loop()
- async def asynctest():
- await peer.channel_establishment_flow()
- loop.run_until_complete(asyncio.gather(asynctest(), peer.main_loop(loop)))
+ loop.run_until_complete(peer.main_loop())
loop.close()