From c434e9ebf59afd45f6ebffce7e7d7470e69729e5 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 22 Feb 2024 10:57:02 -0400 Subject: [PATCH] refactor: remove getters --- waku-bindings/src/general/mod.rs | 36 ++++++-------------------------- waku-bindings/src/node/events.rs | 20 +++--------------- waku-bindings/tests/node.rs | 6 +++--- 3 files changed, 12 insertions(+), 50 deletions(-) diff --git a/waku-bindings/src/general/mod.rs b/waku-bindings/src/general/mod.rs index 33e4b6a..82ca5f7 100644 --- a/waku-bindings/src/general/mod.rs +++ b/waku-bindings/src/general/mod.rs @@ -24,19 +24,19 @@ pub type Result = std::result::Result; #[serde(rename_all = "camelCase")] pub struct WakuMessage { #[serde(with = "base64_serde", default = "Vec::new")] - payload: Vec, + pub payload: Vec, /// The content topic to be set on the message - content_topic: WakuContentTopic, + pub content_topic: WakuContentTopic, /// The Waku Message version number #[serde(default)] - version: WakuMessageVersion, + pub version: WakuMessageVersion, /// Unix timestamp in nanoseconds #[serde(deserialize_with = "deserialize_number_from_string")] - timestamp: usize, + pub timestamp: usize, #[serde(with = "base64_serde", default = "Vec::new")] - meta: Vec, + pub meta: Vec, #[serde(default)] - ephemeral: bool, + pub ephemeral: bool, // TODO: implement RLN fields #[serde(flatten)] _extras: serde_json::Value, @@ -64,30 +64,6 @@ impl WakuMessage { _extras: Default::default(), } } - - pub fn payload(&self) -> &[u8] { - &self.payload - } - - pub fn content_topic(&self) -> &WakuContentTopic { - &self.content_topic - } - - pub fn version(&self) -> WakuMessageVersion { - self.version - } - - pub fn timestamp(&self) -> usize { - self.timestamp - } - - pub fn meta(&self) -> &[u8] { - &self.meta - } - - pub fn ephemeral(&self) -> bool { - self.ephemeral - } } /// WakuMessage encoding scheme diff --git a/waku-bindings/src/node/events.rs b/waku-bindings/src/node/events.rs index b302873..11cbfe9 100644 --- a/waku-bindings/src/node/events.rs +++ b/waku-bindings/src/node/events.rs @@ -29,25 +29,11 @@ pub enum Event { #[serde(rename_all = "camelCase")] pub struct WakuMessageEvent { /// The pubsub topic on which the message was received - pubsub_topic: String, + pub pubsub_topic: String, /// The message id - message_id: MessageId, + pub message_id: MessageId, /// The message in [`WakuMessage`] format - waku_message: WakuMessage, -} - -impl WakuMessageEvent { - pub fn pubsub_topic(&self) -> &String { - &self.pubsub_topic - } - - pub fn message_id(&self) -> &String { - &self.message_id - } - - pub fn waku_message(&self) -> &WakuMessage { - &self.waku_message - } + pub waku_message: WakuMessage, } /// Register callback to act as event handler and receive application events, diff --git a/waku-bindings/tests/node.rs b/waku-bindings/tests/node.rs index 6c1ea24..1a257c1 100644 --- a/waku-bindings/tests/node.rs +++ b/waku-bindings/tests/node.rs @@ -33,9 +33,9 @@ struct Response { fn set_callback(node: &WakuNodeHandle, tx: Sender) { node.set_event_callback(move |event| { if let Event::WakuMessage(message) = event { - let id = message.message_id(); - let message = message.waku_message(); - let payload = message.payload().to_vec(); + let id = message.message_id; + let message = message.waku_message; + let payload = message.payload.to_vec(); tx.send(Response { id: id.to_string(),