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