verify method

FakeAuditCheck verify({
  1. int? fromSeq,
  2. int? toSeq,
})

Checks the rows fromSeq to toSeq (both inclusive); without fromSeq it starts after lastCheckpointSeq (or at 1), without toSeq it ends at the last row.

Implementation

FakeAuditCheck verify({int? fromSeq, int? toSeq}) {
  final from = fromSeq ?? (lastCheckpointSeq ?? 0) + 1;
  final to = toSeq ?? rows.length;
  int? broken;
  String? reason;
  for (var seq = from; seq <= to && seq <= rows.length; seq++) {
    final row = rows[seq - 1];
    final prev = seq == 1 ? auditGenesisHash : rows[seq - 2]['hash'];
    if (row['prev_hash'] != prev) {
      broken = seq;
      reason = 'link_mismatch';
      break;
    }
    if (row['hash'] != hashOf(row)) {
      broken = seq;
      reason = 'hash_mismatch';
      break;
    }
  }
  return {
    'ok': broken == null,
    'checked_from_seq': from,
    'checked_to_seq': broken ?? to,
    'first_broken_seq': ?broken,
    'failure_reason': ?reason,
    'checkpoints_compared': lastCheckpointSeq == null ? 0 : 1,
    'last_checkpoint_seq': ?lastCheckpointSeq,
    'warnings': List.of(warnings),
  };
}