How to calculate the address of an entry without actually submitting it?

Hi guys,

Everything is in the title : is there a way to calculate the address of an entry without actually submitting it?

Thanks!

I think what @ReversedK is looking for is entry_address … takes an Entry:App struct and returns the address that it would get committed to, if it were committed to the chain…
https://developer.holochain.org/api/v0.0.32-alpha2/hdk/api/fn.entry_address.html

3 Likes

Thank you @Connoropolous! We appreciate your support. It’s awesome to see you on the Forum! We miss you!

Excellent! Thanks Connor!

1 Like

Is there a way to do this without touching (importing) the HDK?

I’m trying to get unit tests to work by mocking the results of commit_entry and ```entry_address, but I cannot find a way to calculate the Address for an Entry without loading WASM/DHT code.

Found the answer here: https://github.com/holochain/holochain-rust/blob/9564458505299c668fbf7fb311eaad86a07c6551/crates/core_types/src/entry/mod.rs#L107

use holochain_core_types::entry::*;
use holochain_persistence_api::cas::content::{AddressableContent, Content};

pub fn entry_address(entry: &Entry) -> ZomeApiResult<Address> {
    Ok(Address::encode_from_str(&String::from(entry.content()), Hash::SHA2256))
}
1 Like