chia-blockchain/chia/util/pprint.py
Adam Kelly db19671827
Check Wallet DB integrity (#14401)
* Check Wallet DB integrity

* Update command line help

* Improve duplicate DerivationPath index error message

* Move tests to chia/tests

* lint

* py init file

* Print WalletType names

* Don't complain about wallets not having derivation entries that don't need them

* Validate addresses used in order

* Update tests with new error output

* Fix check_addresses_used_contiguous in the case when the last address of the previous wallet was unused
2023-02-21 18:35:15 -06:00

41 lines
884 B
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import List
@dataclass
class Range:
first: int
last: int
def __repr__(self) -> str:
if self.first == self.last:
return f"{self.first}"
else:
return f"{self.first} to {self.last}"
def int_list_to_ranges(array: List[int]) -> List[Range]:
if len(array) == 0:
return []
sorted_array = sorted(array)
first = sorted_array[0]
last = first
ranges = []
for i in sorted_array[1:]:
if i == last:
pass
elif i == last + 1:
last = i
else:
ranges.append(Range(first, last))
first = i
last = i
ranges.append(Range(first, last))
return ranges
def print_compact_ranges(array: List[int]) -> str:
return str(int_list_to_ranges(array))