Ivan FB 0c0b834aa0
Recover toy chat app powered by libwaku/nwaku (#105)
* bump nwaku to the current master branch ( commit: 625c8ee5 )
* make the waku crate to behave tokio-asynchronously
* use of store
* use of lightpush and filter
* add waku-bindings/src/general/messagehash.rs
* add waku-bindings/src/general/time.rs
* add waku-bindings/src/general/waku_decode.rs
* add WakuEvent management (WakuMessage, ConnectionChange, TopicHealthChange.)
* add waku-bindings/src/macros.rs
2025-01-10 15:19:31 +01:00

35 lines
1.0 KiB
Rust

//! Waku lightpush protocol related methods
// std
use std::ffi::CString;
// internal
use crate::general::libwaku_response::{handle_response, LibwakuResponse};
use crate::general::{messagehash::MessageHash, Result, WakuMessage};
use crate::handle_ffi_call;
use crate::node::context::WakuNodeContext;
use crate::general::pubsubtopic::PubsubTopic;
pub async fn waku_lightpush_publish_message(
ctx: &WakuNodeContext,
message: &WakuMessage,
pubsub_topic: &PubsubTopic,
) -> Result<MessageHash> {
let message = CString::new(
serde_json::to_string(&message)
.expect("WakuMessages should always be able to success serializing"),
)
.expect("CString should build properly from the serialized waku message");
let pubsub_topic = CString::new(String::from(pubsub_topic))
.expect("CString should build properly from pubsub topic");
handle_ffi_call!(
waku_sys::waku_lightpush_publish,
handle_response,
ctx.get_ptr(),
pubsub_topic.as_ptr(),
message.as_ptr()
)
}