Skip to content

How To Pass A String to a Client Instead of A Buffer for Hashes

Connor Turland edited this page Jul 20, 2021 · 2 revisions

When rewriting from holochain-rust to holochain (rsm) the core team decided to serialize hashes (HoloHash) not as simple strings, but as structs, containing buffers. So when you deserialize these hashes on the other side, (like a client/ui), you are going to get something similar. Chances are, you had a lot of assumptions in your UI about hashes (entry hashes, header hashes, agent pub keys, dna hashes) being strings, which will break now. UNLESS you take matters into your own hands, like proposed first in the code for Acorn, and wrap the default hash structs with wrapper structs that express your own serialization preferences, in our case, to strings. Joel wrote this up into a helper file/structs in a new 'hc-utils' crate. See specifically this https://github.com/holochain/hc-utils/blob/develop/crates/hc-utils/src/wrappers.rs So now in your app entry structs, you might use

use hdk::*;

#[hdk_entry]
pub struct MyThing {
  address_reference: hc_utils::WrappedHeaderHash
}

instead of

use hdk::*;

#[hdk_entry]
pub struct MyThing {
  address_reference: HeaderHash
}

now when you do a callZome using holochain-conductor-api, you'll get back something like

{
  address_reference: '1112uasfknasd...'
}

instead of

{
  address_reference: {
    hash: Buffer(123...),
    hash_type: Buffer(43, 32, 34)
  }
}