Define link from Agent ID

I want to define a type of link that goes from an “Agent ID” entry (the entry where the hashed content is the public key of an agent) to one of my own entry types.

Based on the docs for entry! and the docs for link!, it seems that when you’re defining a link coming from a system entry, you should choose the “from” direction and specify the “other entry type” as the name of that system entry.

Like this

#[entry_def]
fn foo_def() -> ValidatingEntryType {
    entry!(
        name: "foo",
        description: "bar",
        sharing: Sharing::Public,
        validation_package: || { hdk::ValidationPackageDefiniton::Entry },
        validation: | my_entry: hdk::EntryValidationData<Foo>| { Ok(()) },
        links: [
            link!(
                direction: hdk::LinkDirection::From,
                other_type: "..." // what do I put for agent ID?
                link_type: "baz",
                validation_package: || { hdk::ValidationPackageDefinition::Entry },
                validation: |_, _, _| Ok(()),
            )
        ]
    )
}

However, as pointed out in the above code snippet, I don’t know what to put for other_type. What should I put for other_type?

Hey @timotree3! Good to meet you; I hear you’re contributing some work to HC core; that’s exciting.

In most examples I’ve seen, you can do this with the literal "%agent_id". Literals make me feel uncomfortable, so I’d recommend EntryType::AgentID.into() and then you’re guaranteed something that’s not going to break on you. And as you can see from the source code, the string conversion is sys_prefix!("agent_id"), and the sys_prefix! macro just tags a "%" onto the beginning of a string. So for now it amounts to the same thing, but I like using the enum because future-proofing.

Oh! I almost forgot! I believe there’s a bug in Holochain that prevents links on the agent Id from propagating through the DHT. It might be fixed though.

1 Like

Any news if this bug has been fixed?
I believe the problem is that agentId entries are not public and so do not propagated on the DHT. Thus when linking from your (private) agentId entry other nodes can’t find the base address.
The DNA entry does not have this problem as every node should already have the same entry locally.