1
+ /// Provides the `SingleOfferRequest`.
2
+ ///
3
+ /// This module provides the `SingleOfferRequest` struct, specifically designed for
4
+ /// constructing requests to query information about a single offer from the Horizon
5
+ /// server. It is tailored for use with the [`HorizonClient::get_single_offer`](crate::horizon_client::HorizonClient::get_single_offer)
6
+ /// method.
7
+ ///
8
+ pub mod single_offer_request;
9
+
10
+ /// Provides the responses.
11
+ ///
12
+ /// This module defines structures representing the response from the Horizon API when querying
13
+ /// for offers. The structures are designed to deserialize the JSON response into Rust
14
+ /// objects, enabling straightforward access to various details of a single Stellar account.
15
+ ///
16
+ /// These structures are equipped with serialization capabilities to handle the JSON data from the
17
+ /// Horizon server and with getter methods for easy field access.
18
+ ///
19
+ pub mod response;
20
+
21
+ /// The base path for offer-related endpoints in the Horizon API.
22
+ ///
23
+ /// # Usage
24
+ /// This variable is intended to be used internally by the request-building logic
25
+ /// to ensure consistent and accurate path construction for offer-related API calls.
26
+ ///
27
+ static OFFERS_PATH : & str = "offers" ;
28
+
29
+ /// The `prelude` module of the `offers` module.
30
+ ///
31
+ /// This module serves as a convenience for users of the Horizon Rust SDK, allowing for easy and
32
+ /// ergonomic import of the most commonly used items across various modules. It re-exports
33
+ /// key structs and traits from the sibling modules, simplifying access to these components
34
+ /// when using the library.
35
+ ///
36
+ /// By importing the contents of `prelude`, users can conveniently access the primary
37
+ /// functionalities of the offer-related modules without needing to import each item
38
+ /// individually.
39
+ ///
40
+ /// # Contents
41
+ ///
42
+ /// The `prelude` includes the following re-exports:
43
+ ///
44
+ /// * From `single_offer_request`: All items (e.g. `SingleOfferRequest`).
45
+ /// * From `response`: All items (e.g. `SingleOfferResponse`, `PriceR`, etc.).
46
+ ///
47
+ /// # Example
48
+ /// ```
49
+ /// # use crate::stellar_rs::models::*;
50
+ /// // Import the contents of the offers prelude
51
+ /// use stellar_rs::offers::prelude::*;
52
+ ///
53
+ /// // Now you can directly use SingleOfferRequest, SingleOfferResponse, etc.
54
+ /// let single_offer_request = SingleOfferRequest::new();
55
+ /// ```
56
+ ///
57
+ pub mod prelude {
58
+ pub use super :: single_offer_request:: * ;
59
+ pub use super :: response:: * ;
60
+ }
61
+
62
+ #[ cfg( test) ]
63
+ pub mod test {
64
+ use super :: prelude:: * ;
65
+ use crate :: horizon_client:: HorizonClient ;
66
+
67
+ #[ tokio:: test]
68
+ async fn test_get_single_offer ( ) {
69
+ const LINK_SELF : & str = "https://horizon-testnet.stellar.org/offers/1" ;
70
+ const LINK_OFFER_MAKER : & str = "https://horizon-testnet.stellar.org/accounts/GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5" ;
71
+ const OFFER_ID : & str = "1" ;
72
+ const PAGING_TOKEN : & str = "1" ;
73
+ const SELLER : & str = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5" ;
74
+ const SELLING_ASSET_TYPE : & str = "credit_alphanum4" ;
75
+ const SELLING_ASSET_CODE : & str = "USDC" ;
76
+ const SELLING_ASSET_ISSUER : & str = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5" ;
77
+ const BUYING_ASSET_TYPE : & str = "credit_alphanum12" ;
78
+ const BUYING_ASSET_CODE : & str = "USDCAllow" ;
79
+ const BUYING_ASSET_ISSUER : & str = "GAWZGWFOURKXZ4XYXBGFADZM4QIG6BJNM74XIZCEIU3BHM62RN2MDEZN" ;
80
+ const AMOUNT : & str = "909086990804.0875807" ;
81
+ const PRICE_R_N : & u32 = & 1 ;
82
+ const PRICE_R_D : & u32 = & 1 ;
83
+ const PRICE : & str = "1.0000000" ;
84
+ const LAST_MODIFIED_LEDGER : & u32 = & 747543 ;
85
+ const LAST_MODIFIED_TIME : & str = "2024-03-23T04:51:18Z" ;
86
+
87
+ let horizon_client =
88
+ HorizonClient :: new ( "https://horizon-testnet.stellar.org"
89
+ . to_string ( ) )
90
+ . unwrap ( ) ;
91
+
92
+ let single_offer_request =
93
+ SingleOfferRequest :: new ( )
94
+ . set_offer_id ( OFFER_ID . to_string ( ) )
95
+ . unwrap ( ) ;
96
+
97
+ let single_offer_response = horizon_client
98
+ . get_single_offer ( & single_offer_request)
99
+ . await ;
100
+
101
+ assert ! ( single_offer_response. clone( ) . is_ok( ) ) ;
102
+ let response = single_offer_response. unwrap ( ) ;
103
+ assert_eq ! ( response. links( ) . self_link( ) . href( ) . as_ref( ) . unwrap( ) , LINK_SELF ) ;
104
+ assert_eq ! ( response. links( ) . offer_maker( ) . href( ) . as_ref( ) . unwrap( ) , LINK_OFFER_MAKER ) ;
105
+ assert_eq ! ( response. id( ) , OFFER_ID ) ;
106
+ assert_eq ! ( response. paging_token( ) , PAGING_TOKEN ) ;
107
+ assert_eq ! ( response. seller( ) , SELLER ) ;
108
+ assert_eq ! ( response. selling( ) . asset_type( ) , SELLING_ASSET_TYPE ) ;
109
+ assert_eq ! ( response. selling( ) . asset_code( ) . as_ref( ) . unwrap( ) , SELLING_ASSET_CODE ) ;
110
+ assert_eq ! ( response. selling( ) . asset_issuer( ) . as_ref( ) . unwrap( ) , SELLING_ASSET_ISSUER ) ;
111
+ assert_eq ! ( response. buying( ) . asset_type( ) , BUYING_ASSET_TYPE ) ;
112
+ assert_eq ! ( response. buying( ) . asset_code( ) . as_ref( ) . unwrap( ) , BUYING_ASSET_CODE ) ;
113
+ assert_eq ! ( response. buying( ) . asset_issuer( ) . as_ref( ) . unwrap( ) , BUYING_ASSET_ISSUER ) ;
114
+ assert_eq ! ( response. amount( ) , AMOUNT ) ;
115
+ assert_eq ! ( response. price_ratio( ) . numenator( ) , PRICE_R_N ) ;
116
+ assert_eq ! ( response. price_ratio( ) . denominator( ) , PRICE_R_D ) ;
117
+ assert_eq ! ( response. price_decimal( ) , PRICE ) ;
118
+ assert_eq ! ( response. last_modified_ledger( ) , LAST_MODIFIED_LEDGER ) ;
119
+ assert_eq ! ( response. last_modified_time( ) , LAST_MODIFIED_TIME ) ;
120
+ }
121
+ }
0 commit comments