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. /// 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 /// 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> { pub fn waku_local_store_query(query: &StoreQuery) -> Result<StoreResponse> {
let result = unsafe { let query_ptr = CString::new(
CStr::from_ptr(waku_sys::waku_store_local_query( serde_json::to_string(query).expect("StoreQuery should always be able to be serialized"),
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") .expect("CString should build properly from the serialized filter subscription")
.into_raw(), .into_raw();
)) let result_ptr = unsafe {
} let res = waku_sys::waku_store_local_query(query_ptr);
.to_str() drop(CString::from_raw(query_ptr));
.expect("Response should always succeed to load to a &str"); res
};
let response: JsonResponse<StoreResponse> = decode_and_free_response(result_ptr)
serde_json::from_str(result).expect("JsonResponse should always succeed to deserialize");
response.into()
} }