aum_core/
reqres.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents various types of requests that can be made.
4#[derive(Deserialize, Serialize, Clone, Debug)]
5pub enum Request {
6    /// Request to retrieve the address of the best wallet to use.
7    RetrieveAddress,
8
9    /// Request to send a transaction to a specific address with a specified amount.
10    SendTransaction { to: String, amount: u64 },
11
12    /// Request to send a transaction from a specific address to another with a specified amount.
13    SendTransactionFrom {
14        from: String,
15        to: String,
16        amount: u64,
17    },
18
19    /// Request to retrieve the balance of specified wallet.
20    RetrieveBalance { address: String },
21
22    /// Request to retrieve balances of all wallets.
23    RetrieveBalances,
24    /// Request to list all available wallets.
25    ListWallets,
26    /// Request to synchronize the system state.
27    Sync,
28}
29
30/// Represents various types of responses that can be returned.
31#[derive(Deserialize, Serialize, Clone, Debug)]
32pub enum Response {
33    /// Response containing the retrieved wallet address.
34    RetrieveAddress { address: String },
35
36    /// Response containing the balance of a specified wallet.
37    RetrieveBalance { address: String, balance: u64 },
38
39    /// Response containing the balances of all wallets.
40    RetrieveBalances { balances: Vec<(String, u64)> },
41
42    /// Response containing a list of wallet identifiers.
43    ListWallets { wallets: Vec<String> },
44
45    /// Response indicating the success of a synchronization operation.
46    Sync { success: bool },
47
48    /// Response containing the transaction ID for a sent transaction.
49    SendTransaction { txid: String },
50
51    /// Response containing the transaction ID and the originating address for a sent transaction.
52    SendTransactionFrom { from: String, txid: String },
53}
54
55impl Response {
56    pub fn to_string(&self) -> String {
57        serde_json::to_string_pretty(self).unwrap()
58    }
59}
60impl Into<String> for Response {
61    fn into(self) -> String {
62        self.to_string()
63    }
64}