mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
start handling topic health event
This commit is contained in:
parent
2d507c4ea6
commit
d758d7273f
@ -40,6 +40,7 @@ async fn main() -> Result<(), Error> {
|
||||
println!("Message Received in NODE 2: {}", msg);
|
||||
println!("::::::::::::::::::::::::::::::::::::::::::::::::::::");
|
||||
}
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {} // do nothing
|
||||
WakuEvent::Unrecognized(err) => panic!("Unrecognized waku event: {:?}", err),
|
||||
_ => panic!("event case not expected"),
|
||||
};
|
||||
|
||||
@ -74,7 +74,8 @@ impl TicTacToeApp<Initialized> {
|
||||
// Handle the error as needed, or just log and skip
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {}, // do nothing
|
||||
WakuEvent::Unrecognized(err) => panic!("Unrecognized waku event: {:?}", err),
|
||||
_ => panic!("event case not expected"),
|
||||
};
|
||||
|
||||
@ -110,7 +110,8 @@ impl App<Initialized> {
|
||||
write!(out, "{e:?}").unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {} // do nothing
|
||||
WakuEvent::Unrecognized(err) => eprintln!("Unrecognized waku event: {:?}", err),
|
||||
_ => eprintln!("event case not expected"),
|
||||
};
|
||||
|
||||
@ -20,6 +20,10 @@ use crate::MessageHash;
|
||||
pub enum WakuEvent {
|
||||
#[serde(rename = "message")]
|
||||
WakuMessage(WakuMessageEvent),
|
||||
|
||||
#[serde(rename = "relay_topic_health_change")]
|
||||
RelayTopicHealthChange(TopicHealthEvent),
|
||||
|
||||
Unrecognized(serde_json::Value),
|
||||
}
|
||||
|
||||
@ -35,9 +39,20 @@ pub struct WakuMessageEvent {
|
||||
pub waku_message: WakuMessage,
|
||||
}
|
||||
|
||||
/// Type of `event` field for a `message` event
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TopicHealthEvent {
|
||||
/// The pubsub topic on which the message was received
|
||||
pub pubsub_topic: String,
|
||||
/// The message hash
|
||||
pub topic_health: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::WakuEvent;
|
||||
use crate::WakuEvent::RelayTopicHealthChange;
|
||||
|
||||
#[test]
|
||||
fn deserialize_message_event() {
|
||||
@ -45,4 +60,17 @@ mod tests {
|
||||
let evt: WakuEvent = serde_json::from_str(s).unwrap();
|
||||
assert!(matches!(evt, WakuEvent::WakuMessage(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_topic_health_change_event() {
|
||||
let s = "{\"eventType\":\"relay_topic_health_change\", \"pubsubTopic\":\"/waku/2/rs/16/1\",\"topicHealth\":\"MinimallyHealthy\"}";
|
||||
let evt: WakuEvent = serde_json::from_str(s).unwrap();
|
||||
match evt {
|
||||
RelayTopicHealthChange(topic_health_event) => {
|
||||
assert_eq!(topic_health_event.pubsub_topic, "/waku/2/rs/16/1");
|
||||
assert_eq!(topic_health_event.topic_health, "MinimallyHealthy");
|
||||
}
|
||||
_ => panic!("Expected RelayTopicHealthChange event, but got {:?}", evt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user