From c00b98ccb189d9596596a0bb9c0167f785ce2a0a Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Tue, 27 Sep 2022 10:53:43 +0200 Subject: [PATCH] Added general types --- waku/src/general/mod.rs | 91 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) 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, +}