nym_wireguard_private_metadata_client/
lib.rs

1// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use async_trait::async_trait;
5use tracing::instrument;
6
7use nym_http_api_client::{ApiClient, Client, HttpClientError, NO_PARAMS};
8
9use nym_wireguard_private_metadata_shared::{
10    Version, routes, {Request, Response},
11};
12
13#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
14#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
15pub trait WireguardMetadataApiClient: ApiClient {
16    #[instrument(level = "debug", skip(self))]
17    async fn version(&self) -> Result<Version, HttpClientError> {
18        let version: u64 = self
19            .get_json(
20                &[routes::V1_API_VERSION, routes::BANDWIDTH, routes::VERSION],
21                NO_PARAMS,
22            )
23            .await?;
24        Ok(version.into())
25    }
26
27    #[instrument(level = "debug", skip(self))]
28    async fn available_bandwidth(
29        &self,
30        request_body: &Request,
31    ) -> Result<Response, HttpClientError> {
32        self.post_json(
33            &[routes::V1_API_VERSION, routes::BANDWIDTH, routes::AVAILABLE],
34            NO_PARAMS,
35            request_body,
36        )
37        .await
38    }
39
40    #[instrument(level = "debug", skip(self, request_body))]
41    async fn topup_bandwidth(&self, request_body: &Request) -> Result<Response, HttpClientError> {
42        self.post_json(
43            &[routes::V1_API_VERSION, routes::BANDWIDTH, routes::TOPUP],
44            NO_PARAMS,
45            request_body,
46        )
47        .await
48    }
49
50    #[instrument(level = "debug", skip(self, request_body))]
51    async fn request_upgrade_mode_check(
52        &self,
53        request_body: &Request,
54    ) -> Result<Response, HttpClientError> {
55        self.post_json(
56            &[
57                routes::V1_API_VERSION,
58                routes::NETWORK,
59                routes::UPGRADE_MODE_CHECK,
60            ],
61            NO_PARAMS,
62            request_body,
63        )
64        .await
65    }
66}
67
68#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
69#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
70impl WireguardMetadataApiClient for Client {}