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

Function validate_leaf_parent

atomic-core/src/crdt/apply/leaf.rs:395–415  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

393///
394/// `Ok(())` if the leaf belongs to the branch.
395pub 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

Callers 1

Calls 3

storage_errFunction · 0.85
get_leafMethod · 0.45
branchMethod · 0.45

Tested by 1