Rename decode response util

This commit is contained in:
Daniel Sanchez Quiros 2023-02-14 16:19:57 +01:00
parent b0ea59a29d
commit 65d1e538b4
8 changed files with 22 additions and 22 deletions

View File

@ -5,7 +5,7 @@ use std::time::Duration;
use multiaddr::Multiaddr;
use url::{Host, Url};
// internal
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
use crate::Result;
/// RetrieveNodes returns a list of multiaddress given a url to a DNS discoverable ENR tree.
@ -44,5 +44,5 @@ pub fn waku_dns_discovery(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}

View File

@ -8,7 +8,7 @@ use std::time::Duration;
// internal
use crate::general::Result;
use crate::general::{FilterSubscription, PeerId};
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Creates a subscription in a lightnode for messages that matches a content filter and optionally a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`)
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_subscribechar-filterjson-char-peerid-int-timeoutms)
@ -40,7 +40,7 @@ pub fn waku_filter_subscribe(
drop(CString::from_raw(peer_id_ptr));
result_ptr
};
decode_response::<bool>(result_ptr).map(|_| ())
decode_and_free_response::<bool>(result_ptr).map(|_| ())
}
/// Removes subscriptions in a light node matching a content filter and, optionally, a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`)
@ -67,5 +67,5 @@ pub fn waku_filter_unsubscribe(
res
};
decode_response::<bool>(result_ptr).map(|_| ())
decode_and_free_response::<bool>(result_ptr).map(|_| ())
}

View File

@ -9,7 +9,7 @@ use secp256k1::{PublicKey, SecretKey};
// internal
use crate::general::{MessageId, PeerId, Result, WakuMessage, WakuPubSubTopic};
use crate::node::waku_dafault_pubsub_topic;
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Publish a message using Waku Lightpush
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publishchar-messagejson-char-topic-char-peerid-int-timeoutms)
@ -54,7 +54,7 @@ pub fn waku_lightpush_publish(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}
/// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Lightpush
@ -117,7 +117,7 @@ pub fn waku_lightpush_publish_encrypt_asymmetric(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}
/// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Lightpush
@ -179,5 +179,5 @@ pub fn waku_lightpush_publish_encrypt_symmetric(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}

View File

@ -7,7 +7,7 @@ use std::ffi::{CStr, CString};
// internal
use super::config::WakuNodeConfig;
use crate::general::{JsonResponse, PeerId, Result};
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Instantiates a Waku node
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_newchar-jsonconfig)
@ -99,7 +99,7 @@ pub fn waku_peer_id() -> Result<PeerId> {
/// as per [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_listen_addresses)
pub fn waku_listen_addresses() -> Result<Vec<Multiaddr>> {
let response_ptr = unsafe { waku_sys::waku_listen_addresses() };
decode_response(response_ptr)
decode_and_free_response(response_ptr)
}
#[cfg(test)]

View File

@ -8,7 +8,7 @@ use multiaddr::Multiaddr;
use serde::Deserialize;
// internal
use crate::general::{JsonResponse, PeerId, ProtocolId, Result};
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Add a node multiaddress and protocol to the waku nodes peerstore.
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid)
@ -206,7 +206,7 @@ pub type WakuPeers = Vec<WakuPeerData>;
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peers)
pub fn waku_peers() -> Result<WakuPeers> {
let response_ptr = unsafe { waku_sys::waku_peers() };
decode_response(response_ptr)
decode_and_free_response(response_ptr)
}
#[cfg(test)]

View File

@ -10,7 +10,7 @@ use secp256k1::{PublicKey, SecretKey};
use crate::general::{
Encoding, JsonResponse, MessageId, Result, WakuContentTopic, WakuMessage, WakuPubSubTopic,
};
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Create a content topic according to [RFC 23](https://rfc.vac.dev/spec/23/)
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding)
@ -138,7 +138,7 @@ pub fn waku_relay_publish_message(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}
/// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Relay
@ -196,7 +196,7 @@ pub fn waku_relay_publish_encrypt_asymmetric(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}
/// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Relay
@ -254,7 +254,7 @@ pub fn waku_relay_publish_encrypt_symmetric(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}
pub fn waku_enough_peers(pubsub_topic: Option<WakuPubSubTopic>) -> Result<bool> {
@ -299,7 +299,7 @@ pub fn waku_relay_subscribe(pubsub_topic: Option<WakuPubSubTopic>) -> Result<()>
res
};
decode_response::<bool>(result_ptr).map(|_| ())
decode_and_free_response::<bool>(result_ptr).map(|_| ())
}
pub fn waku_relay_unsubscribe(pubsub_topic: Option<WakuPubSubTopic>) -> Result<()> {
@ -317,5 +317,5 @@ pub fn waku_relay_unsubscribe(pubsub_topic: Option<WakuPubSubTopic>) -> Result<(
res
};
decode_response::<bool>(result_ptr).map(|_| ())
decode_and_free_response::<bool>(result_ptr).map(|_| ())
}

View File

@ -6,7 +6,7 @@ use std::time::Duration;
// crates
// internal
use crate::general::{PeerId, Result, StoreQuery, StoreResponse};
use crate::utils::decode_response;
use crate::utils::decode_and_free_response;
/// Retrieves historical messages on specific content topics. This method may be called with [`PagingOptions`](`crate::general::PagingOptions`),
/// to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](`crate::general::PagingOptions`),
@ -44,5 +44,5 @@ pub fn waku_store_query(
res
};
decode_response(result_ptr)
decode_and_free_response(result_ptr)
}

View File

@ -4,7 +4,7 @@ use std::ffi::{c_char, CStr};
/// Safety: The caller is responsible for ensuring that the pointer is valid for the duration of the call.
/// This takes a pointer to a C string coming from the waku lib, that data is consumed and then freed using [`waku_sys::waku_utils_free`].
pub fn decode_response<T: DeserializeOwned>(response_ptr: *mut c_char) -> Result<T> {
pub fn decode_and_free_response<T: DeserializeOwned>(response_ptr: *mut c_char) -> Result<T> {
let response = unsafe { CStr::from_ptr(response_ptr) }
.to_str()
.expect("Response should always succeed to load to a &str");