Skip to main content

esi_openapi/groups/
wallet.rs

1#![allow(unused)]
2
3use crate::prelude::*;
4
5/// Endpoints for Wallet
6pub struct WalletGroup<'a> {
7    pub(crate) esi: &'a Esi,
8}
9
10impl WalletGroup<'_> {
11    api_get!(
12        /// Returns a character’s wallet balance
13        get_wallet,
14        "GetCharactersCharacterIdWallet",
15        RequestType::Authenticated,
16        f64,
17        (character_id: i64) => "{character_id}"
18    );
19}
20
21/// What the context ID of a wallet journal entry refers to.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum JournalContextType {
25    /// A structure ID.
26    StructureId,
27    /// A station ID.
28    StationId,
29    /// A market transaction ID.
30    MarketTransactionId,
31    /// A character ID.
32    CharacterId,
33    /// A corporation ID.
34    CorporationId,
35    /// An alliance ID.
36    AllianceId,
37    /// An EVE system.
38    EveSystem,
39    /// An industry job ID.
40    IndustryJobId,
41    /// A contract ID.
42    ContractId,
43    /// A planet ID.
44    PlanetId,
45    /// A solar system ID.
46    SystemId,
47    /// A type ID.
48    TypeId,
49    /// A kind this version of the crate does not know about.
50    #[serde(other)]
51    Unrecognized,
52}
53
54/// An entry of a wallet journal.
55#[derive(Debug, Clone, PartialEq, Deserialize)]
56#[allow(missing_docs)]
57pub struct JournalEntry {
58    pub amount: Option<f64>,
59    pub balance: Option<f64>,
60    pub context_id: Option<i64>,
61    pub context_id_type: Option<JournalContextType>,
62    pub date: String,
63    pub description: String,
64    pub first_party_id: Option<i64>,
65    pub id: i64,
66    pub reason: Option<String>,
67    /// The kind of transaction, such as `bounty_prizes` or `player_trading`.
68    /// ESI defines more than 160 values, so it is kept as a string.
69    pub ref_type: String,
70    pub second_party_id: Option<i64>,
71    pub tax: Option<f64>,
72    pub tax_receiver_id: Option<i64>,
73}
74
75impl WalletGroup<'_> {
76    api_get!(
77        /// Get a character's wallet journal for the last 30 days.
78        get_journal,
79        "GetCharactersCharacterIdWalletJournal",
80        RequestType::Authenticated,
81        Vec<JournalEntry>,
82        (character_id: i64) => "{character_id}";
83        Optional(page: i32) => "page"
84    );
85}
86
87#[cfg(test)]
88mod character_basic_tests {
89    use super::{JournalContextType, JournalEntry};
90
91    #[test]
92    fn test_parse_journal_entries() {
93        let json = r#"[
94            {"id": 9000000000, "date": "2026-10-01T00:00:00Z", "description": "Bounty",
95             "ref_type": "bounty_prizes", "amount": 1500.5, "balance": 100.0,
96             "context_id": 30000142, "context_id_type": "system_id", "first_party_id": 2112625428},
97            {"id": 2, "date": "2026-10-01T00:00:00Z", "description": "?", "ref_type": "new_kind",
98             "context_id_type": "something_new"}
99        ]"#;
100        let entries: Vec<JournalEntry> = serde_json::from_str(json).unwrap();
101        assert_eq!(entries[0].id, 9_000_000_000);
102        assert_eq!(
103            entries[0].context_id_type,
104            Some(JournalContextType::SystemId)
105        );
106        assert_eq!(
107            entries[1].context_id_type,
108            Some(JournalContextType::Unrecognized)
109        );
110        assert!(entries[1].amount.is_none());
111    }
112}
113
114/// The balance of one corporation wallet division.
115#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
116#[allow(missing_docs)]
117pub struct DivisionBalance {
118    pub balance: f64,
119    pub division: i64,
120}
121
122/// A market transaction of a corporation wallet division.
123#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
124#[allow(missing_docs)]
125pub struct CorporationWalletTransaction {
126    pub client_id: i64,
127    pub date: String,
128    pub is_buy: bool,
129    pub journal_ref_id: i64,
130    pub location_id: i64,
131    pub quantity: i64,
132    pub transaction_id: i64,
133    pub type_id: i64,
134    pub unit_price: f64,
135}
136
137impl WalletGroup<'_> {
138    api_get!(
139        /// Get the balance of every wallet division of a corporation.
140        get_corporation_wallets,
141        "GetCorporationsCorporationIdWallets",
142        RequestType::Authenticated,
143        Vec<DivisionBalance>,
144        (corporation_id: i64) => "{corporation_id}"
145    );
146
147    api_get!(
148        /// Get the journal of a corporation wallet division for the last 30 days.
149        get_corporation_journal,
150        "GetCorporationsCorporationIdWalletsDivisionJournal",
151        RequestType::Authenticated,
152        Vec<JournalEntry>,
153        (corporation_id: i64) => "{corporation_id}",
154        (division: i64) => "{division}";
155        Optional(page: i32) => "page"
156    );
157
158    api_get!(
159        /// Get the market transactions of a corporation wallet division.
160        /// Pass the lowest `transaction_id` of the previous page as `from_id` to continue.
161        get_corporation_transactions,
162        "GetCorporationsCorporationIdWalletsDivisionTransactions",
163        RequestType::Authenticated,
164        Vec<CorporationWalletTransaction>,
165        (corporation_id: i64) => "{corporation_id}",
166        (division: i64) => "{division}";
167        Optional(from_id: i64) => "from_id"
168    );
169}