[][src]Function hdk::get_entry

pub fn get_entry<T>(address: HashString) -> Result<Option<T>, ZomeApiError> where
    T: DeserializeOwned

Retrieves an entry from the local chain or the DHT, by looking it up using its address.


pub fn handle_get_post(post_address: HashString) -> serde_json::Value {
    // get_entry returns a Result<Option<T>, ZomeApiError>
    // where T is the type that you used to commit the entry, in this case a Blog
    // It's a ZomeApiError if something went wrong (i.e. wrong type in deserialization)
    // Otherwise its a Some(T) or a None
    let result : Result<Option<Post>,ZomeApiError> = hdk::get_entry(post_address);
    match result {
        // In the case we don't get an error
        // it might be an entry ...
        Ok(Some(post)) => json!(post),
        Ok(None) =>  json!({}),
        Err(err) => json!({"error deserializing post": err.to_string()}),