From 3132182a7aedbea24227e6e954584615bd2e800d Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Tue, 27 Sep 2022 10:53:43 +0200 Subject: [PATCH] Added general types --- waku-sys/build.rs | 3 +- waku/src/general/mod.rs | 91 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/waku-sys/build.rs b/waku-sys/build.rs index 5983533..7de924d 100644 --- a/waku-sys/build.rs +++ b/waku-sys/build.rs @@ -3,7 +3,6 @@ use std::env::set_current_dir; use std::path::PathBuf; use std::process::Command; - fn main() { // TODO: well, there are a lot of things to consider here, including architechture target. A better aware system should be used. // For now this will have to do @@ -20,7 +19,7 @@ fn main() { let output_lib = "libgowaku.a"; set_current_dir("./vendor").unwrap(); Command::new(go_bin) - .env("CGO_ENABLED","1") + .env("CGO_ENABLED", "1") .arg("build") .arg("-buildmode=c-archive") .arg("-o") diff --git a/waku/src/general/mod.rs b/waku/src/general/mod.rs index 86ba620..804cff9 100644 --- a/waku/src/general/mod.rs +++ b/waku/src/general/mod.rs @@ -1,5 +1,4 @@ // std - // crates use serde::{Deserialize, Serialize}; // internal @@ -33,7 +32,97 @@ impl From> for Response { #[serde(rename_all = "camelCase")] pub struct WakuMessage { payload: Box<[u8]>, + /// The content topic to be set on the message content_topic: String, + /// The Waku Message version number version: usize, + /// Unix timestamp in nanoseconds timestamp: usize, } + +/// A payload once decoded, used when a received Waku Message is encrypted +pub struct DecodedPayload { + /// Public key that signed the message (optional), hex encoded with 0x prefix + public_key: Option, + /// Message signature (optional), hex encoded with 0x prefix + signature: Option, + /// Decrypted message payload base64 encoded + data: String, + /// Padding base64 encoded + padding: String, +} + +/// The content topic of a Waku message +/// as per the [specification](https://rfc.vac.dev/spec/36/#contentfilter-type) +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ContentFilter { + /// The content topic of a Waku message + content_topic: String, +} + +/// The criteria to create subscription to a light node in JSON Format +/// as per the [specification](https://rfc.vac.dev/spec/36/#filtersubscription-type) +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FilterSubscription { + /// Array of [`ContentFilter`] being subscribed to / unsubscribed from + content_filters: Vec, + /// Optional pubsub topic + pubsub_topic: Option, +} + +/// Criteria used to retrieve historical messages +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct StoreQuery { + /// The pubsub topic on which messages are published + pubsub_topic: Option, + /// Array of [`ContentFilter`] to query for historical messages + content_filters: Vec, + /// The inclusive lower bound on the timestamp of queried messages. + /// This field holds the Unix epoch time in nanoseconds + start_time: Option, + /// The inclusive upper bound on the timestamp of queried messages. + /// This field holds the Unix epoch time in nanoseconds + end_time: Option, + /// Paging information in [`PagingOptions`] format + paging_options: Option, +} + +/// The response received after doing a query to a store node +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StoreResponse { + /// Array of retrieved historical messages in [`WakuMessage`] format + messages: Vec, + /// Paging information in [`PagingOptions`] format from which to resume further historical queries + paging_options: Option, +} + +/// Paging information +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PagingOptions { + /// Number of messages to retrieve per page + page_size: usize, + /// Message Index from which to perform pagination. + /// If not included and forward is set to true, paging will be performed from the beginning of the list. + /// If not included and forward is set to false, paging will be performed from the end of the list + cursor: Option, + /// `true` if paging forward, `false` if paging backward + forward: bool, +} + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct MessageIndex { + /// Hash of the message at this [`MessageIndex`] + digest: String, + /// UNIX timestamp in nanoseconds at which the message at this [`MessageIndex`] was received + receiver_time: usize, + /// UNIX timestamp in nanoseconds at which the message is generated by its sender + sender_time: usize, + /// The pubsub topic of the message at this [`MessageIndex`] + pubsub_topic: String, +}