mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 07:23:25 +00:00
lnbase: expose wallet object in LNWorker
This commit is contained in:
parent
567dfe62e3
commit
23c32b9eda
1 changed files with 13 additions and 17 deletions
|
@ -334,16 +334,13 @@ class Peer(PrintError):
|
||||||
async def main_loop(self, loop):
|
async def main_loop(self, loop):
|
||||||
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, loop=loop)
|
||||||
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))
|
||||||
|
|
||||||
# read init
|
# read init
|
||||||
msg = await self.read_message()
|
msg = await self.read_message()
|
||||||
self.process_message(msg)
|
self.process_message(msg)
|
||||||
|
# initialized
|
||||||
self.init_message_received_future.set_result(msg)
|
self.init_message_received_future.set_result(msg)
|
||||||
|
|
||||||
# loop
|
# loop
|
||||||
while True:
|
while True:
|
||||||
self.ping_if_required()
|
self.ping_if_required()
|
||||||
|
@ -355,9 +352,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
async def channel_establishment_flow(self):
|
async def channel_establishment_flow(self):
|
||||||
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)
|
||||||
msg = gen_msg("open_channel", temporary_channel_id=temp_channel_id, chain_hash=bytes.fromhex(rev_hex(constants.net.GENESIS)), funding_satoshis=20000, max_accepted_htlcs=5, funding_pubkey=next(pubkeys), revocation_basepoint=next(pubkeys), htlc_basepoint=next(pubkeys), payment_basepoint=next(pubkeys), delayed_payment_basepoint=next(pubkeys), first_per_commitment_point=next(pubkeys))
|
msg = gen_msg("open_channel", temporary_channel_id=temp_channel_id, chain_hash=bytes.fromhex(rev_hex(constants.net.GENESIS)), funding_satoshis=20000, max_accepted_htlcs=5, funding_pubkey=next(pubkeys), revocation_basepoint=next(pubkeys), htlc_basepoint=next(pubkeys), payment_basepoint=next(pubkeys), delayed_payment_basepoint=next(pubkeys), first_per_commitment_point=next(pubkeys))
|
||||||
self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id] = asyncio.Future()
|
self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id] = asyncio.Future()
|
||||||
|
@ -369,23 +364,24 @@ class Peer(PrintError):
|
||||||
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]
|
||||||
|
|
||||||
# check that it is in my pending requests
|
|
||||||
# I need to attach a wallet to each request
|
|
||||||
if ok:
|
|
||||||
tx = wallet.create_funding_tx()
|
|
||||||
wallet.sign(tx)
|
|
||||||
m = gen_msg('funding created', signature)
|
|
||||||
self.send_message(m)
|
|
||||||
|
|
||||||
# replacement for lightningCall
|
# replacement for lightningCall
|
||||||
class LNWallet(Wallet):
|
class LNWorker:
|
||||||
|
|
||||||
def __init__(self, wallet, peer):
|
def __init__(self, wallet, network):
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.peer = peer
|
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))
|
||||||
|
|
||||||
def openchannel(self):
|
def openchannel(self):
|
||||||
# todo: get utxo from wallet
|
# todo: get utxo from wallet
|
||||||
|
# submit coro to asyncio main loop
|
||||||
self.peer.open_channel()
|
self.peer.open_channel()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue