Validates that a leaf belongs to the specified branch. # Arguments `txn` - The transaction `leaf_id` - The leaf to validate `expected_branch` - The expected parent branch # Returns `Ok(())` if the leaf belongs to the branch.
(
txn: &T,
leaf_id: LeafId,
expected_branch: BranchId,
)
| 393 | /// |
| 394 | /// `Ok(())` if the leaf belongs to the branch. |
| 395 | pub fn validate_leaf_parent<T: MutCrdtTxnT>( |
| 396 | txn: &T, |
| 397 | leaf_id: LeafId, |
| 398 | expected_branch: BranchId, |
| 399 | ) -> ApplyResult<()> { |
| 400 | let leaf = txn |
| 401 | .get_leaf(leaf_id) |
| 402 | .map_err(|e| storage_err(e, "getting leaf"))? |
| 403 | .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?; |
| 404 | |
| 405 | if leaf.branch() != expected_branch { |
| 406 | return Err(ApplyError::internal(format!( |
| 407 | "Leaf {} belongs to branch {}, not {}", |
| 408 | leaf_id, |
| 409 | leaf.branch(), |
| 410 | expected_branch |
| 411 | ))); |
| 412 | } |
| 413 | |
| 414 | Ok(()) |
| 415 | } |
| 416 | |
| 417 | // Tests |
| 418 |