gevulot_rs/
sudo_client.rs

1use std::sync::Arc;
2use tokio::sync::RwLock;
3
4use crate::{
5    base_client::BaseClient,
6    error::Result,
7    proto::gevulot::gevulot::{
8        MsgSudoDeletePin, MsgSudoDeletePinResponse, MsgSudoDeleteTask, MsgSudoDeleteTaskResponse,
9        MsgSudoDeleteWorker, MsgSudoDeleteWorkerResponse, MsgSudoFreezeAccount,
10        MsgSudoFreezeAccountResponse,
11    },
12};
13
14/// Client for managing sudo operations in the Gevulot system.
15#[derive(Debug, Clone)]
16pub struct SudoClient {
17    base_client: Arc<RwLock<BaseClient>>,
18}
19
20impl SudoClient {
21    /// Creates a new instance of SudoClient.
22    ///
23    /// # Arguments
24    ///
25    /// * `base_client` - An Arc-wrapped RwLock of the BaseClient.
26    ///
27    /// # Returns
28    ///
29    /// A new instance of SudoClient.
30    pub fn new(base_client: Arc<RwLock<BaseClient>>) -> Self {
31        Self { base_client }
32    }
33
34    /// Deletes a pin.
35    ///
36    /// # Arguments
37    ///
38    /// * `msg` - The message containing the details of the pin to delete.
39    ///
40    /// # Returns
41    ///
42    /// A Result containing the response of the delete pin operation or an error.
43    ///
44    /// # Errors
45    ///
46    /// This function will return an error if the request to the Gevulot client fails.
47    pub async fn delete_pin(&mut self, msg: MsgSudoDeletePin) -> Result<MsgSudoDeletePinResponse> {
48        let resp: MsgSudoDeletePinResponse = self
49            .base_client
50            .write()
51            .await
52            .send_msg_sync(msg, "")
53            .await?;
54        Ok(resp)
55    }
56
57    /// Deletes a worker.
58    ///
59    /// # Arguments
60    ///
61    /// * `msg` - The message containing the details of the worker to delete.
62    ///
63    /// # Returns
64    ///
65    /// A Result containing the response of the delete worker operation or an error.
66    ///
67    /// # Errors
68    ///
69    /// This function will return an error if the request to the Gevulot client fails.
70    pub async fn delete_worker(
71        &mut self,
72        msg: MsgSudoDeleteWorker,
73    ) -> Result<MsgSudoDeleteWorkerResponse> {
74        let resp: MsgSudoDeleteWorkerResponse = self
75            .base_client
76            .write()
77            .await
78            .send_msg_sync(msg, "")
79            .await?;
80        Ok(resp)
81    }
82
83    /// Deletes a task.
84    ///
85    /// # Arguments
86    ///
87    /// * `msg` - The message containing the details of the task to delete.
88    ///
89    /// # Returns
90    ///
91    /// A Result containing the response of the delete task operation or an error.
92    ///
93    /// # Errors
94    ///
95    /// This function will return an error if the request to the Gevulot client fails.
96    pub async fn delete_task(
97        &mut self,
98        msg: MsgSudoDeleteTask,
99    ) -> Result<MsgSudoDeleteTaskResponse> {
100        let resp: MsgSudoDeleteTaskResponse = self
101            .base_client
102            .write()
103            .await
104            .send_msg_sync(msg, "")
105            .await?;
106        Ok(resp)
107    }
108
109    /// Freezes an account.
110    ///
111    /// # Arguments
112    ///
113    /// * `msg` - The message containing the details of the account to freeze.
114    ///
115    /// # Returns
116    ///
117    /// A Result containing the response of the freeze account operation or an error.
118    ///
119    /// # Errors
120    ///
121    /// This function will return an error if the request to the Gevulot client fails.
122    pub async fn freeze_account(
123        &mut self,
124        msg: MsgSudoFreezeAccount,
125    ) -> Result<MsgSudoFreezeAccountResponse> {
126        let resp: MsgSudoFreezeAccountResponse = self
127            .base_client
128            .write()
129            .await
130            .send_msg_sync(msg, "")
131            .await?;
132        Ok(resp)
133    }
134}