Help with learning SAFE API as I refactor application

I’m refactoring a conventional app that I created in order to learn the SAFE API.

Repository: https://github.com/hunterlester/safe_rabbit_hole

Creating this thread to post questions that I have along the way. Thank you for your help.


First problem

I’m attempting to append appendable data to another appendable data, ultimately calling PUT /appendable-data/:handleId/:dataIdHandle (https://github.com/hunterlester/safe_rabbit_hole/blob/master/app/components/compose_mail.js#L43)

Error response:

description: "FfiError::InvalidDataIdHandle",
errorCode: -1514

I’d like to learn about what I’m doing wrong while also learning about core files:

The appendable_data_append function at https://github.com/maidsafe/safe_client_libs/blob/0.22.1/src/ffi/low_level_api/appendable_data.rs#L668 appears to be throwing an error at https://github.com/maidsafe/safe_client_libs/blob/0.22.1/src/ffi/low_level_api/appendable_data.rs#L677

The get_data_id function (https://github.com/maidsafe/safe_client_libs/blob/0.22.1/src/ffi/low_level_api/object_cache.rs#L122) according to the documentation (http://contain-rs.github.io/lru-cache/lru_cache/struct.LruCache.html#method.get_mut), “Returns a mutable reference to the value corresponding to the given key in the cache, if any”

get_data_id, if not an FfiError, should return a mutable reference to DataIdentifier wrapped in a Result. DataIdentifier is an enum that should be one of four data types (https://github.com/maidsafe/routing/blob/master/src/data/mod.rs#L111)

I’m expecting that the data id handle that I’m passing in belongs to a public appendable data.

I need help from here.
As I intend to post further questions in this thread, please let me know if I can improve the format for ease of reading

2 Likes

Hello @hunterlester,

so, let’s unpack what is going on here. So, you have on AppendableData and you want to append it to another AppendableData, correct? Let’s call them Home and Office.

At the current version of the low level API this isn’t super straight forward, as there are multiple handle-named things that aren’t easy to distinguish. Just remember that the DataHandleId essentially is a persistent address to an object in the network (aka XorAddress + TAG_ID). The other handles are internal keys, that you used to communicate to your session which object you are interacting with within that session - think of them as C-style File-Handlers, you use them to identify which file you want to write to within this process. Those are non-permanent, by the primary way you use to talk to your session when you want to change something.

So if you open Home, you get a temporary handleId to mutate and act with that specific item. Now, if you want to add a reference of Home to Office, you need to get a permanent address - the DataHandleId. The way to do this is through the get data-id for appendable-data-API. With the result of that API-call you should be able to do the request you mentioned and get the expected result.


FYI, we is a very verbose and not clearly defined API and requires a lot of very similar terms in your head, which can make it very confusing. Which is why we are intending of replacing this with a much cleaner approach in our current efforts to provide a mobile-friendly development approach. Expect to see a much more refined and clearer API in the next couple of weeks.

5 Likes