paratro_sdk/
transaction.rs1use serde::Deserialize;
2
3use crate::client::MpcClient;
4use crate::error::Error;
5
6#[derive(Debug, Deserialize)]
8pub struct Transaction {
9 pub tx_id: String,
10 pub wallet_id: String,
11 pub client_id: String,
12 pub chain: String,
13 pub transaction_type: String,
14 pub from_address: String,
15 pub to_address: String,
16 pub token_symbol: String,
17 pub amount: String,
18 pub status: String,
19 pub tx_hash: String,
20 pub created_at: String,
21}
22
23#[derive(Debug, Default)]
25pub struct ListTransactionsRequest {
26 pub wallet_id: Option<String>,
27 pub account_id: Option<String>,
28 pub chain: Option<String>,
29 pub page: Option<i32>,
30 pub page_size: Option<i32>,
31}
32
33#[derive(Debug, Deserialize)]
35pub struct ListTransactionsResponse {
36 #[serde(rename = "data")]
37 pub items: Vec<Transaction>,
38 pub total: i64,
39 pub has_more: bool,
40}
41
42impl MpcClient {
43 pub async fn get_transaction(&self, tx_id: &str) -> Result<Transaction, Error> {
45 self.get(&format!("/api/v1/transactions/{tx_id}")).await
46 }
47
48 pub async fn list_transactions(
50 &self,
51 req: &ListTransactionsRequest,
52 ) -> Result<ListTransactionsResponse, Error> {
53 let mut params = Vec::new();
54 if let Some(ref wallet_id) = req.wallet_id {
55 params.push(("wallet_id".to_string(), wallet_id.clone()));
56 }
57 if let Some(ref account_id) = req.account_id {
58 params.push(("account_id".to_string(), account_id.clone()));
59 }
60 if let Some(ref chain) = req.chain {
61 params.push(("chain".to_string(), chain.clone()));
62 }
63 if let Some(page) = req.page {
64 params.push(("page".to_string(), page.to_string()));
65 }
66 if let Some(page_size) = req.page_size {
67 params.push(("page_size".to_string(), page_size.to_string()));
68 }
69 self.get_with_query("/api/v1/transactions", ¶ms).await
70 }
71}