hc_utils 0.6.1-rc.1

Helper functions for holochain hdk development
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use hdk::prelude::*;

pub fn get_from<E: TryFrom<Entry>, H>(hash: H) -> ExternResult<(E, Record)>
where
    AnyDhtHash: From<H>,
{
    let reserve_action = get(hash, GetOptions::network())?;
    if let Some(record) = reserve_action {
        if let RecordEntry::Present(entry) = record.entry() {
            let entry =
                E::try_from(entry.to_owned()).or(Err(wasm_error!("unable to serialize entry")))?;
            return Ok((entry, record));
        }
    }
    Err(wasm_error!("no entry found"))
}