1use serde::{Deserialize, Serialize};
2
3use crate::client::MpcClient;
4use crate::error::Error;
5
6#[derive(Debug, Serialize)]
8pub struct CreateAssetRequest {
9 pub account_id: String,
10 pub symbol: String,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub chain: Option<String>,
13}
14
15#[derive(Debug, Deserialize)]
17pub struct Asset {
18 pub asset_id: String,
19 pub account_id: String,
20 pub wallet_id: String,
21 pub client_id: String,
22 pub chain: String,
23 pub network: String,
24 pub symbol: String,
25 pub name: String,
26 pub contract_address: String,
27 pub decimals: i32,
28 pub asset_type: String,
29 pub balance: String,
30 pub locked_balance: String,
31 pub is_active: bool,
32 pub created_at: String,
33}
34
35#[derive(Debug, Default)]
37pub struct ListAssetsRequest {
38 pub account_id: Option<String>,
39 pub page: Option<i32>,
40 pub page_size: Option<i32>,
41}
42
43#[derive(Debug, Deserialize)]
45pub struct ListAssetsResponse {
46 #[serde(rename = "data")]
47 pub items: Vec<Asset>,
48 pub total: i64,
49 pub has_more: bool,
50}
51
52impl MpcClient {
53 pub async fn create_asset(&self, req: &CreateAssetRequest) -> Result<Asset, Error> {
55 self.post("/api/v1/assets", req).await
56 }
57
58 pub async fn get_asset(&self, asset_id: &str) -> Result<Asset, Error> {
60 self.get(&format!("/api/v1/assets/{asset_id}")).await
61 }
62
63 pub async fn list_assets(&self, req: &ListAssetsRequest) -> Result<ListAssetsResponse, Error> {
65 let mut params = Vec::new();
66 if let Some(ref account_id) = req.account_id {
67 params.push(("account_id".to_string(), account_id.clone()));
68 }
69 if let Some(page) = req.page {
70 params.push(("page".to_string(), page.to_string()));
71 }
72 if let Some(page_size) = req.page_size {
73 params.push(("page_size".to_string(), page_size.to_string()));
74 }
75 self.get_with_query("/api/v1/assets", ¶ms).await
76 }
77}