MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_can_apply

Function validate_can_apply

atomic-core/src/apply/change.rs:206–232  ·  view source on GitHub ↗

Check if applying a change would succeed (without actually applying). This performs validation checks: - Change not already on view - All dependencies present # Arguments `txn` - The transaction to check against `view` - The view to check `change_id` - The internal ID of the change `change_hash` - The hash of the change `change` - The change to validate # Returns `Ok(())` if the change can be

(
    txn: &T,
    view: &ViewState,
    change_id: NodeId,
    change_hash: &Hash,
    change: &Change,
)

Source from the content-addressed store, hash-verified

204///
205/// `Ok(())` if the change can be applied, or an error describing why not.
206pub fn validate_can_apply<T: ViewTxnT + GraphTxnT>(
207 txn: &T,
208 view: &ViewState,
209 change_id: NodeId,
210 change_hash: &Hash,
211 change: &Change,
212) -> Result<(), LocalApplyError> {
213 // Check if already applied
214 if is_change_on_view(txn, view, change_id).map_err(|e| LocalApplyError::Internal {
215 message: format!("Failed to check view: {}", e),
216 })? {
217 return Err(LocalApplyError::ChangeAlreadyApplied { hash: *change_hash });
218 }
219
220 // Check dependencies
221 let missing = verify_dependencies(txn, change).map_err(|e| LocalApplyError::Internal {
222 message: format!("Failed to verify dependencies: {}", e),
223 })?;
224
225 if let Some(first_missing) = missing.first() {
226 return Err(LocalApplyError::DependencyMissing {
227 hash: *first_missing,
228 });
229 }
230
231 Ok(())
232}
233
234#[cfg(test)]
235mod tests {

Callers 1

write_change_to_graphFunction · 0.85

Calls 2

is_change_on_viewFunction · 0.85
verify_dependenciesFunction · 0.85

Tested by

no test coverage detected