From 04e541df10e1cb135189d2d6f83ce13b1a431462 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Mon, 26 Feb 2024 13:43:32 +0100 Subject: [PATCH 1/4] transaction request --- .../effects_for_transaction_request.rs | 166 ++++++++++++++++ src/effects/mod.rs | 2 + src/horizon_client.rs | 177 ++++++++++++++++-- 3 files changed, 329 insertions(+), 16 deletions(-) create mode 100644 src/effects/effects_for_transaction_request.rs diff --git a/src/effects/effects_for_transaction_request.rs b/src/effects/effects_for_transaction_request.rs new file mode 100644 index 0000000..567598d --- /dev/null +++ b/src/effects/effects_for_transaction_request.rs @@ -0,0 +1,166 @@ +use stellar_xdr::curr::SurveyRequestMessage; + +use crate::{models::{Order, Request}, BuildQueryParametersExt}; + +/// Represents a request to fetch effect data from the Stellar Horizon API. +/// +/// `EffectForTransactionRequest` is a struct used to construct queries for retrieving information about effects +/// from the Horizon server. It includes parameters that allow for pagination control and sorting +/// of the effect records. +/// +/// # Usage +/// Instances of `EffectForTransactionRequest` are created and optionally configured using the builder pattern. +/// Once the desired parameters are set, the request can be passed to the Horizon client to fetch +/// effect data. +/// +/// # Example +/// ```rust +/// use stellar_rs::effects::effects_for_transaction_request::EffectForTransactionRequest; +/// use stellar_rs::models::*; +/// +/// let request = EffectForTransactionRequest::new() +/// .set_transaction_hash("transaction_hash".to_string()) +/// .set_cursor(1234).unwrap() +/// .set_limit(20).unwrap() +/// .set_order(Order::Desc); +/// +/// // The request can now be used with a Horizon client to fetch effects. +/// ``` +#[derive(Default)] +pub struct EffectForTransactionRequest { + /// The transaction hash of the transaction of the effect + transaction_hash: Option, + + /// A pointer to a specific location in a collection of responses, derived from the + /// `paging_token` value of a record. Used for pagination control in the API response. + cursor: Option, + + /// Specifies the maximum number of records to be returned in a single response. + /// The range for this parameter is from 1 to 200. The default value is set to 10. + limit: Option, + + /// Determines the [`Order`] of the records in the response. Valid options are [`Order::Asc`] (ascending) + /// and [`Order::Desc`] (descending). If not specified, it defaults to ascending. + order: Option, +} + +impl EffectForTransactionRequest { + /// Creates a new `EffectForTransactionRequest` with default parameters. + pub fn new() -> Self { + EffectForTransactionRequest::default() + } + + /// Sets the liquidity pool id for the request. + /// + /// # Arguments + /// * `liquidity_pool_id` - A `String` value representing the liquidity pool id. + /// + pub fn set_transaction_hash( + self, + transaction_hash: String, + ) -> EffectForTransactionRequest { + EffectForTransactionRequest { + transaction_hash: Some(transaction_hash), + ..self + } + } + + /// Sets the cursor for pagination. + /// + /// # Arguments + /// * `cursor` - A `u32` value pointing to a specific location in a collection of responses. + /// + pub fn set_cursor(self, cursor: u32) -> Result { + if cursor < 1 { + return Err("cursor must be greater than or equal to 1".to_string()); + } + + Ok(EffectForTransactionRequest { + cursor: Some(cursor), + ..self + }) + } + + /// Sets the maximum number of records to return. + /// + /// # Arguments + /// * `limit` - A `u8` value specifying the maximum number of records. Range: 1 to 200. Defaults to 10. + /// + pub fn set_limit(self, limit: u8) -> Result { + if limit < 1 || limit > 200 { + return Err("limit must be between 1 and 200".to_string()); + } + + Ok(EffectForTransactionRequest { + limit: Some(limit), + ..self + }) + } + + /// Sets the order of the returned records. + /// + /// # Arguments + /// * `order` - An [`Order`] enum value specifying the order (ascending or descending). + /// + pub fn set_order(self, order: Order) -> EffectForTransactionRequest { + EffectForTransactionRequest { + order: Some(order), + ..self + } + } +} + +impl Request for EffectForTransactionRequest { + fn get_query_parameters(&self) -> String { + vec![ + self.transaction_hash + .as_ref() + .map(|l| format!("transaction_hash={}", l)), + self.cursor.as_ref().map(|c| format!("cursor={}", c)), + self.limit.as_ref().map(|l| format!("limit={}", l)), + self.order.as_ref().map(|o| format!("order={}", o)), + ] + .build_query_parameters() + } + + fn build_url(&self, base_url: &str) -> String { + format!( + "{}/{}{}", + base_url, + super::EFFECTS_PATH, + self.get_query_parameters() + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::BuildQueryParametersExt; + + #[test] + fn test_effects_for_liquidity_pools_request() { + let request = EffectForTransactionRequest::new() + .set_transaction_hash("transaction_hash".to_string()) + .set_cursor(1) + .unwrap() + .set_limit(10) + .unwrap() + .set_order(Order::Asc); + + let url = request.build_url("https://horizon-testnet.stellar.org"); + let query_parameters = vec![ + Some("transaction_hash=transaction_hash".to_string()), + Some("cursor=1".to_string()), + Some("limit=10".to_string()), + Some("order=asc".to_string()), + ] + .build_query_parameters(); + + assert_eq!( + url, + "https://horizon-testnet.stellar.org/effects?transaction_hash=transaction_hash&cursor=1&limit=10&order=asc" + ); + assert_eq!(query_parameters, "?transaction_hash=transaction_hash&cursor=1&limit=10&order=asc"); + } +} diff --git a/src/effects/mod.rs b/src/effects/mod.rs index 298dd07..e707c43 100644 --- a/src/effects/mod.rs +++ b/src/effects/mod.rs @@ -3,6 +3,7 @@ pub mod effects_response; pub mod effects_for_account_request; pub mod effects_for_liquidity_pools_request; pub mod effects_for_ledger_request; +pub mod effects_for_transaction_request; static EFFECTS_PATH: &str = "effects"; @@ -12,6 +13,7 @@ pub mod prelude { pub use super::effects_for_account_request::*; pub use super::effects_for_liquidity_pools_request::*; pub use super::effects_for_ledger_request::*; + pub use super::effects_for_transaction_request::*; } #[cfg(test)] diff --git a/src/horizon_client.rs b/src/horizon_client.rs index c1983d1..f29dcfb 100644 --- a/src/horizon_client.rs +++ b/src/horizon_client.rs @@ -411,6 +411,57 @@ impl HorizonClient { self.get::(request).await } + /// Retrieves a list of effects for a specific transaction from the Horizon server. + /// + /// This asynchronous method fetches a list of effects for a specific transaction from the Horizon server. + /// It requires an [`EffectForTransactionRequest`] to specify the transaction hash and optional query parameters. + /// + /// # Arguments + /// * `request` - A reference to an [`EffectForTransactionRequest`] instance, containing the transaction hash + /// and optional query parameters for the effects request. + /// + /// # Returns + /// + /// On successful execution, returns a `Result` containing an [`EffectsResponse`], which includes + /// the list of effects obtained from the Horizon server. If the request fails, it returns an error within `Result`. + /// + /// # Example + /// To use this method, create an instance of [`EffectForTransactionRequest`] and set the transaction hash and any + /// desired query parameters. + /// + /// ``` + /// # use stellar_rs::effects::prelude::*; + /// # use stellar_rs::models::Request; + /// # use stellar_rs::horizon_client::HorizonClient; + /// + /// # async fn example() -> Result<(), Box> { + /// # let base_url = "https://horizon-testnet.stellar.org".to_string(); + /// # let horizon_client = HorizonClient::new(base_url) + /// # .expect("Failed to create Horizon Client"); + /// let request = EffectForTransactionRequest::new() + /// .set_transaction_hash("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string()); + /// + /// let response = horizon_client.get_effects_for_transaction(&request).await; + /// + /// // Access the effects + /// if let Ok(effects_response) = response { + /// for effect in effects_response._embedded().records() { + /// println!("Effect ID: {}", effect.id()); + /// // Further processing... + /// } + /// } + /// + /// # Ok({}) + /// # } + /// ``` + /// + pub async fn get_effects_for_transaction( + &self, + request: &EffectForTransactionRequest, + ) -> Result { + self.get::(request).await + } + /// Retrieves a list of all ledgers. /// /// This asynchronous method is designed to fetch list of ledgers @@ -1911,41 +1962,135 @@ mod tests { } #[tokio::test] - async fn test_get_effects_for_ledger() { - // found by trial and error in the Stellar laboratory - let ledger_sequence = 125; + async fn get_effects_for_transactions() { + const ID: &str = "0000000459561504769-0000000001"; + const PAGING_TOKEN: &str = "459561504769-1"; + const ACCOUNT: &str = "GAIH3ULLFQ4DGSECF2AR555KZ4KNDGEKN4AFI4SU2M7B43MGK3QJZNSR"; + const RECORD_TYPE: &str = "account_created"; + const TYPE_I: u32 = 0; + const CREATED_AT: &str = "2024-02-06T17:42:48Z"; + const STARTING_BALANCE: &str = "10000000000.0000000"; let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap(); - let effects_for_ledger_request = - EffectsForLedgerRequest::new().set_sequence(ledger_sequence); - let _effects_for_ledger_response = horizon_client - .get_effects_for_ledger(&effects_for_ledger_request) + let effects_for_liquidity_pools_request = + EffectForTransactionRequest::new().set_limit(2).unwrap(); + + let effects_for_liquidity_pools_response = horizon_client + .get_effects_for_transaction(&effects_for_liquidity_pools_request) .await; - println!("{:#?}", _effects_for_ledger_response); + assert!(effects_for_liquidity_pools_response.clone().is_ok()); + + assert_eq!( + effects_for_liquidity_pools_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .id(), + ID + ); + + assert_eq!( + effects_for_liquidity_pools_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .paging_token(), + PAGING_TOKEN + ); - assert!(_effects_for_ledger_response.clone().is_ok()); + assert_eq!( + effects_for_liquidity_pools_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .account(), + ACCOUNT + ); assert_eq!( - _effects_for_ledger_response + effects_for_liquidity_pools_response .clone() .unwrap() ._embedded() .records()[0] - .id, - "0000000536870916097-0000000001" + .effect_type(), + RECORD_TYPE ); assert_eq!( - _effects_for_ledger_response + effects_for_liquidity_pools_response .clone() .unwrap() ._embedded() - .records()[1] - .effect_type, - "account_debited" + .records()[0] + .type_i(), + &TYPE_I + ); + + assert_eq!( + effects_for_liquidity_pools_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .created_at(), + CREATED_AT + ); + + assert_eq!( + effects_for_liquidity_pools_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .starting_balance() + .as_ref() + .unwrap(), + &STARTING_BALANCE ); } } + +#[tokio::test] +async fn test_get_effects_for_ledger() { + // found by trial and error in the Stellar laboratory + let ledger_sequence = 125; + + let horizon_client = + HorizonClient::new("https://horizon-testnet.stellar.org".to_string()).unwrap(); + + let effects_for_ledger_request = EffectsForLedgerRequest::new().set_sequence(ledger_sequence); + let _effects_for_ledger_response = horizon_client + .get_effects_for_ledger(&effects_for_ledger_request) + .await; + + println!("{:#?}", _effects_for_ledger_response); + + assert!(_effects_for_ledger_response.clone().is_ok()); + + assert_eq!( + _effects_for_ledger_response + .clone() + .unwrap() + ._embedded() + .records()[0] + .id, + "0000000536870916097-0000000001" + ); + + assert_eq!( + _effects_for_ledger_response + .clone() + .unwrap() + ._embedded() + .records()[1] + .effect_type, + "account_debited" + ); +} From 19451fca2c9e6351e71fdd47aeebae9935c6ad23 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Mon, 26 Feb 2024 15:42:14 +0100 Subject: [PATCH 2/4] requested changes --- .../effects_for_transaction_request.rs | 2 -- src/horizon_client.rs | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/effects/effects_for_transaction_request.rs b/src/effects/effects_for_transaction_request.rs index 567598d..fcba14d 100644 --- a/src/effects/effects_for_transaction_request.rs +++ b/src/effects/effects_for_transaction_request.rs @@ -1,5 +1,3 @@ -use stellar_xdr::curr::SurveyRequestMessage; - use crate::{models::{Order, Request}, BuildQueryParametersExt}; /// Represents a request to fetch effect data from the Stellar Horizon API. diff --git a/src/horizon_client.rs b/src/horizon_client.rs index f29dcfb..eb8d6fa 100644 --- a/src/horizon_client.rs +++ b/src/horizon_client.rs @@ -1946,7 +1946,7 @@ mod tests { .expect("REASON") .set_liquidity_pool_id("0000000459561504769-0000000001".to_string()); let effects_for_liquidity_pools_response = horizon_client - .get_effects_for_liquidity_pools(&effects_for_liquidity_pools_request) + .get_effects_for_liquidity_pools(&effects_for_liquidity_pools_request_with_id) .await; assert!(effects_for_liquidity_pools_response.clone().is_ok()); @@ -1977,14 +1977,14 @@ mod tests { let effects_for_liquidity_pools_request = EffectForTransactionRequest::new().set_limit(2).unwrap(); - let effects_for_liquidity_pools_response = horizon_client + let effects_for_transaction_response = horizon_client .get_effects_for_transaction(&effects_for_liquidity_pools_request) .await; - assert!(effects_for_liquidity_pools_response.clone().is_ok()); + assert!(effects_for_transaction_response.clone().is_ok()); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -1994,7 +1994,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -2004,7 +2004,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -2014,7 +2014,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -2024,7 +2024,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -2034,7 +2034,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() @@ -2044,7 +2044,7 @@ mod tests { ); assert_eq!( - effects_for_liquidity_pools_response + effects_for_transaction_response .clone() .unwrap() ._embedded() From 4dd53f48be845c43b6ecf15192bf7ebafcdfd4d9 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Mon, 4 Mar 2024 16:11:58 +0100 Subject: [PATCH 3/4] added tests --- .gitignore | 3 ++ .../all_claimable_balances_request.rs | 50 +++++++++++++++++++ src/horizon_client.rs | 11 ++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 7fec66e..e7e56a0 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ keys.txt # Ignore Visual Studio Code project files .vscode/ + +# Ignore the tarpaulin code coverage report +tarpaulin-report.html \ No newline at end of file diff --git a/src/claimable_balances/all_claimable_balances_request.rs b/src/claimable_balances/all_claimable_balances_request.rs index 1c83657..92c04fc 100644 --- a/src/claimable_balances/all_claimable_balances_request.rs +++ b/src/claimable_balances/all_claimable_balances_request.rs @@ -219,4 +219,54 @@ mod tests { "limit must be between 1 and 200".to_string() ); } + + #[test] + fn test_set_sponsor_valid() { + let request = AllClaimableBalancesRequest::new() + .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()) + .unwrap(); + assert_eq!( + request.sponsor.unwrap(), + "GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7" + ); + } + + #[test] + fn test_set_sponsor_invalid() { + let request = AllClaimableBalancesRequest::new().set_sponsor("invalid_sponsor".to_string()); + assert!(request.is_err()); + } + + #[test] + fn test_set_claimant_valid() { + let request = AllClaimableBalancesRequest::new() + .set_claimant("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()) + .unwrap(); + assert_eq!( + request.claimant.unwrap(), + "GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7" + ); + } + + #[test] + fn test_set_claimant_invalid() { + let request = + AllClaimableBalancesRequest::new().set_claimant("invalid_claimant".to_string()); + assert!(request.is_err()); + } + + #[test] + fn test_build_url() { + let request = AllClaimableBalancesRequest::new() + .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()) + .unwrap() + .set_cursor(12345) + .unwrap() + .set_limit(20) + .unwrap() + .set_order(Order::Desc); + let base_url = "https://horizon.stellar.org"; + let url = request.build_url(base_url); + assert_eq!(url, "https://horizon.stellar.org/claimable_balances/?sponsor=GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7&cursor=12345&limit=20&order=desc"); + } } diff --git a/src/horizon_client.rs b/src/horizon_client.rs index eb8d6fa..74cd622 100644 --- a/src/horizon_client.rs +++ b/src/horizon_client.rs @@ -1944,20 +1944,21 @@ mod tests { let effects_for_liquidity_pools_request_with_id = EffectsForLiquidityPoolRequest::new() .set_limit(2) .expect("REASON") - .set_liquidity_pool_id("0000000459561504769-0000000001".to_string()); - let effects_for_liquidity_pools_response = horizon_client + .set_liquidity_pool_id("01c58ab8fb283c8b083a26bf2fe06b7b6c6304c13f9d29d956cdf15a48bea72d".to_string()); + + let effects_for_liquidity_pools_response_with_id = horizon_client .get_effects_for_liquidity_pools(&effects_for_liquidity_pools_request_with_id) .await; - assert!(effects_for_liquidity_pools_response.clone().is_ok()); + assert!(effects_for_liquidity_pools_response_with_id.clone().is_ok()); assert_eq!( - effects_for_liquidity_pools_response + effects_for_liquidity_pools_response_with_id .clone() .unwrap() ._embedded() .records()[0] .id(), - ID + "0001072977319841793-0000000001" ); } From 207423ab5d2e8afbcb0403c6ca770e7637d0b1e5 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Mon, 4 Mar 2024 16:45:14 +0100 Subject: [PATCH 4/4] _embedded to embedded --- src/accounts/accounts_response.rs | 3 +- src/assets/all_assets_response.rs | 3 +- src/effects/effects_response.rs | 10 +- src/horizon_client.rs | 174 +++++++++++++++--------------- src/ledgers/ledgers_response.rs | 3 +- 5 files changed, 98 insertions(+), 95 deletions(-) diff --git a/src/accounts/accounts_response.rs b/src/accounts/accounts_response.rs index 4a06807..b4d4515 100644 --- a/src/accounts/accounts_response.rs +++ b/src/accounts/accounts_response.rs @@ -156,7 +156,8 @@ pub struct AccountsResponse { /// Navigational links related to the response. _links: AccountsResponseLinks, /// The embedded object containing the actual account records. - _embedded: Embedded, + #[serde(rename = "_embedded")] + embedded: Embedded, } impl Response for AccountsResponse { diff --git a/src/assets/all_assets_response.rs b/src/assets/all_assets_response.rs index 7140ac9..0bca7a0 100644 --- a/src/assets/all_assets_response.rs +++ b/src/assets/all_assets_response.rs @@ -177,7 +177,8 @@ pub struct AllAssetsResponse { /// An `Embedded` struct that contains the actual list of asset records. Each /// record in this list provides detailed information about an individual asset, including /// its type, issuer, and various statistics related to its distribution and usage. - _embedded: Embedded, + #[serde(rename = "_embedded")] + embedded: Embedded, } impl Response for AllAssetsResponse { diff --git a/src/effects/effects_response.rs b/src/effects/effects_response.rs index 0ebdf10..66c638f 100644 --- a/src/effects/effects_response.rs +++ b/src/effects/effects_response.rs @@ -5,7 +5,7 @@ use crate::models::Response; /// Represents the navigational links in a effect response from the Stellar Horizon API. /// -/// This struct includes links such as the self-link (current page), next, and previous, +/// This struct includes links such as the self-link (current page), next, and previous, /// providing quick navigation across different pages of the effect response. /// #[derive(Debug, Deserialize, Clone, Getters)] @@ -29,12 +29,12 @@ pub struct SelfLink { /// A `String` representing the hyperlink reference to the current resource or query. href: String, /// Optionally indicates if the link is templated - templated: Option + templated: Option, } /// Represents the navigational links belonging to an effect from the Stellar Horizon API. /// -/// This struct includes links such as the operation (current effect), succeeds, and precedes, +/// This struct includes links such as the operation (current effect), succeeds, and precedes, /// providing quick navigation across operational sequence belonging to the effect. /// #[derive(Debug, Deserialize, Clone, Getters)] @@ -88,7 +88,6 @@ pub struct Embedded { records: Vec, } - /// Represents the response to a request for listing all effects from the Stellar Horizon API. /// /// This struct contains the overall structure of the response for querying all effects. It includes @@ -99,7 +98,8 @@ pub struct EffectsResponse { /// Navigational links for the current, next, and previous pages of the response. _links: EffectsResponseLink, /// Contains the actual list of effect records in the `records` field. - _embedded: Embedded, + #[serde(rename = "_embedded")] + embedded: Embedded, } impl Response for EffectsResponse { diff --git a/src/horizon_client.rs b/src/horizon_client.rs index 74cd622..47ba807 100644 --- a/src/horizon_client.rs +++ b/src/horizon_client.rs @@ -81,7 +81,7 @@ impl HorizonClient { /// .await; /// /// // Access the account details - /// for record in response?._embedded().records() { + /// for record in response?.embedded().records() { /// println!("Account ID: {}", record.account_id()); /// // Further processing... /// } @@ -184,7 +184,7 @@ impl HorizonClient { /// let response = horizon_client.get_all_assets(&request).await; /// /// // Access asset details - /// for asset in response?._embedded().records() { + /// for asset in response?.embedded().records() { /// println!("Asset Code: {}", asset.asset_code()); /// // Further processing... /// } @@ -343,7 +343,7 @@ impl HorizonClient { /// /// // Access the effects /// if let Ok(effects_response) = response { - /// for effect in effects_response._embedded().records() { + /// for effect in effects_response.embedded().records() { /// println!("Effect ID: {}", effect.id()); /// // Further processing... /// } @@ -387,14 +387,14 @@ impl HorizonClient { /// # let base_url = "https://horizon-testnet.stellar.org".to_string(); /// # let horizon_client = HorizonClient::new(base_url) /// # .expect("Failed to create Horizon Client"); - /// let request = EffectsForAccountRequest::new() - /// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()); + /// let request = EffectsForLiquidityPoolRequest::new() + /// .set_liquidity_pool_id("01c58ab8fb283c8b083a26bf2fe06b7b6c6304c13f9d29d956cdf15a48bea72d".to_string()); /// - /// let response = horizon_client.get_effects_for_account(&request).await; + /// let response = horizon_client.get_effects_for_liquidity_pools(&request).await; /// /// // Access the effects /// if let Ok(effects_response) = response { - /// for effect in effects_response._embedded().records() { + /// for effect in effects_response.embedded().records() { /// println!("Effect ID: {}", effect.id()); /// // Further processing... /// } @@ -445,7 +445,7 @@ impl HorizonClient { /// /// // Access the effects /// if let Ok(effects_response) = response { - /// for effect in effects_response._embedded().records() { + /// for effect in effects_response.embedded().records() { /// println!("Effect ID: {}", effect.id()); /// // Further processing... /// } @@ -502,7 +502,7 @@ impl HorizonClient { /// // Process the response /// match response { /// Ok(ledgers_response) => { - /// for ledger in ledgers_response._embedded().records() { + /// for ledger in ledgers_response.embedded().records() { /// println!("Ledger ID: {}", ledger.id()); /// // Further processing... /// } @@ -609,7 +609,7 @@ impl HorizonClient { /// /// // Access the effects /// if let Ok(effects_response) = response { - /// for effect in effects_response._embedded().records() { + /// for effect in effects_response.embedded().records() { /// println!("Effect ID: {}", effect.id()); /// // Further processing... /// } @@ -863,135 +863,135 @@ mod tests { assert!(_accounts_response.is_ok()); assert_eq!( - _accounts_response.clone().unwrap()._embedded().records()[0].account_id(), + _accounts_response.clone().unwrap().embedded().records()[0].account_id(), ACCOUNT_ID ); assert_eq!( - _accounts_response.clone().unwrap()._embedded().records()[0].id(), + _accounts_response.clone().unwrap().embedded().records()[0].id(), ACCOUNT_ID ); assert_eq!( - _accounts_response.clone().unwrap()._embedded().records()[0].sequence(), + _accounts_response.clone().unwrap().embedded().records()[0].sequence(), SEQUENCE ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].subentry_count(), + *_accounts_response.clone().unwrap().embedded().records()[0].subentry_count(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].last_modified_ledger(), + *_accounts_response.clone().unwrap().embedded().records()[0].last_modified_ledger(), LAST_MODIFIED_LEDGER ); assert_eq!( - _accounts_response.clone().unwrap()._embedded().records()[0].last_modified_time(), + _accounts_response.clone().unwrap().embedded().records()[0].last_modified_time(), LAST_MODIFIED_TIME ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .thresholds() .low_threshold(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .thresholds() .med_threshold(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .thresholds() .high_threshold(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .flags() .auth_required(), false ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .flags() .auth_revocable(), false ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .flags() .auth_immutable(), false ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0] + *_accounts_response.clone().unwrap().embedded().records()[0] .flags() .auth_clawback_enabled(), false ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].balances()[0].balance(), + *_accounts_response.clone().unwrap().embedded().records()[0].balances()[0].balance(), "10000.0000000".to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].balances()[0] + *_accounts_response.clone().unwrap().embedded().records()[0].balances()[0] .asset_type(), "native".to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].balances()[0] + *_accounts_response.clone().unwrap().embedded().records()[0].balances()[0] .buying_liabilities(), "0.0000000".to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].balances()[0] + *_accounts_response.clone().unwrap().embedded().records()[0].balances()[0] .selling_liabilities(), "0.0000000".to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].signers()[0].key(), + *_accounts_response.clone().unwrap().embedded().records()[0].signers()[0].key(), ACCOUNT_ID.to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].signers()[0].weight(), + *_accounts_response.clone().unwrap().embedded().records()[0].signers()[0].weight(), 1 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].signers()[0] + *_accounts_response.clone().unwrap().embedded().records()[0].signers()[0] .signer_type(), "ed25519_public_key".to_string() ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].num_sponsoring(), + *_accounts_response.clone().unwrap().embedded().records()[0].num_sponsoring(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].num_sponsored(), + *_accounts_response.clone().unwrap().embedded().records()[0].num_sponsored(), 0 ); assert_eq!( - *_accounts_response.clone().unwrap()._embedded().records()[0].paging_token(), + *_accounts_response.clone().unwrap().embedded().records()[0].paging_token(), ACCOUNT_ID.to_string() ); } @@ -1196,104 +1196,104 @@ mod tests { assert!(_all_assets_response.is_ok()); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].asset_type(), + _all_assets_response.clone().unwrap().embedded().records()[0].asset_type(), asset_type ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].asset_code(), + _all_assets_response.clone().unwrap().embedded().records()[0].asset_code(), asset_code ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].asset_issuer(), + _all_assets_response.clone().unwrap().embedded().records()[0].asset_issuer(), asset_issuer ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].paging_token(), + _all_assets_response.clone().unwrap().embedded().records()[0].paging_token(), paging_token ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].paging_token(), + _all_assets_response.clone().unwrap().embedded().records()[0].paging_token(), &format!("{}_{}_{}", asset_code, asset_issuer, asset_type) ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0].num_accounts(), + *_all_assets_response.clone().unwrap().embedded().records()[0].num_accounts(), num_accounts ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .num_claimable_balances(), 0 ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0].num_liquidity_pools(), + *_all_assets_response.clone().unwrap().embedded().records()[0].num_liquidity_pools(), 0 ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].amount(), + _all_assets_response.clone().unwrap().embedded().records()[0].amount(), amount ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .accounts() .authorized(), num_authorized ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .accounts() .authorized_to_maintain_liabilities(), 2 ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .accounts() .unauthorized(), num_unauthorized ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0] + _all_assets_response.clone().unwrap().embedded().records()[0] .claimable_balances_amount(), "0.0000000" ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].liquidity_pools_amount(), + _all_assets_response.clone().unwrap().embedded().records()[0].liquidity_pools_amount(), "0.0000000" ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0].contracts_amount(), + _all_assets_response.clone().unwrap().embedded().records()[0].contracts_amount(), "0.0000000" ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0] + _all_assets_response.clone().unwrap().embedded().records()[0] .balances() .authorized(), balances_authorized ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0] + _all_assets_response.clone().unwrap().embedded().records()[0] .balances() .authorized_to_maintain_liabilities(), "1.0000000" ); assert_eq!( - _all_assets_response.clone().unwrap()._embedded().records()[0] + _all_assets_response.clone().unwrap().embedded().records()[0] .balances() .unauthorized(), balances_unauthorized @@ -1301,28 +1301,28 @@ mod tests { let auth_required = true; assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .flags() .auth_required(), auth_required ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .flags() .auth_revocable(), true ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .flags() .auth_immutable(), false ); assert_eq!( - *_all_assets_response.clone().unwrap()._embedded().records()[0] + *_all_assets_response.clone().unwrap().embedded().records()[0] .flags() .auth_clawback_enabled(), true @@ -1346,28 +1346,28 @@ mod tests { assert!(_all_ledgers_response.clone().is_ok()); assert_eq!( - _all_ledgers_response.clone().unwrap()._embedded().records()[0].hash(), + _all_ledgers_response.clone().unwrap().embedded().records()[0].hash(), hash ); assert_eq!( - _all_ledgers_response.clone().unwrap()._embedded().records()[0].prev_hash(), + _all_ledgers_response.clone().unwrap().embedded().records()[0].prev_hash(), prev_hash ); assert_eq!( - *_all_ledgers_response.clone().unwrap()._embedded().records()[0].sequence(), + *_all_ledgers_response.clone().unwrap().embedded().records()[0].sequence(), 2 ); assert_eq!( - *_all_ledgers_response.clone().unwrap()._embedded().records()[0] + *_all_ledgers_response.clone().unwrap().embedded().records()[0] .successful_transaction_count(), 0 ); assert_eq!( - _all_ledgers_response.clone().unwrap()._embedded().records()[0].paging_token(), + _all_ledgers_response.clone().unwrap().embedded().records()[0].paging_token(), "8589934592" ); } @@ -1739,7 +1739,7 @@ mod tests { _all_effects_response .clone() .unwrap() - ._embedded() + .embedded() .records() .len() as u8, num_records_to_fetch @@ -1747,13 +1747,13 @@ mod tests { // test first record retrieved assert_eq!( - _all_effects_response.clone().unwrap()._embedded().records()[0].type_i, + _all_effects_response.clone().unwrap().embedded().records()[0].type_i, 0 ); // test second record retrieved assert_eq!( - _all_effects_response.clone().unwrap()._embedded().records()[1].type_i, + _all_effects_response.clone().unwrap().embedded().records()[1].type_i, 3 ); } @@ -1785,7 +1785,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .id(), ID @@ -1794,7 +1794,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .paging_token(), PAGING_TOKEN @@ -1803,7 +1803,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .account(), ACCOUNT @@ -1812,7 +1812,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .effect_type(), RECORD_TYPE @@ -1821,7 +1821,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .type_i(), &TYPE_I @@ -1830,7 +1830,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .created_at(), CREATED_AT @@ -1839,7 +1839,7 @@ mod tests { effects_for_account_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .starting_balance() .as_ref() @@ -1873,7 +1873,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .id(), ID @@ -1883,7 +1883,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .paging_token(), PAGING_TOKEN @@ -1893,7 +1893,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .account(), ACCOUNT @@ -1903,7 +1903,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .effect_type(), RECORD_TYPE @@ -1913,7 +1913,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .type_i(), &TYPE_I @@ -1923,7 +1923,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .created_at(), CREATED_AT @@ -1933,7 +1933,7 @@ mod tests { effects_for_liquidity_pools_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .starting_balance() .as_ref() @@ -1955,7 +1955,7 @@ mod tests { effects_for_liquidity_pools_response_with_id .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .id(), "0001072977319841793-0000000001" @@ -1988,7 +1988,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .id(), ID @@ -1998,7 +1998,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .paging_token(), PAGING_TOKEN @@ -2008,7 +2008,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .account(), ACCOUNT @@ -2018,7 +2018,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .effect_type(), RECORD_TYPE @@ -2028,7 +2028,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .type_i(), &TYPE_I @@ -2038,7 +2038,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .created_at(), CREATED_AT @@ -2048,7 +2048,7 @@ mod tests { effects_for_transaction_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .starting_balance() .as_ref() @@ -2079,7 +2079,7 @@ async fn test_get_effects_for_ledger() { _effects_for_ledger_response .clone() .unwrap() - ._embedded() + .embedded() .records()[0] .id, "0000000536870916097-0000000001" @@ -2089,7 +2089,7 @@ async fn test_get_effects_for_ledger() { _effects_for_ledger_response .clone() .unwrap() - ._embedded() + .embedded() .records()[1] .effect_type, "account_debited" diff --git a/src/ledgers/ledgers_response.rs b/src/ledgers/ledgers_response.rs index 4234596..28e62c3 100644 --- a/src/ledgers/ledgers_response.rs +++ b/src/ledgers/ledgers_response.rs @@ -96,7 +96,8 @@ pub struct LedgersResponse { /// Navigational links for the current, next, and previous pages of the response. _links: LedgersResponseLink, /// Contains the actual list of ledger records in the `records` field. - _embedded: Embedded, + #[serde(rename = "_embedded")] + embedded: Embedded, } impl Response for LedgersResponse {