core-lightning/contrib/pyln-proto/examples/connect.py
Christian Decker 3418e59d76 pyln: Split pylightning into multiple pyln modules
This is the first step to transition to a better organized python module
structure. Sadly we can't reuse the `pylightning` module as a namespace module
since having importable things in the top level of the namespace is not
allowed in any of the namespace variants [1], hence we just switch over to the
`pyln` namespace. The code the was under `lightning` will now be reachable
under `pyln.client` and we add the `pyln.proto` module for all the things that
are independent of talking to lightningd and can be used for protocol testing.

[1] https://packaging.python.org/guides/packaging-namespace-packages/

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-09-30 13:27:37 +02:00

28 lines
787 B
Python

#!/usr/bin/env python3
"""Simple connect and read test
Connects to a peer, performs handshake and then just prints all the messages
it gets.
"""
from pyln.proto.wire import connect, PrivateKey, PublicKey
from binascii import unhexlify, hexlify
ls_privkey = PrivateKey(unhexlify(
b'1111111111111111111111111111111111111111111111111111111111111111'
))
remote_pubkey = PublicKey(unhexlify(
b'03b31e5bbf2cdbe115b485a2b480e70a1ef3951a0dc6df4b1232e0e56f3dce18d6'
))
lc = connect(ls_privkey, remote_pubkey, '127.0.0.1', 9375)
# Send an init message, with no global features, and 0b10101010 as local
# features.
lc.send_message(b'\x00\x10\x00\x00\x00\x01\xaa')
# Now just read whatever our peer decides to send us
while True:
print(hexlify(lc.read_message()).decode('ASCII'))