mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
fix: waku_peer_count conversion to usize
This commit is contained in:
parent
32bd05c6fc
commit
e17cb311a3
@ -62,6 +62,7 @@ pub fn waku_listen_addresses() -> Result<Vec<Multiaddr>> {
|
||||
mod test {
|
||||
use super::waku_new;
|
||||
use crate::node::management::{waku_listen_addresses, waku_peer_id, waku_start, waku_stop};
|
||||
use crate::node::peers::waku_peer_count;
|
||||
use serial_test::serial;
|
||||
|
||||
#[test]
|
||||
@ -74,6 +75,9 @@ mod test {
|
||||
dbg!(&id);
|
||||
assert!(!id.is_empty());
|
||||
|
||||
let peer_cnt = waku_peer_count().unwrap();
|
||||
dbg!(peer_cnt);
|
||||
|
||||
// test addresses, since we cannot start different instances of the node
|
||||
let addresses = waku_listen_addresses().unwrap();
|
||||
dbg!(&addresses);
|
||||
|
||||
@ -98,7 +98,11 @@ pub fn waku_disconnect_peer_with_id(peer_id: &PeerId) -> Result<()> {
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peer_count)
|
||||
pub fn waku_peer_count() -> Result<usize> {
|
||||
let response_ptr = unsafe { waku_sys::waku_peer_cnt() };
|
||||
decode_and_free_response(response_ptr)
|
||||
let num_str = decode_and_free_response::<String>(response_ptr)?;
|
||||
let num = num_str
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "could not convert peer count into u32".to_string())?;
|
||||
usize::try_from(num).map_err(|_| "could not convert peer count into usize".to_string())
|
||||
}
|
||||
|
||||
/// Waku peer supported protocol
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user