rollbackToChecksum method

Future<SdkResult<T>> rollbackToChecksum(
  1. String checksum
)

ENH-96 (withHistory only): re-activates the verified revision whose checksum is checksum — re-verifies it was indeed in history (never trusts an caller-supplied checksum blindly), persists it as the current cache entry, appends a fresh history entry recording WHEN the rollback itself happened (so the audit trail shows the rollback as its own event, not a silent rewrite of the original entry's timestamp), and only then swaps _current. Returns SdkFailure (no mutation at all) if no history entry matches.

Implementation

Future<SdkResult<T>> rollbackToChecksum(String checksum) async {
  _ensureHistoryLoaded();
  final match = _history.cast<_HistoryRecord?>().lastWhere(
    (r) => r!.checksum == checksum,
    orElse: () => null,
  );
  if (match == null) {
    return const SdkFailure(
      kind: SdkErrorKind.validation,
      message: 'No history entry matches that checksum',
    );
  }
  return _activateHistoryRecord(match);
}