validateChangeset method

  1. @protected
Hlc validateChangeset(
  1. CrdtChangeset changeset
)

Checks if changeset is valid. This method is intended for implementations and shouldn't generally be called from outside.

Returns the highest hlc in the changeset or the canonical time, if higher.

Implementation

@protected
Hlc validateChangeset(CrdtChangeset changeset) {
  var hlc = canonicalTime;
  // Iterate through all the incoming timestamps to:
  // - Check for invalid entries (throws exception)
  // - Update local canonical time if needed
  changeset.forEach((table, records) {
    for (final record in records) {
      try {
        hlc = hlc.merge(record['hlc'] as Hlc);
      } catch (e) {
        throw MergeError(e, table, record);
      }
    }
  });
  return hlc;
}