1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Contains effects that pertain to trades being executed.
use resources::{Amount, AssetIdentifier};

/// Enum representing all the different kinds of effects that represent
/// changes made to an account.
#[derive(Debug, Deserialize, Clone)]
pub enum Kind {
    /// An effect representing the fact that an trade occured
    Trade(Trade),
}

/// People on the Stellar network can make offers to buy or sell assets. When an offer is fully or
/// partially fulfilled, a trade happens.
#[derive(Debug, Deserialize, Clone)]
pub struct Trade {
    account: String,
    offer_id: i64,
    seller: String,
    sold_amount: Amount,
    sold_asset: AssetIdentifier,
    bought_amount: Amount,
    bought_asset: AssetIdentifier,
}

impl Trade {
    /// Creates a new Trade
    pub fn new(
        account: String,
        offer_id: i64,
        seller: String,
        sold_amount: Amount,
        sold_asset: AssetIdentifier,
        bought_amount: Amount,
        bought_asset: AssetIdentifier,
    ) -> Trade {
        Trade {
            account,
            offer_id,
            seller,
            sold_amount,
            sold_asset,
            bought_amount,
            bought_asset,
        }
    }

    /// The public address of the account that bought a trade
    pub fn account(&self) -> &String {
        &self.account
    }

    /// The id of the offer which was used in executing the trade
    pub fn offer_id(&self) -> i64 {
        self.offer_id
    }

    /// The public address of the other party in the trade
    pub fn seller(&self) -> &String {
        &self.seller
    }

    /// The amount of the sold asset that was exchanged in this trade
    pub fn sold_amount(&self) -> Amount {
        self.sold_amount
    }

    /// The asset being sold in the trade
    pub fn sold_asset(&self) -> &AssetIdentifier {
        &self.sold_asset
    }

    /// The amount of the bought asset that was exchanged in this trade
    pub fn bought_amount(&self) -> Amount {
        self.bought_amount
    }

    /// The asset being bought in the trade
    pub fn bought_asset(&self) -> &AssetIdentifier {
        &self.bought_asset
    }
}