historian: Add a command to read a snapshot and hexdump it to stdout

This commit is contained in:
Christian Decker
2020-08-28 14:39:38 +02:00
parent efdf985352
commit c22562bd7f

View File

@@ -6,7 +6,7 @@ from sqlalchemy.orm import sessionmaker
from sqlalchemy import func
from datetime import datetime, timedelta
import click
from pyln.proto.primitives import varint_encode
from pyln.proto.primitives import varint_encode, varint_decode
import os
from sqlalchemy.orm import load_only
@@ -154,5 +154,20 @@ def full(ctx, destination, db):
ctx.invoke(incremental, since=since, destination=destination, db=db)
@snapshot.command()
@click.argument('snapshot', type=click.File('rb'))
def read(snapshot):
while True:
l = varint_decode(snapshot)
if l is None:
break
msg = snapshot.read(l)
if len(msg) != l:
raise ValueError("Incomplete read at end of file")
print(msg.hex())
if __name__ == "__main__":
cli()