mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-13 14:09:50 +00:00
lnbase: add lnbase_test
This commit is contained in:
parent
23c32b9eda
commit
752f0379d3
4 changed files with 25 additions and 13 deletions
|
@ -21,6 +21,7 @@
|
||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import threading
|
import threading
|
||||||
import asyncio
|
import asyncio
|
||||||
import itertools
|
import itertools
|
||||||
|
|
|
@ -762,6 +762,11 @@ class Commands:
|
||||||
lightning.lightningCall(self.wallet.network.lightningrpc, lcmd)(*lightningargs)
|
lightning.lightningCall(self.wallet.network.lightningrpc, lcmd)(*lightningargs)
|
||||||
return q.get(block=True, timeout=600)
|
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:
|
def eval_bool(x: str) -> bool:
|
||||||
if x == 'false': return False
|
if x == 'false': return False
|
||||||
|
@ -771,7 +776,6 @@ def eval_bool(x: str) -> bool:
|
||||||
except:
|
except:
|
||||||
return bool(x)
|
return bool(x)
|
||||||
|
|
||||||
|
|
||||||
param_descriptions = {
|
param_descriptions = {
|
||||||
'privkey': 'Private key. Type \'?\' to get a prompt.',
|
'privkey': 'Private key. Type \'?\' to get a prompt.',
|
||||||
'destination': 'Bitcoin address, contact or alias',
|
'destination': 'Bitcoin address, contact or alias',
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
# - Standard_Wallet: one keystore, P2PKH
|
# - Standard_Wallet: one keystore, P2PKH
|
||||||
# - Multisig_Wallet: several keystores, P2SH
|
# - Multisig_Wallet: several keystores, P2SH
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
|
|
@ -331,8 +331,8 @@ class Peer(PrintError):
|
||||||
#def open_channel(self, funding_sat, push_msat):
|
#def open_channel(self, funding_sat, push_msat):
|
||||||
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))
|
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))
|
||||||
|
|
||||||
async def main_loop(self, loop):
|
async def main_loop(self):
|
||||||
self.reader, self.writer = await asyncio.open_connection(self.host, self.port, loop=loop)
|
self.reader, self.writer = await asyncio.open_connection(self.host, self.port)
|
||||||
await self.handshake()
|
await self.handshake()
|
||||||
# send init
|
# send init
|
||||||
self.send_message(gen_msg("init", gflen=0, lflen=0))
|
self.send_message(gen_msg("init", gflen=0, lflen=0))
|
||||||
|
@ -350,7 +350,7 @@ class Peer(PrintError):
|
||||||
self.print_error('closing lnbase')
|
self.print_error('closing lnbase')
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
|
||||||
async def channel_establishment_flow(self):
|
async def channel_establishment_flow(self, wallet):
|
||||||
await self.init_message_received_future
|
await self.init_message_received_future
|
||||||
pubkeys = get_unused_public_keys()
|
pubkeys = get_unused_public_keys()
|
||||||
temp_channel_id = os.urandom(32)
|
temp_channel_id = os.urandom(32)
|
||||||
|
@ -359,11 +359,11 @@ class Peer(PrintError):
|
||||||
self.send_message(msg)
|
self.send_message(msg)
|
||||||
try:
|
try:
|
||||||
accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
||||||
except LightningError:
|
|
||||||
return
|
|
||||||
finally:
|
finally:
|
||||||
del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
||||||
|
|
||||||
|
raise Exception("TODO: create funding transaction using wallet")
|
||||||
|
|
||||||
|
|
||||||
# replacement for lightningCall
|
# replacement for lightningCall
|
||||||
class LNWorker:
|
class LNWorker:
|
||||||
|
@ -371,19 +371,29 @@ class LNWorker:
|
||||||
def __init__(self, wallet, network):
|
def __init__(self, wallet, network):
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.network = network
|
self.network = network
|
||||||
self.loop = network.asyncio_loop
|
|
||||||
host, port, pubkey = ('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff')
|
host, port, pubkey = ('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff')
|
||||||
pubkey = binascii.unhexlify(pubkey)
|
pubkey = binascii.unhexlify(pubkey)
|
||||||
port = int(port)
|
port = int(port)
|
||||||
privkey = b"\x21"*32 + b"\x01"
|
privkey = b"\x21"*32 + b"\x01"
|
||||||
self.peer = Peer(privkey, host, port, pubkey)
|
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):
|
def openchannel(self):
|
||||||
# todo: get utxo from wallet
|
# todo: get utxo from wallet
|
||||||
# submit coro to asyncio main loop
|
# submit coro to asyncio main loop
|
||||||
self.peer.open_channel()
|
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 = [
|
node_list = [
|
||||||
('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff'),
|
('ecdsa.net', '9735', '038370f0e7a03eded3e1d41dc081084a87f0afa1c5b22090b4f3abb391eb15d8ff'),
|
||||||
|
@ -405,8 +415,5 @@ if __name__ == "__main__":
|
||||||
port = int(port)
|
port = int(port)
|
||||||
privkey = b"\x21"*32 + b"\x01"
|
privkey = b"\x21"*32 + b"\x01"
|
||||||
peer = Peer(privkey, host, port, pubkey)
|
peer = Peer(privkey, host, port, pubkey)
|
||||||
loop = asyncio.get_event_loop()
|
loop.run_until_complete(peer.main_loop())
|
||||||
async def asynctest():
|
|
||||||
await peer.channel_establishment_flow()
|
|
||||||
loop.run_until_complete(asyncio.gather(asynctest(), peer.main_loop(loop)))
|
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue