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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use crate::models::amount::XRPAmount;
/// Response format for the fee method, which reports the current state of
/// the open ledger requirements for the transaction cost.
///
/// See Fee:
/// `<https://xrpl.org/fee.html>`
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Fee<'a> {
/// Number of transactions provisionally included in the in-progress
/// ledger.
pub current_ledger_size: Cow<'a, str>,
/// Number of transactions currently queued for the next ledger.
pub current_queue_size: Cow<'a, str>,
/// Various information about the transaction cost (the Fee field of a
/// transaction), in drops of XRP.
pub drops: Drops<'a>,
/// The approximate number of transactions expected to be included in the
/// current ledger.
pub expected_ledger_size: Cow<'a, str>,
/// The Ledger Index of the current open ledger these stats describe.
pub ledger_current_index: u32,
/// Various information about the transaction cost, in fee levels.
pub levels: Levels<'a>,
/// The maximum number of transactions that the transaction queue can
/// currently hold.
pub max_queue_size: Option<Cow<'a, str>>,
}
/// Information about transaction costs in drops of XRP
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Drops<'a> {
/// The transaction cost required for a reference transaction to be
/// included in a ledger under minimum load, represented in drops of XRP.
pub base_fee: XRPAmount<'a>,
/// An approximation of the median transaction cost among transactions
/// included in the previous validated ledger, represented in drops of XRP.
pub median_fee: XRPAmount<'a>,
/// The minimum transaction cost for a reference transaction to be queued
/// for a later ledger, represented in drops of XRP.
pub minimum_fee: XRPAmount<'a>,
/// The minimum transaction cost that a reference transaction must pay to
/// be included in the current open ledger, represented in drops of XRP.
pub open_ledger_fee: XRPAmount<'a>,
}
/// Information about transaction costs in fee levels
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Levels<'a> {
/// The median transaction cost among transactions in the previous
/// validated ledger, represented in fee levels.
pub median_level: Cow<'a, str>,
/// The minimum transaction cost required to be queued for a future
/// ledger, represented in fee levels.
pub minimum_level: Cow<'a, str>,
/// The minimum transaction cost required to be included in the current
/// open ledger, represented in fee levels.
pub open_ledger_level: Cow<'a, str>,
/// The equivalent of the minimum transaction cost, represented in fee
/// levels.
pub reference_level: Cow<'a, str>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fee_deserialize() {
let json = r#"{
"current_ledger_size": "14",
"current_queue_size": "0",
"drops": {
"base_fee": "10",
"median_fee": "11000",
"minimum_fee": "10",
"open_ledger_fee": "10"
},
"expected_ledger_size": "24",
"ledger_current_index": 26575101,
"levels": {
"median_level": "281600",
"minimum_level": "256",
"open_ledger_level": "256",
"reference_level": "256"
},
"max_queue_size": "480"
}"#;
let fee: Fee = serde_json::from_str(json).unwrap();
// Test top-level fields
assert_eq!(fee.current_ledger_size, "14");
assert_eq!(fee.current_queue_size, "0");
assert_eq!(fee.expected_ledger_size, "24");
assert_eq!(fee.ledger_current_index, 26575101);
assert_eq!(fee.max_queue_size, Some("480".into()));
// Test drops
assert_eq!(fee.drops.base_fee, XRPAmount::from("10"));
assert_eq!(fee.drops.median_fee, XRPAmount::from("11000"));
assert_eq!(fee.drops.minimum_fee, XRPAmount::from("10"));
assert_eq!(fee.drops.open_ledger_fee, XRPAmount::from("10"));
// Test levels
assert_eq!(fee.levels.median_level, "281600");
assert_eq!(fee.levels.minimum_level, "256");
assert_eq!(fee.levels.open_ledger_level, "256");
assert_eq!(fee.levels.reference_level, "256");
}
#[test]
fn test_fee_serialize() {
let fee = Fee {
current_ledger_size: "14".into(),
current_queue_size: "0".into(),
drops: Drops {
base_fee: XRPAmount::from("10"),
median_fee: XRPAmount::from("11000"),
minimum_fee: XRPAmount::from("10"),
open_ledger_fee: XRPAmount::from("10"),
},
expected_ledger_size: "24".into(),
ledger_current_index: 26575101,
levels: Levels {
median_level: "281600".into(),
minimum_level: "256".into(),
open_ledger_level: "256".into(),
reference_level: "256".into(),
},
max_queue_size: Some("480".into()),
};
let serialized = serde_json::to_string(&fee).unwrap();
let deserialized: Fee = serde_json::from_str(&serialized).unwrap();
assert_eq!(fee, deserialized);
}
}