From a29899752e142fa8f919d75ec1b83df9b16107b1 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Mon, 13 Feb 2023 13:46:39 +0100 Subject: [PATCH] Expose local archive query Update to beta4 --- Cargo.lock | 10 +++++----- examples/Cargo.lock | 4 ++-- examples/toy-chat/src/main.rs | 1 + waku-bindings/Cargo.toml | 2 +- waku-bindings/src/node/mod.rs | 8 ++++++++ waku-bindings/src/node/store.rs | 23 +++++++++++++++++++++++ waku-sys/Cargo.toml | 4 ++-- 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f9564..cb62c06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,9 +87,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bindgen" -version = "0.63.0" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags", "cexpr", @@ -1246,9 +1246,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.24.2" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "pin-project-lite", @@ -1403,7 +1403,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.1.0-beta3" +version = "0.1.0-beta4" dependencies = [ "bindgen", ] diff --git a/examples/Cargo.lock b/examples/Cargo.lock index e326045..dfa9764 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1203,7 +1203,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waku-bindings" -version = "0.1.0-beta1" +version = "0.1.0-beta3" dependencies = [ "aes-gcm", "base64", @@ -1222,7 +1222,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.1.0-beta1" +version = "0.1.0-beta4" dependencies = [ "bindgen", ] diff --git a/examples/toy-chat/src/main.rs b/examples/toy-chat/src/main.rs index 716fc79..cf0c9bc 100644 --- a/examples/toy-chat/src/main.rs +++ b/examples/toy-chat/src/main.rs @@ -102,6 +102,7 @@ fn retrieve_history( }) .collect()) } + fn setup_node_handle() -> std::result::Result, Box> { let node_handle = waku_new(None)?; let node_handle = node_handle.start()?; diff --git a/waku-bindings/Cargo.toml b/waku-bindings/Cargo.toml index c650a59..ccba65a 100644 --- a/waku-bindings/Cargo.toml +++ b/waku-bindings/Cargo.toml @@ -25,7 +25,7 @@ serde_json = "1.0" sscanf = "0.3" smart-default = "0.6" url = "2.3" -waku-sys = { version = "0.1.0-beta3", path = "../waku-sys" } +waku-sys = { version = "0.1.0-beta4", path = "../waku-sys" } [dev-dependencies] futures = "0.3.25" diff --git a/waku-bindings/src/node/mod.rs b/waku-bindings/src/node/mod.rs index e39c3b1..d601e53 100644 --- a/waku-bindings/src/node/mod.rs +++ b/waku-bindings/src/node/mod.rs @@ -225,6 +225,14 @@ impl WakuNodeHandle { store::waku_store_query(query, peer_id, timeout) } + /// Retrieves locally stored historical messages on specific content topics. This method may be called with [`PagingOptions`](`crate::general::PagingOptions`), + /// to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](`crate::general::PagingOptions`), + /// 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 local_store_query(&self, query: &StoreQuery) -> Result { + store::waku_local_store_query(query) + } + /// Publish a message using Waku Lightpush /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publishchar-messagejson-char-topic-char-peerid-int-timeoutms) pub fn lightpush_publish( diff --git a/waku-bindings/src/node/store.rs b/waku-bindings/src/node/store.rs index 824ff04..98dfc5c 100644 --- a/waku-bindings/src/node/store.rs +++ b/waku-bindings/src/node/store.rs @@ -46,3 +46,26 @@ pub fn waku_store_query( decode_and_free_response(result_ptr) } + +/// Retrieves locally stored historical messages on specific content topics from the local archive system. This method may be called with [`PagingOptions`](`crate::general::PagingOptions`), +/// to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](`crate::general::PagingOptions`), +/// 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() +} diff --git a/waku-sys/Cargo.toml b/waku-sys/Cargo.toml index 45838a4..37dcc1a 100644 --- a/waku-sys/Cargo.toml +++ b/waku-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waku-sys" -version = "0.1.0-beta3" +version = "0.1.0-beta4" edition = "2021" authors = [ "Daniel Sanchez Quiros " @@ -19,4 +19,4 @@ crate-type = ["rlib"] [dependencies] [build-dependencies] -bindgen = "0.63" \ No newline at end of file +bindgen = "0.64" \ No newline at end of file