1use serde::{Deserialize, Serialize};
2
3use crate::client::MpcClient;
4use crate::error::Error;
5
6#[derive(Debug, Serialize)]
8pub struct CreateAccountRequest {
9 pub wallet_id: String,
10 pub chain: String,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub account_type: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub label: Option<String>,
15}
16
17#[derive(Debug, Deserialize)]
19pub struct Account {
20 pub account_id: String,
21 pub wallet_id: String,
22 pub client_id: String,
23 pub address: String,
24 pub network: String,
25 pub address_type: String,
26 pub label: String,
27 pub status: String,
28 pub created_at: String,
29}
30
31#[derive(Debug, Default)]
33pub struct ListAccountsRequest {
34 pub wallet_id: Option<String>,
35 pub page: Option<i32>,
36 pub page_size: Option<i32>,
37}
38
39#[derive(Debug, Deserialize)]
41pub struct ListAccountsResponse {
42 #[serde(rename = "data")]
43 pub items: Vec<Account>,
44 pub total: i64,
45 pub has_more: bool,
46}
47
48impl MpcClient {
49 pub async fn create_account(&self, req: &CreateAccountRequest) -> Result<Account, Error> {
51 self.post("/api/v1/accounts", req).await
52 }
53
54 pub async fn get_account(&self, account_id: &str) -> Result<Account, Error> {
56 self.get(&format!("/api/v1/accounts/{account_id}")).await
57 }
58
59 pub async fn list_accounts(
61 &self,
62 req: &ListAccountsRequest,
63 ) -> Result<ListAccountsResponse, Error> {
64 let mut params = Vec::new();
65 if let Some(ref wallet_id) = req.wallet_id {
66 params.push(("wallet_id".to_string(), wallet_id.clone()));
67 }
68 if let Some(page) = req.page {
69 params.push(("page".to_string(), page.to_string()));
70 }
71 if let Some(page_size) = req.page_size {
72 params.push(("page_size".to_string(), page_size.to_string()));
73 }
74 self.get_with_query("/api/v1/accounts", ¶ms).await
75 }
76}