dfns_sdk_rs/api/networks/
client.rs1use super::types::*;
4use crate::{
5 error::DfnsError,
6 models::generic::DfnsApiClientOptions,
7 utils::{fetch::simple_fetch, url::build_path_and_query, user_action_fetch::user_action_fetch},
8};
9use std::collections::HashMap;
10
11pub struct NetworksClient {
12 api_options: DfnsApiClientOptions,
13}
14
15impl NetworksClient {
16 pub fn new(api_options: DfnsApiClientOptions) -> Self {
17 Self { api_options }
18 }
19
20 pub async fn get_fees(
21 &self,
22 request: Option<GetFeesRequest>,
23 ) -> Result<GetFeesResponse, DfnsError> {
24 let path = build_path_and_query(
25 "/networks/fees",
26 &crate::utils::url::PathAndQueryParams {
27 path: HashMap::new(),
28 query: request
29 .and_then(|r| r.query)
30 .map(|q| {
31 let mut map = HashMap::new();
32 map.insert("network".to_string(), format!("{:?}", q.network));
33 map
34 })
35 .unwrap_or_default(),
36 },
37 );
38
39 simple_fetch(
40 &path,
41 crate::utils::fetch::FetchOptions {
42 method: crate::utils::fetch::HttpMethod::GET,
43 headers: None,
44 body: None,
45 api_options: self.api_options.base.clone(),
46 },
47 )
48 .await
49 }
50
51 pub async fn read_contract(
52 &self,
53 request: ReadContractRequest,
54 ) -> Result<ReadContractResponse, DfnsError> {
55 let path = build_path_and_query(
56 "/networks/read-contract",
57 &crate::utils::url::PathAndQueryParams {
58 path: HashMap::new(),
59 query: HashMap::new(),
60 },
61 );
62
63 user_action_fetch(
64 &path,
65 crate::utils::fetch::FetchOptions {
66 method: crate::utils::fetch::HttpMethod::POST,
67 headers: None,
68 body: Some(serde_json::to_value(&request.body)?),
69 api_options: self.api_options.clone(),
70 },
71 )
72 .await
73 }
74}