Updating entries and listing them

Hi all -

I am trying to update entries in a private source chain.

I create the entry like this, with an anchor and a path:

let entry_input = blah blah
create_entry(&entry_input)?;
let entry_input_hash = hash_entry(&entry_input)?;
let path = anchor_path(AgentPubKey::from(agent_info()?.agent_latest_pubkey.clone()));
path.ensure()?;
create_link(path.hash()?, entry_input_hash.clone(), ())?;

The anchor is specified by agentpubkey to avoid hotspotting.

Next I want to update an entry. I get the headerhash and update it with this function:

#[hdk_extern]
pub fn update_entry(header_hash: HeaderHash) -> ExternResult<HeaderHash> {
    let agent_info = agent_info()?;

    hdk::prelude::update_entry(header_hash.clone(),EntryStruct{
        EntryStructFields: newdata
    })
}

I can use the returned header hash to validate that the entry has been made.

The problem is that I am using a general ‘list entries’ function and - after making this update - I am expecting the relevant entry to change, but it does not. The ‘list entries’ function I use is like this:

pub fn list_entries() -> ExternResult<Vec<EntryOutput>> {
    let path = anchor_path(AgentPubKey::from(agent_info()?.agent_latest_pubkey.clone()));
    let links = get_links(path.hash()?, None)?;
    let mut results = vec![];
    for a in links
        .iter()
        {
            let entrys = utils::try_get_and_convert::<EntryStruct>(HoloHash::from(a.target.clone()))?;
            results.push(EntryStructOutput{
                entry_hash:HoloHash::from(a.target.clone()),
                entry:entrys
            })
        }
        return Ok(results);
}

This function always returns the same entries, even if I update or delete one of them. Is this expected? Do I also have to do some updating of links or something?

I get that the original entry still exists in the source chain, but I presumed that the update_entry function would also take care of paths and links but possibly not. Any advice here much appreciated.
Thanks - alex.

1 Like

something else I notice is that if I instead try to delete this entry completely, then my ‘list_entries’ function just fails.

For example, I have 4 entries and I use this function to delete the last one:

pub fn delete_record(header_hash: HeaderHash) -> ExternResult<HeaderHash> {
    hdk::prelude::delete_entry(header_hash)
}

Now I expect that if I call the ‘list_entries’ function then it returns only the first 3 entries. However, what happens is that I get this error:

19:26:27 [tryorama] e[31merrore[39m: Test error: {
          type: 'error',
          data: {
            type: 'ribosome_error',
            data: 'Wasm error while working with Ribosome: Guest("Could not find entry")'
          }
        }

It might be a totally different issue, but can anyone help me understand why I am not simply getting back the 3 entries that haven’t been deleted??

1 Like