From 1bec289ece167514f50a21b9ad241fc9cfea96bf Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Tue, 14 Feb 2023 18:47:16 +0100 Subject: [PATCH] Use decode response function --- waku-bindings/src/node/store.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/waku-bindings/src/node/store.rs b/waku-bindings/src/node/store.rs index 98dfc5c..c5dca16 100644 --- a/waku-bindings/src/node/store.rs +++ b/waku-bindings/src/node/store.rs @@ -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 { - 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"), - ) - .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 = - serde_json::from_str(result).expect("JsonResponse should always succeed to deserialize"); - response.into() + 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(); + 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) }