fn validate_version_range(
    since_version: u64,
    p: &CertifiedPayload,
) -> Result<u64, CertificationError> {
    let last_version = p
        .delta
        .keys()
        .try_fold(since_version, |prev_version, next_version| {
            if *next_version != prev_version + 1 {
                Err(CertificationError::InvalidDeltas(format!(
                    "version range not continuous: {} follows {}",
                    next_version, prev_version,
                )))
            } else {
                Ok(*next_version)
            }
        })?;

    if last_version == since_version && p.current_version.0 > since_version {
        return Err(CertificationError::InvalidDeltas(format!(
            "current version {} is newer than requested {}, but the payload has no deltas",
            p.current_version.0, since_version
        )));
    }

    Ok(p.current_version.0)
}
/// Validates that changes in the payload form a valid range.  We want to check
/// the following properties:
///
///   1. The version of the first delta is the successor of `since_version`.
///
///   2. Versions of deltas form a continuous range.
///
///   3. If current_version > since_version, the range contains at least one
///      delta.  Note that It is fine for the registry canister to not return
///      all entries up until the current version.  This can happen, e.g., if
///      the list of updates is too long for a single request.
Validates that changes in the payload form a valid range.  We want to check
the following properties.

1. The version of the first delta is the successor of `since_version`.

2. Versions of deltas form a continuous range.

3. If current_version > since_version, the range contains at least one
delta.  Note that It is fine for the registry canister to not return
all entries up until the current version.  This can happen, e.g., if
the list of updates is too long for a single request.
Validates that changes in the payload form a valid range . We want to check the following properties . 1 . The version of the first delta is the successor of ` since_version ` . 2 . Versions of deltas form a continuous range . 3 . If current_version > since_version the range contains at least one delta . Note that It is fine for the registry canister to not return all entries up until the current version . This can happen e . g . if the list of updates is too long for a single request .
fn validate_version_range(
    since_version: u64,
    p: &CertifiedPayload,
) -> Result<u64, CertificationError> {
    let last_version = p
        .delta
        .keys()
        .try_fold(since_version, |prev_version, next_version| {
            if *next_version != prev_version + 1 {
                Err(CertificationError::InvalidDeltas(format!(
                    "version range not continuous: {} follows {}",
                    next_version, prev_version,
                )))
            } else {
                Ok(*next_version)
            }
        })?;
    if last_version == since_version && p.current_version.0 > since_version {
        return Err(CertificationError::InvalidDeltas(format!(
            "current version {} is newer than requested {}, but the payload has no deltas",
            p.current_version.0, since_version
        )));
    }
    Ok(p.current_version.0)
}
fn validate_version_range ( since_version : u64 , p : & CertifiedPayload , ) -> Result < u64 , CertificationError > { let last_version = p . delta . keys ( ) . try_fold ( since_version , | prev_version , next_version | { if * next_version != prev_version + 1 { Err ( CertificationError :: InvalidDeltas ( format ! ( " " next_version prev_version ) ) ) } else { Ok ( * next_version ) } } ) ? ; if last_version == since_version && p . current_version . 0 > since_version { return Err ( CertificationError :: InvalidDeltas ( format ! ( " " p current_version 0 since_version ) ) ) ; } Ok ( p . current_version . 0 ) }
Validates that changes in the payload form a valid range.
Validates that changes in the payload form a valid range .
since_version
u64
p
&CertifiedPayload
since_version
u64
p
&CertifiedPayload