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
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::models::{currency::Currency, requests::RequestMethod, Model};
use super::{CommonFields, LedgerIndex, LookupByLedgerRequest, Request};
/// The book_offers method retrieves a list of offers, also known
/// as the order book, between two currencies.
///
/// See Book Offers:
/// `<https://xrpl.org/book_offers.html#book_offers>`
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct BookOffers<'a> {
/// The common fields shared by all requests.
#[serde(flatten)]
pub common_fields: CommonFields<'a>,
/// Specification of which currency the account taking
/// the offer would receive, as an object with currency
/// and issuer fields (omit issuer for XRP),
/// like currency amounts.
pub taker_gets: Currency<'a>,
/// Specification of which currency the account taking
/// the offer would pay, as an object with currency and
/// issuer fields (omit issuer for XRP),
/// like currency amounts.
pub taker_pays: Currency<'a>,
/// The unique identifier of a ledger.
#[serde(flatten)]
pub ledger_lookup: Option<LookupByLedgerRequest<'a>>,
/// If provided, the server does not provide more than
/// this many offers in the results. The total number of
/// results returned may be fewer than the limit,
/// because the server omits unfunded offers.
pub limit: Option<u16>,
/// The Address of an account to use as a perspective.
/// Unfunded offers placed by this account are always
/// included in the response. (You can use this to look
/// up your own orders to cancel them.)
pub taker: Option<Cow<'a, str>>,
}
impl<'a> Model for BookOffers<'a> {}
impl<'a> Request<'a> for BookOffers<'a> {
fn get_common_fields(&self) -> &CommonFields<'a> {
&self.common_fields
}
fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
&mut self.common_fields
}
}
impl<'a> BookOffers<'a> {
pub fn new(
id: Option<Cow<'a, str>>,
taker_gets: Currency<'a>,
taker_pays: Currency<'a>,
ledger_hash: Option<Cow<'a, str>>,
ledger_index: Option<LedgerIndex<'a>>,
limit: Option<u16>,
taker: Option<Cow<'a, str>>,
) -> Self {
Self {
common_fields: CommonFields {
command: RequestMethod::BookOffers,
id,
},
taker_gets,
taker_pays,
ledger_lookup: Some(LookupByLedgerRequest {
ledger_hash,
ledger_index,
}),
limit,
taker,
}
}
}
#[cfg(test)]
mod test {
use crate::models::currency::{Currency, IssuedCurrency, XRP};
use super::BookOffers;
#[test]
fn test_serde() {
let req = BookOffers::new(
None,
Currency::IssuedCurrency(IssuedCurrency::new("EUR".into(), "rTestIssuer".into())),
Currency::XRP(XRP::new()),
None,
None,
None,
None,
);
let serialized = serde_json::to_string(&req).unwrap();
let deserialized: BookOffers = serde_json::from_str(&serialized).unwrap();
assert_eq!(req, deserialized);
}
}