Use decode response function

This commit is contained in:
Daniel Sanchez Quiros 2023-02-14 18:47:16 +01:00
parent a44e3276dd
commit 1bec289ece
1 changed files with 11 additions and 16 deletions

View File

@ -52,20 +52,15 @@ pub fn waku_store_query(
/// the node must return messages on a per-page basis and include [`PagingOptions`](`crate::general::PagingOptions`) in the response.
/// These [`PagingOptions`](`crate::general::PagingOptions`) must contain a cursor pointing to the Index from which a new page can be requested
pub fn waku_local_store_query(query: &StoreQuery) -> Result<StoreResponse> {
let result = unsafe {
CStr::from_ptr(waku_sys::waku_store_local_query(
CString::new(
serde_json::to_string(query)
.expect("StoreQuery should always be able to be serialized"),
let query_ptr = CString::new(
serde_json::to_string(query).expect("StoreQuery should always be able to be serialized"),
)
.expect("CString should build properly from the serialized filter subscription")
.into_raw(),
))
}
.to_str()
.expect("Response should always succeed to load to a &str");
let response: JsonResponse<StoreResponse> =
serde_json::from_str(result).expect("JsonResponse should always succeed to deserialize");
response.into()
.into_raw();
let result_ptr = unsafe {
let res = waku_sys::waku_store_local_query(query_ptr);
drop(CString::from_raw(query_ptr));
res
};
decode_and_free_response(result_ptr)
}