electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d8eedf514d437c68d4361c7af23a39bda5f396aa
parent fc2864cb63048047ca5a7a218921640880c0cc24
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 11 Apr 2018 13:53:51 +0200

lnbase: add draft handlers

Diffstat:
Mlib/lnbase.py | 37+++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -288,15 +288,37 @@ class Peer(PrintError): def process_message(self, message): message_type, payload = decode_msg(message) self.print_error("Received '%s'" % message_type.upper(), payload) - if message_type == 'ping': - l = int.from_bytes(payload['num_pong_bytes'], byteorder="big") - self.send_message(gen_msg('pong', byteslen=l)) - elif message == 'channel_update': - pass - - def open_channel(self): + try: + f = getattr(self, 'on_' + message_type) + except AttributeError: + return + f(payload) + + def on_ping(self, payload): + l = int.from_bytes(payload['num_pong_bytes'], byteorder="big") + self.send_message(gen_msg('pong', byteslen=l)) + + def on_accept_channel(self, payload): + # 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) + + def on_funding_signed(self, payload): + sig = payload['signature'] + channel_id = payload['channel_id'] + tx = self.channels[channel_id] + self.network.broadcast(tx) + + def on_funding_locked(self, payload): pass + 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) await self.handshake() @@ -345,4 +367,3 @@ if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(peer.main_loop(loop)) loop.close() -