dfns_sdk_rust/swaps/
mod.rs1pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9#[derive(Clone)]
11pub struct SwapsClient {
12 client: crate::client::Client,
13}
14
15impl SwapsClient {
16 pub fn new(client: crate::client::Client) -> Self {
17 SwapsClient { client }
18 }
19
20 pub async fn list_swaps(
22 &self,
23 query: Option<ListSwapsQuery>,
24 ) -> Result<ListSwapsResponse, crate::error::Error> {
25 let mut path = String::from("/swaps");
26 if let Some(query) = &query {
27 let mut q: Vec<String> = Vec::new();
28 if let Some(v) = &query.limit {
29 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
30 }
31 if let Some(v) = &query.pagination_token {
32 q.push(format!(
33 "paginationToken={}",
34 urlencoding::encode(&v.to_string())
35 ));
36 }
37 if !q.is_empty() {
38 path.push('?');
39 path.push_str(&q.join("&"));
40 }
41 }
42 self.client
43 .request::<ListSwapsResponse>(reqwest::Method::GET, &path, None, false)
44 .await
45 }
46
47 pub async fn create_swap(
49 &self,
50 body: CreateSwapRequest,
51 ) -> Result<CreateSwapResponse, crate::error::Error> {
52 let path = String::from("/swaps");
53 let body = serde_json::to_value(&body)?;
54 self.client
55 .request::<CreateSwapResponse>(reqwest::Method::POST, &path, Some(&body), true)
56 .await
57 }
58
59 pub async fn request_swap_quote(
61 &self,
62 body: RequestSwapQuoteRequest,
63 ) -> Result<RequestSwapQuoteResponse, crate::error::Error> {
64 let path = String::from("/swaps/quotes");
65 let body = serde_json::to_value(&body)?;
66 self.client
67 .request::<RequestSwapQuoteResponse>(reqwest::Method::POST, &path, Some(&body), false)
68 .await
69 }
70
71 pub async fn get_swap(&self, swap_id: String) -> Result<GetSwapResponse, crate::error::Error> {
73 let path = format!("/swaps/{}", urlencoding::encode(&swap_id));
74 self.client
75 .request::<GetSwapResponse>(reqwest::Method::GET, &path, None, false)
76 .await
77 }
78
79 pub async fn get_swap_quote(
81 &self,
82 quote_id: String,
83 ) -> Result<GetSwapQuoteResponse, crate::error::Error> {
84 let path = format!("/swaps/quotes/{}", urlencoding::encode("e_id));
85 self.client
86 .request::<GetSwapQuoteResponse>(reqwest::Method::GET, &path, None, false)
87 .await
88 }
89}