Applies a Restore operation to restore a deleted token. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is currently deleted 3. Updates the leaf's state to Alive # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is not deleted
(
txn: &mut T,
context: &mut ApplyContext,
leaf_id: LeafId,
)
| 313 | /// - `LeafNotFound` - The leaf doesn't exist |
| 314 | /// - `InvalidLeafState` - The leaf is not deleted |
| 315 | fn apply_restore<T: MutCrdtTxnT>( |
| 316 | txn: &mut T, |
| 317 | context: &mut ApplyContext, |
| 318 | leaf_id: LeafId, |
| 319 | ) -> ApplyResult<()> { |
| 320 | // Verify leaf exists |
| 321 | let leaf = txn |
| 322 | .get_leaf(leaf_id) |
| 323 | .map_err(|e| storage_err(e, "getting leaf"))? |
| 324 | .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?; |
| 325 | |
| 326 | // Check current state |
| 327 | if !leaf.state().is_deleted() { |
| 328 | if context.options().allow_duplicate_ids() { |
| 329 | context.record_skipped(); |
| 330 | return Ok(()); |
| 331 | } |
| 332 | return Err(ApplyError::invalid_leaf_state(leaf_id, "alive", "restore")); |
| 333 | } |
| 334 | |
| 335 | // Update state to alive |
| 336 | txn.update_leaf_state(leaf_id, LeafState::Alive) |
| 337 | .map_err(|e| storage_err(e, "updating leaf state"))?; |
| 338 | |
| 339 | context.record_leaf_restored(); |
| 340 | Ok(()) |
| 341 | } |
| 342 | |
| 343 | // Validation Helpers |
| 344 |
no test coverage detected