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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::models::requests::Marker;
/// Response format for the account_objects method, which returns the raw
/// ledger format for all objects owned by an account.
///
/// See Account Objects:
/// `<https://xrpl.org/account_objects.html>`
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct AccountObjects<'a> {
/// Unique Address of the account this request corresponds to
pub account: Cow<'a, str>,
/// Array of objects owned by this account. Each object is in its raw
/// ledger format. Using Value since objects can be of different types
/// (RippleState, Offer, etc.)
pub account_objects: Cow<'a, [Value]>,
/// The identifying hash of the ledger that was used to generate this
/// response. May be omitted.
pub ledger_hash: Option<Cow<'a, str>>,
/// The ledger index of the ledger version that was used to generate
/// this response. Omitted if ledger_current_index is provided instead.
pub ledger_index: Option<u32>,
/// The ledger index of the current in-progress ledger version, which was
/// used to generate this response. May be omitted if ledger_hash or
/// ledger_index is provided.
pub ledger_current_index: Option<u32>,
/// The limit that was used in this request, if any.
pub limit: Option<u32>,
/// Server-defined value indicating the response is paginated. Pass this
/// to the next call to resume where this call left off. Omitted when
/// there are no additional pages after this one.
pub marker: Option<Marker<'a>>,
/// If true, the information in this response comes from a validated
/// ledger version. Otherwise, the information is subject to change.
/// Omitted for in-progress ledger responses.
pub validated: Option<bool>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_account_objects_deserialization() {
let json = r#"{
"account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"account_objects": [
{
"Balance": {
"currency": "ASP",
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
"value": "0"
},
"Flags": 65536,
"HighLimit": {
"currency": "ASP",
"issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"value": "0"
},
"HighNode": "0000000000000000",
"LedgerEntryType": "RippleState",
"LowLimit": {
"currency": "ASP",
"issuer": "r3vi7mWxru9rJCxETCyA1CHvzL96eZWx5z",
"value": "10"
},
"LowNode": "0000000000000000",
"PreviousTxnID": "BF7555B0F018E3C5E2A3FF9437A1A5092F32903BE246202F988181B9CED0D862",
"PreviousTxnLgrSeq": 1438879,
"index": "2243B0B630EA6F7330B654EFA53E27A7609D9484E535AB11B7F946DF3D247CE9"
}
],
"ledger_hash": "4C99E5F63C0D0B1C2283B4F5DCE2239F80CE92E8B1A6AED1E110C198FC96E659",
"ledger_index": 14380380,
"limit": 10,
"marker": "F60ADF645E78B69857D2E4AEC8B7742FEABC8431BD8611D099B428C3E816DF93,94A9F05FEF9A153229E2E997E64919FD75AAE2028C8153E8EBDB4440BD3ECBB5",
"validated": true
}"#;
let account_objects: AccountObjects = serde_json::from_str(json).unwrap();
// Test main struct fields
assert_eq!(
account_objects.account,
"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
);
assert_eq!(
account_objects.ledger_hash.unwrap(),
"4C99E5F63C0D0B1C2283B4F5DCE2239F80CE92E8B1A6AED1E110C198FC96E659"
);
assert_eq!(account_objects.ledger_index, Some(14380380));
assert_eq!(account_objects.limit.unwrap(), 10);
assert_eq!(account_objects.validated, Some(true));
// Test account objects array
assert_eq!(account_objects.account_objects.len(), 1);
// Test marker
let marker = account_objects.marker.unwrap();
assert_eq!(
marker,
Marker::Str(
"F60ADF645E78B69857D2E4AEC8B7742FEABC8431BD8611D099B42\
8C3E816DF93,94A9F05FEF9A153229E2E997E64919FD75AAE2028C\
8153E8EBDB4440BD3ECBB5"
.into()
)
);
// Test first account object
let first_object = &account_objects.account_objects[0];
assert_eq!(first_object["LedgerEntryType"], "RippleState");
assert_eq!(first_object["Flags"], 65536);
assert_eq!(
first_object["PreviousTxnID"],
"BF7555B0F018E3C5E2A3FF9437A1A5092F32903BE246202F988181B9CED0D862"
);
}
}