estimate min height
This commit is contained in:
18
iavlread
18
iavlread
@@ -11,9 +11,9 @@ def decode_protobuf(subformats: dict, format_prefix: str, data: bytes):
|
||||
idx = f'{format_prefix}.{k}'
|
||||
if idx in subformats:
|
||||
f = subformats[idx]
|
||||
if f == 'proto':
|
||||
if f == 'pb':
|
||||
decoded_value = decode_protobuf(subformats, idx, v)
|
||||
elif f == 'protodict':
|
||||
elif f == 'pbdict':
|
||||
decoded_value = dict(decode_protobuf(subformats, idx, v))
|
||||
else:
|
||||
decoded_value = decode_output(f, v)
|
||||
@@ -53,10 +53,10 @@ def decode_output(format: str, data: bytes) -> str:
|
||||
return struct.unpack('>H', data[:4])[0] - (1<<15)
|
||||
elif format == 'i8ord':
|
||||
return struct.unpack('>B', data[:4])[0] - (1<<7)
|
||||
elif format.startswith('protodict'):
|
||||
elif format.startswith('pbdict'):
|
||||
subformats = {'.' + id: subformat for x in format.split(',')[1:] for id, subformat in (x.split('='),)}
|
||||
return dict(decode_protobuf(subformats, '', data))
|
||||
elif format.startswith('proto'):
|
||||
elif format.startswith('pb'):
|
||||
subformats = {'.' + id: subformat for x in format.split(',')[1:] for id, subformat in (x.split('='),)}
|
||||
return decode_protobuf(subformats, '', data)
|
||||
else:
|
||||
@@ -72,6 +72,9 @@ def get_args():
|
||||
|
||||
subparsers = parser.add_subparsers(required=True, dest='cmd')
|
||||
p_max_height = subparsers.add_parser('max_height', help = 'Get the max block height in the snapshot')
|
||||
p_max_height.add_argument('prefix', help = 'Prefix (e.g. "s/k:emissions/")')
|
||||
p_min_height = subparsers.add_parser('min_height', help = 'Get the min block height in the snapshot')
|
||||
p_min_height.add_argument('prefix', help = 'Prefix (e.g. "s/k:emissions/")')
|
||||
p_get = subparsers.add_parser('get', help = 'Retrieve a single item')
|
||||
p_get.add_argument('prefix', help = 'Prefix (e.g. "s/k:emissions/")')
|
||||
p_get.add_argument('key', nargs='+', help = 'Key parts')
|
||||
@@ -95,7 +98,7 @@ def run(args):
|
||||
keyformat = args.keyformat if args.keyformat is not None else ''
|
||||
valueformat = args.valueformat if args.valueformat is not None else 'b'
|
||||
|
||||
if args.cmd == 'max_height' or args.key is None or len(args.key) == 0:
|
||||
if args.cmd == 'max_height' or args.cmd == 'min_height' or args.key is None or len(args.key) == 0:
|
||||
key = None
|
||||
else:
|
||||
if len(args.key) > len(keyformat) + 1:
|
||||
@@ -109,12 +112,15 @@ def run(args):
|
||||
|
||||
with plyvel.DB(dbpath) as db:
|
||||
if args.height is None or args.cmd == 'max_height':
|
||||
height = iavltree.max_height(db)
|
||||
height = iavltree.max_height(db, args.prefix.encode('utf-8'))
|
||||
else:
|
||||
height = args.height
|
||||
|
||||
if args.cmd == 'max_height':
|
||||
print(height)
|
||||
elif args.cmd == 'min_height':
|
||||
hmin, _ = iavltree.min_max_height(db, args.prefix.encode('utf-8'))
|
||||
print(hmin)
|
||||
elif args.cmd == 'get':
|
||||
result = iavltree.get(db, args.prefix, height, keyformat, key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user