xrpl/asynch/clients/
client.rs1use crate::models::{
2 requests::{Request, XRPLRequest},
3 results::XRPLResponse,
4};
5use url::Url;
6
7use super::exceptions::XRPLClientResult;
8
9#[allow(async_fn_in_trait)]
10pub trait XRPLClient {
11 async fn request_impl<'a: 'b, 'b>(
12 &self,
13 request: XRPLRequest<'a>,
14 ) -> XRPLClientResult<XRPLResponse<'b>>;
15
16 fn get_host(&self) -> Url;
17
18 fn set_request_id(&self, request: &mut XRPLRequest<'_>) {
19 let common_fields = request.get_common_fields_mut();
20 if common_fields.id.is_none() {
21 #[cfg(feature = "std")]
22 {
23 common_fields.id = Some(self.get_random_id());
24 }
25 #[cfg(not(feature = "std"))]
26 unimplemented!(
27 "Random ID generation is not supported in no_std. Please provide an ID."
28 );
29 }
30 }
31
32 #[cfg(feature = "std")]
34 fn get_random_id<'a>(&self) -> alloc::borrow::Cow<'a, str> {
35 use alloc::string::ToString;
36
37 let random_id = rand::random::<u32>().to_string();
38
39 alloc::borrow::Cow::Owned(random_id)
40 }
41}