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

Method build_anchor_binding

atomic-repository/src/repository/anchor.rs:658–723  ·  view source on GitHub ↗

Build the signed Anchor payload for the current view/HEAD pair, reusing a byte-identical stored fact on repeat enables (RFC §5.1).

(
        &self,
        git: &GitRepository,
        view: &str,
        signer: &atomic_identity::keypair::KeyPair,
    )

Source from the content-addressed store, hash-verified

656 /// Build the signed Anchor payload for the current view/HEAD pair,
657 /// reusing a byte-identical stored fact on repeat enables (RFC §5.1).
658 fn build_anchor_binding(
659 &self,
660 git: &GitRepository,
661 view: &str,
662 signer: &atomic_identity::keypair::KeyPair,
663 ) -> Result<GitStateBinding, ShimAnchorError> {
664 let head = git
665 .head()
666 .ok()
667 .and_then(|head| head.target())
668 .ok_or_else(|| {
669 ShimAnchorError::Git("Git HEAD is not a direct commit reference".to_string())
670 })?;
671 let commit = git.find_commit(head).map_err(|error| {
672 ShimAnchorError::Git(format!("cannot read Git HEAD commit: {error}"))
673 })?;
674 let raw_commit = git
675 .odb()
676 .map_err(|error| ShimAnchorError::Git(format!("cannot open Git odb: {error}")))?
677 .read(head)
678 .map_err(|error| ShimAnchorError::Git(format!("cannot read raw HEAD commit: {error}")))?
679 .data()
680 .to_vec();
681
682 let identity = self.view_identity(view)?;
683 let ordered_changes: Vec<atomic_core::Hash> = self
684 .effective_history(Some(view))?
685 .iter()
686 .map(|entry| entry.hash)
687 .collect();
688 let operation = self.sole_working_copy_operation_head()?;
689
690 let mut payload = GitStateBindingPayload {
691 version: BINDING_VERSION,
692 git_object_format: object_format_for(&head)?,
693 git_commit: tagged_oid(&head)?,
694 git_tree: tagged_oid(&commit.tree_id())?,
695 git_parents: commit
696 .parent_ids()
697 .map(|parent| tagged_oid(&parent))
698 .collect::<Result<Vec<_>, _>>()?,
699 raw_commit_object: Some(raw_commit),
700 set_id: identity.set_id,
701 merkle_state: identity.merkle,
702 view_hint: Some(view.to_string()),
703 ordered_changes,
704 closure_root: atomic_core::Hash::from_bytes([0u8; 32]),
705 operation,
706 origin: CausalOrigin::ExactAtomicResurrection,
707 loss: Vec::new(),
708 provenance_roots: Vec::new(),
709 attestation_roots: Vec::new(),
710 signer: BindingSigner::for_keypair(signer),
711 };
712 payload.closure_root = payload.compute_closure_root();
713
714 // Idempotent retries: an identical stored fact is reused byte-for-byte.
715 if let Some(existing) = self.find_stored_identical_binding(&payload, signer)? {

Callers 1

Calls 15

GitClass · 0.85
object_format_forFunction · 0.85
tagged_oidFunction · 0.85
RepositoryClass · 0.85
view_identityMethod · 0.80
effective_historyMethod · 0.80
compute_closure_rootMethod · 0.80
okMethod · 0.45
headMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected