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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
/// Response from an account_currencies request, containing a list of
/// currencies that an accountn can send or receive, based on its trust lines.
///
/// See Account Currencies:
/// `<https://xrpl.org/account_currencies.html>`
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct AccountCurrencies<'a> {
/// The identifying hash of the ledger version used to retrieve this data,
/// as hex.
pub ledger_hash: Option<Cow<'a, str>>,
/// The ledger index of the ledger version used to retrieve this data.
pub ledger_index: u32,
/// Array of Currency Codes for currencies that this account can receive.
pub receive_currencies: Cow<'a, [Cow<'a, str>]>,
/// Array of Currency Codes for currencies that this account can send.
pub send_currencies: Cow<'a, [Cow<'a, str>]>,
/// If true, this data comes from a validated ledger.
pub validated: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_account_currencies_deserialization() {
let json = r#"{
"ledger_index": 11775823,
"receive_currencies": [
"BTC",
"CNY",
"DYM",
"EUR",
"JOE",
"MXN",
"USD",
"015841551A748AD2C1F76FF6ECB0CCCD00000000"
],
"send_currencies": [
"ASP",
"BTC",
"CHF",
"CNY",
"DYM",
"EUR",
"JOE",
"JPY",
"MXN",
"USD"
],
"status": "success",
"validated": true
}"#;
let account_currencies: AccountCurrencies = serde_json::from_str(json).unwrap();
assert_eq!(account_currencies.ledger_index, 11775823);
assert_eq!(account_currencies.validated, true);
// Test receive_currencies
let expected_receive = [
"BTC",
"CNY",
"DYM",
"EUR",
"JOE",
"MXN",
"USD",
"015841551A748AD2C1F76FF6ECB0CCCD00000000",
];
assert_eq!(
account_currencies.receive_currencies.len(),
expected_receive.len()
);
for (i, currency) in expected_receive.iter().enumerate() {
assert_eq!(account_currencies.receive_currencies[i], *currency);
}
// Test send_currencies
let expected_send = [
"ASP", "BTC", "CHF", "CNY", "DYM", "EUR", "JOE", "JPY", "MXN", "USD",
];
assert_eq!(
account_currencies.send_currencies.len(),
expected_send.len()
);
for (i, currency) in expected_send.iter().enumerate() {
assert_eq!(account_currencies.send_currencies[i], *currency);
}
}
}