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,
)
| 204 | /// |
| 205 | /// `Ok(())` if the change can be applied, or an error describing why not. |
| 206 | pub 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)] |
| 235 | mod tests { |
no test coverage detected