Python implementation of hobbits(wire protocol for ethereum 2.0 network testing)
- Code Review
- Pylint Score 9.87 / 10
- Python3
pip install -r requirements.txt
Encode a message
msg = {'protocol': 'EWP', 'call': 'RPC', 'version': '0.2', 'headers': '', 'body': '{"id":1,"method_id":0x00}'}
encoded = marshall(msg)
print(encoded)
Decode a message
msg = 'EWP 0.2 RPC 0 25\n{"id":1,"method_id":0x00}'
decoded = parse(msg)
print(decoded)
Here is a demo server
SERVER = create()
SERVER.bind(('127.0.0.1', 9000))
SERVER.listen(10)
while True:
CONN, ADDR = SERVER.accept()
print("Received client's request")
MSG = ''
while True:
DATA = CONN.recv(4096)
print(DATA)
if not DATA:
break
MSG += DATA.decode('utf-8')
print(MSG)
MIT © Pegasys