From 8d15b7c9d741cf31f70873e366f7774eafba2bf1 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Tue, 9 Apr 2024 13:54:17 +0200 Subject: [PATCH 1/4] operations for liquiditypools request --- .../operations_for_liquidity_pool_request.rs | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs index 8b13789..afa1c29 100644 --- a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs @@ -1 +1,148 @@ +use crate::{ + models::{IncludeFailed, Order, Request}, + BuildQueryParametersExt, +}; +use super::operations_for_account_request::OperationsForAccountRequest; + +#[derive(Default)] +pub struct OperationsForLiquidityPoolRequest { + /// A unique identifier for the liquidity pool of the operation(s). + liquidity_pool_id: Option, + /// A number that points to a specific location in a collection of responses and is pulled + /// from the paging_token value of a record. + cursor: Option, + /// The maximum number of records returned. The limit can range from 1 to 200 - an upper limit + /// that is hardcoded in Horizon for performance reasons. If this argument isn’t designated, it + /// defaults to 10. + limit: Option, + /// A designation of the [`Order`] in which records should appear. Options include [`Order::Asc`] (ascending) + /// or [`Order::Desc`] (descending). If this argument isn’t set, it defaults to asc. + order: Option, + /// Set to true to include failed operations in results. Options include true and false. + include_failed: Option, +} + +impl OperationsForLiquidityPoolRequest { + pub fn new() -> Self { + OperationsForLiquidityPoolRequest::default() + } + + /// 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(OperationsForLiquidityPoolRequest { + 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(OperationsForLiquidityPoolRequest { + 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) -> OperationsForLiquidityPoolRequest { + OperationsForLiquidityPoolRequest { + order: Some(order), + ..self + } + } + + /// Sets whether to include failed operations in the response. + /// + /// # Arguments + /// * `include_failed` - A boolean value that determines whether to include failed operations in the response. + /// + pub fn set_include_failed( + self, + include_failed: IncludeFailed, + ) -> OperationsForLiquidityPoolRequest { + OperationsForLiquidityPoolRequest { + include_failed: Some(include_failed), + ..self + } + } + + /// Sets the account ID for which to retrieve operations. + /// + /// # Arguments + /// * `account_id` - A `String` representing the account ID. + /// + pub fn set_account_id(self, liquidity_pool_id: String) -> OperationsForLiquidityPoolRequest { + OperationsForLiquidityPoolRequest { + liquidity_pool_id: Some(liquidity_pool_id), + ..self + } + } +} + +impl Request for OperationsForLiquidityPoolRequest { + fn get_query_parameters(&self) -> String { + vec![ + 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)), + self.include_failed + .as_ref() + .map(|i| format!("include_failed={}", i)), + ] + .build_query_parameters() + } + fn build_url(&self, base_url: &str) -> String { + let binding = "".to_string(); + let liquidity_pool_id = self.liquidity_pool_id.as_ref().unwrap_or(&binding); + format!( + "{}/liquidity_pools/{}/{}?{}", + base_url, + liquidity_pool_id, + super::OPERATIONS_PATH, + self.get_query_parameters(), + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::models::Order; + + #[test] + fn test_all_operations_request() { + let request = OperationsForLiquidityPoolRequest::new() + .set_cursor(1) + .unwrap() + .set_limit(10) + .unwrap() + .set_order(Order::Desc) + .set_include_failed(IncludeFailed::True); + + assert_eq!( + request.get_query_parameters(), + "?cursor=1&limit=10&order=desc&include_failed=true" + ); + } +} From 0791d01ebe51ea6a0bd66b2ee7c50467b7dcd75c Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Tue, 9 Apr 2024 14:33:19 +0200 Subject: [PATCH 2/4] reponse and tests and documentation --- stellar_rust_sdk/src/horizon_client.rs | 115 +++++++++++++----- stellar_rust_sdk/src/operations/mod.rs | 81 +++++++++++- .../operations_for_ledger_request.rs | 8 -- .../operations_for_liquidity_pool_request.rs | 4 +- 4 files changed, 164 insertions(+), 44 deletions(-) diff --git a/stellar_rust_sdk/src/horizon_client.rs b/stellar_rust_sdk/src/horizon_client.rs index ae4d36f..df36b36 100644 --- a/stellar_rust_sdk/src/horizon_client.rs +++ b/stellar_rust_sdk/src/horizon_client.rs @@ -12,14 +12,19 @@ use crate::{ prelude::{Ledger, LedgersRequest, LedgersResponse, SingleLedgerRequest}, single_ledger_request::Sequence, }, - liquidity_pools::{all_liquidity_pools_request::AllLiquidityPoolsRequest, prelude::{ - AllLiquidityPoolsResponse, LiquidityPool, LiquidityPoolId, - SingleLiquidityPoolRequest, - }}, + liquidity_pools::{ + all_liquidity_pools_request::AllLiquidityPoolsRequest, + prelude::{ + AllLiquidityPoolsResponse, LiquidityPool, LiquidityPoolId, SingleLiquidityPoolRequest, + }, + }, models::{Request, Response}, operations::{ operations_for_account_request::OperationsForAccountRequest, - prelude::{AllOperationsRequest, OperationResponse, OperationsForLedgerRequest}, + prelude::{ + AllOperationsRequest, OperationResponse, OperationsForLedgerRequest, + OperationsForLiquidityPoolRequest, + }, response::Operation, single_operation_request::{OperationId, SingleOperationRequest}, }, @@ -739,23 +744,23 @@ impl HorizonClient { } /// Retrieves a list of all fee stats from the Horizon server. - /// + /// /// This asynchronous method fetches a list of all fee stats from the Horizon server. /// It requires a [`FeeStatsRequest`] to specify the optional query parameters. - /// + /// /// # Arguments /// * `request` - A reference to a [`FeeStatsRequest`] instance, containing the /// parameters for the fee stats request. - /// + /// /// # Returns - /// + /// /// On successful execution, returns a `Result` containing a [`FeeStatsResponse`], which includes /// the list of all fee stats obtained from the Horizon server. If the request fails, it returns an error within `Result`. - /// + /// /// # Usage /// To use this method, create an instance of [`FeeStatsRequest`] and set any desired /// filters or parameters. - /// + /// /// ``` /// # use stellar_rs::fee_stats::fee_stats_request::FeeStatsRequest; /// # use stellar_rs::horizon_client::HorizonClient; @@ -765,9 +770,9 @@ impl HorizonClient { /// # let horizon_client = HorizonClient::new(base_url) /// # .expect("Failed to create Horizon Client"); /// let request = FeeStatsRequest::new(); - /// + /// /// let response = horizon_client.get_fee_stats(&request).await; - /// + /// /// // Access the fee stats /// if let Ok(fee_stats_response) = response { /// println!("Max Fee: {:?}", fee_stats_response.max_fee()); @@ -776,7 +781,7 @@ impl HorizonClient { /// # Ok({}) /// # } /// ``` - /// + /// pub async fn get_fee_stats( &self, request: &FeeStatsRequest, @@ -835,22 +840,22 @@ impl HorizonClient { } /// Retrieves detailed information for a specific operation from the Horizon server. - /// + /// /// This asynchronous method fetches details of a single operation from the Horizon server. /// It requires a [`SingleOperationRequest`] parameterized with `OperationId`, which includes the unique identifier /// of the operation to be retrieved. - /// + /// /// # Arguments /// * `request` - A reference to a [`SingleOperationRequest`] instance containing the unique ID of the operation to be fetched. - /// + /// /// # Returns - /// + /// /// Returns a `Result` containing an [`Operation`], which includes detailed information about the requested operation. /// If the request fails, it returns an error encapsulated within `Result`. - /// + /// /// # Usage /// To use this method, create an instance of [`SingleOperationRequest`] and set the unique ID of the operation to be queried. - /// + /// /// ``` /// # use stellar_rs::operations::prelude::*; /// # use stellar_rs::models::Request; @@ -862,9 +867,9 @@ impl HorizonClient { /// # .expect("Failed to create Horizon Client"); /// let request = SingleOperationRequest::new() /// .set_operation_id("459561504769".to_string()); - /// + /// /// let response = horizon_client.get_single_operation(&request).await; - /// + /// /// if let Ok(operation) = response { /// println!("Operation ID: {}", operation.id()); /// // Additional processing... @@ -881,23 +886,23 @@ impl HorizonClient { } /// Retrieves a list of all operations for an account from the Horizon server. - /// + /// /// This asynchronous method fetches a list of all operations for an account from the Horizon server. /// It requires an [`OperationsForAccountRequest`] to specify the optional query parameters. - /// + /// /// # Arguments /// * `request` - A reference to an [`OperationsForAccountRequest`] instance, containing the /// parameters for the operations for account request. /// /// # Returns - /// + /// /// On successful execution, returns a `Result` containing a [`OperationsForAccountRequest`], which includes /// the list of all operations obtained from the Horizon server. If the request fails, it returns an error within `Result`. - /// + /// /// # Usage /// To use this method, create an instance of [`OperationsForAccountRequest`] and set any desired /// filters or parameters. - /// + /// /// ``` /// # use stellar_rs::operations::prelude::*; /// # use stellar_rs::models::Request; @@ -910,9 +915,9 @@ impl HorizonClient { /// # .expect("Failed to create Horizon Client"); /// let request = OperationsForAccountRequest::new() /// .set_limit(2).unwrap(); - /// + /// /// let response = horizon_client.get_operation_for_account(&request).await; - /// + /// /// // Access the payments /// if let Ok(operations_for_account_response) = response { /// for operation in operations_for_account_response.embedded().records() { @@ -923,7 +928,7 @@ impl HorizonClient { /// # Ok({}) /// # } /// ``` - /// + /// pub async fn get_operation_for_account( &self, request: &OperationsForAccountRequest, @@ -938,6 +943,56 @@ impl HorizonClient { self.get::(request).await } + /// Retrieves a list of all operations for a specific liquidity pool from the Horizon server. + /// + /// This asynchronous method fetches a list of all operations for a specific liquidity pool from the Horizon server. + /// It requires an [`OperationsForLiquidityPoolRequest`] to specify the liquidity pool ID and optional query parameters. + /// + /// # Arguments + /// * `request` - A reference to an [`OperationsForLiquidityPoolRequest`] instance, containing the liquidity pool ID + /// and optional query parameters for the operations for liquidity pool request. + /// + /// # Returns + /// + /// On successful execution, returns a `Result` containing a [`OperationResponse`], which includes + /// the list of all operations obtained from the Horizon server. If the request fails, it returns an error within `Result`. + /// + /// # Usage + /// To use this method, create an instance of [`OperationsForLiquidityPoolRequest`] and set the liquidity pool ID and any desired + /// filters or parameters. + /// + /// ``` + /// # use stellar_rs::operations::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 = OperationsForLiquidityPoolRequest::new() + /// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string()); + /// + /// let response = horizon_client.get_operations_for_liquidity_pool(&request).await; + /// + /// // Access the operations + /// if let Ok(operations_for_liquidity_pool_response) = response { + /// for operation in operations_for_liquidity_pool_response.embedded().records() { + /// + /// println!("Operation ID: {}", operation.id()); + /// // Further processing... + /// } + /// } + /// # Ok({}) + /// # } + /// ``` + /// + pub async fn get_operations_for_liquidity_pool( + &self, + request: &OperationsForLiquidityPoolRequest, + ) -> Result { + self.get::(request).await + } /// Sends a GET request to the Horizon server and retrieves a specified response type. /// /// This internal asynchronous method is designed to handle various GET requests to the diff --git a/stellar_rust_sdk/src/operations/mod.rs b/stellar_rust_sdk/src/operations/mod.rs index 9e68b04..fe8d92f 100644 --- a/stellar_rust_sdk/src/operations/mod.rs +++ b/stellar_rust_sdk/src/operations/mod.rs @@ -28,7 +28,9 @@ pub mod tests { models::{IncludeFailed, Order}, operations::{ operations_for_account_request::OperationsForAccountRequest, - prelude::{AllOperationsRequest, OperationsForLedgerRequest}, + prelude::{ + AllOperationsRequest, OperationsForLedgerRequest, OperationsForLiquidityPoolRequest, + }, response::{Operation, OperationResponse}, single_operation_request::SingleOperationRequest, }, Paginatable, @@ -221,14 +223,85 @@ pub mod tests { operation_for_ledger_response.transaction_successful(), &TRANSACTION_SUCCESFULL ); - assert_eq!(operation_for_ledger_response.source_account(), SOURCE_ACCOUNT); + assert_eq!( + operation_for_ledger_response.source_account(), + SOURCE_ACCOUNT + ); assert_eq!(operation_for_ledger_response.type_field(), TYPE); assert_eq!(operation_for_ledger_response.type_i(), &TYPE_I); assert_eq!(operation_for_ledger_response.created_at(), CREATED_AT); - assert_eq!(operation_for_ledger_response.transaction_hash(), TRANSACTION_HASH); - assert_eq!(operation_for_ledger_response.starting_balance(), STARTING_BALANCE); + assert_eq!( + operation_for_ledger_response.transaction_hash(), + TRANSACTION_HASH + ); + assert_eq!( + operation_for_ledger_response.starting_balance(), + STARTING_BALANCE + ); assert_eq!(operation_for_ledger_response.funder(), FUNDER); assert_eq!(operation_for_ledger_response.account(), ACCOUNT); + } + + #[tokio::test] + async fn test_get_operations_for_liquidity_pool() { + const ID: &str = "459561504769"; + const PAGING_TOKEN: &str = "459561504769"; + const TRANSACTION_SUCCESFULL: bool = true; + const SOURCE_ACCOUNT: &str = "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"; + const TYPE: &str = "create_account"; + const TYPE_I: i64 = 0; + const CREATED_AT: &str = "2024-02-06T17:42:48Z"; + const TRANSACTION_HASH: &str = + "b9d0b2292c4e09e8eb22d036171491e87b8d2086bf8b265874c8d182cb9c9020"; + const STARTING_BALANCE: &str = "10000000000.0000000"; + const FUNDER: &str = "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"; + const ACCOUNT: &str = "GAIH3ULLFQ4DGSECF2AR555KZ4KNDGEKN4AFI4SU2M7B43MGK3QJZNSR"; + let horizon_client = + horizon_client::HorizonClient::new("https://horizon-testnet.stellar.org".to_string()) + .unwrap(); + + let operations_for_liquidity_pool_request = OperationsForLiquidityPoolRequest::new() + .set_limit(2) + .unwrap(); + + let operation_for_liquidity_pool_response = horizon_client + .get_operations_for_liquidity_pool(&operations_for_liquidity_pool_request) + .await; + + assert!(operation_for_liquidity_pool_response.is_ok()); + + let binding = operation_for_liquidity_pool_response.unwrap(); + let operation_for_liquidity_pool_response = &binding.embedded().records()[0]; + + assert_eq!(operation_for_liquidity_pool_response.id(), ID); + assert_eq!( + operation_for_liquidity_pool_response.paging_token(), + PAGING_TOKEN + ); + assert_eq!( + operation_for_liquidity_pool_response.transaction_successful(), + &TRANSACTION_SUCCESFULL + ); + assert_eq!( + operation_for_liquidity_pool_response.source_account(), + SOURCE_ACCOUNT + ); + assert_eq!(operation_for_liquidity_pool_response.type_field(), TYPE); + assert_eq!(operation_for_liquidity_pool_response.type_i(), &TYPE_I); + assert_eq!( + operation_for_liquidity_pool_response.created_at(), + CREATED_AT + ); + assert_eq!( + operation_for_liquidity_pool_response.transaction_hash(), + TRANSACTION_HASH + ); + assert_eq!( + operation_for_liquidity_pool_response.starting_balance(), + STARTING_BALANCE + ); + assert_eq!(operation_for_liquidity_pool_response.funder(), FUNDER); + assert_eq!(operation_for_liquidity_pool_response.account(), ACCOUNT); } } diff --git a/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs b/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs index 82d97ff..03b719e 100644 --- a/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs @@ -115,14 +115,6 @@ impl Request for OperationsForLedgerRequest { let binding = "".to_string(); let ledger_sequence = self.ledger_sequence.as_ref().unwrap_or(&binding); - println!( - "URL {}/ledgers/{}/{}{}", - base_url, - ledger_sequence, - super::OPERATIONS_PATH, - self.get_query_parameters() - ); - format!( "{}/ledgers/{}/{}{}", base_url, diff --git a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs index afa1c29..eeb039f 100644 --- a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs @@ -92,7 +92,7 @@ impl OperationsForLiquidityPoolRequest { /// # Arguments /// * `account_id` - A `String` representing the account ID. /// - pub fn set_account_id(self, liquidity_pool_id: String) -> OperationsForLiquidityPoolRequest { + pub fn set_liquidity_pool_id(self, liquidity_pool_id: String) -> OperationsForLiquidityPoolRequest { OperationsForLiquidityPoolRequest { liquidity_pool_id: Some(liquidity_pool_id), ..self @@ -116,7 +116,7 @@ impl Request for OperationsForLiquidityPoolRequest { let binding = "".to_string(); let liquidity_pool_id = self.liquidity_pool_id.as_ref().unwrap_or(&binding); format!( - "{}/liquidity_pools/{}/{}?{}", + "{}/liquidity_pools/{}/{}{}", base_url, liquidity_pool_id, super::OPERATIONS_PATH, From ecf6c9e6e901b963cdcac73257622a4cab029e28 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Fri, 12 Apr 2024 15:27:28 +0200 Subject: [PATCH 3/4] Code cleanup --- stellar_rust_sdk/src/operations/mod.rs | 6 +----- .../src/operations/operations_for_liquidity_pool_request.rs | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/stellar_rust_sdk/src/operations/mod.rs b/stellar_rust_sdk/src/operations/mod.rs index fe8d92f..fb97c01 100644 --- a/stellar_rust_sdk/src/operations/mod.rs +++ b/stellar_rust_sdk/src/operations/mod.rs @@ -1,6 +1,3 @@ - -use self::operations_for_account_request::OperationsForAccountRequest; - pub mod all_operations_request; pub mod operations_for_account_request; pub mod operations_for_ledger_request; @@ -16,7 +13,7 @@ pub mod prelude { pub use super::operations_for_account_request::*; pub use super::operations_for_ledger_request::*; pub use super::operations_for_liquidity_pool_request::*; - pub use super::operations_for_transaction_request::*; + //pub use super::operations_for_transaction_request::*; pub use super::response::*; pub use super::single_operation_request::*; } @@ -25,7 +22,6 @@ pub mod prelude { pub mod tests { use crate::{ horizon_client, - models::{IncludeFailed, Order}, operations::{ operations_for_account_request::OperationsForAccountRequest, prelude::{ diff --git a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs index eeb039f..bc233da 100644 --- a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs @@ -3,8 +3,6 @@ use crate::{ BuildQueryParametersExt, }; -use super::operations_for_account_request::OperationsForAccountRequest; - #[derive(Default)] pub struct OperationsForLiquidityPoolRequest { /// A unique identifier for the liquidity pool of the operation(s). From b9daa815431f460e41bcb262304e5391406c7b87 Mon Sep 17 00:00:00 2001 From: LeonardTibben Date: Fri, 12 Apr 2024 15:33:21 +0200 Subject: [PATCH 4/4] Use derive macro for pagination --- .../operations_for_ledger_request.rs | 50 ++----------------- .../operations_for_liquidity_pool_request.rs | 50 ++----------------- 2 files changed, 10 insertions(+), 90 deletions(-) diff --git a/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs b/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs index 03b719e..1223a79 100644 --- a/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs @@ -1,9 +1,12 @@ +use stellar_rust_sdk_derive::Pagination; +use crate::Paginatable; + use crate::{ models::{IncludeFailed, Order, Request}, BuildQueryParametersExt, }; -#[derive(Default)] +#[derive(Default, Pagination)] pub struct OperationsForLedgerRequest { /// The account ID for which to retrieve operations. ledger_sequence: Option, @@ -29,50 +32,6 @@ impl OperationsForLedgerRequest { OperationsForLedgerRequest::default() } - /// 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(OperationsForLedgerRequest { - 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(OperationsForLedgerRequest { - 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) -> OperationsForLedgerRequest { - OperationsForLedgerRequest { - order: Some(order), - ..self - } - } - /// Sets whether to include failed operations in the response. /// /// # Arguments @@ -137,6 +96,7 @@ mod tests { .set_limit(200) .unwrap() .set_order(Order::Desc) + .unwrap() .set_include_failed(IncludeFailed::True) .set_account_id("00000000".to_string()); diff --git a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs index bc233da..8cea2d3 100644 --- a/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_liquidity_pool_request.rs @@ -1,9 +1,12 @@ +use stellar_rust_sdk_derive::Pagination; +use crate::Paginatable; + use crate::{ models::{IncludeFailed, Order, Request}, BuildQueryParametersExt, }; -#[derive(Default)] +#[derive(Default, Pagination)] pub struct OperationsForLiquidityPoolRequest { /// A unique identifier for the liquidity pool of the operation(s). liquidity_pool_id: Option, @@ -26,50 +29,6 @@ impl OperationsForLiquidityPoolRequest { OperationsForLiquidityPoolRequest::default() } - /// 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(OperationsForLiquidityPoolRequest { - 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(OperationsForLiquidityPoolRequest { - 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) -> OperationsForLiquidityPoolRequest { - OperationsForLiquidityPoolRequest { - order: Some(order), - ..self - } - } - /// Sets whether to include failed operations in the response. /// /// # Arguments @@ -136,6 +95,7 @@ mod tests { .set_limit(10) .unwrap() .set_order(Order::Desc) + .unwrap() .set_include_failed(IncludeFailed::True); assert_eq!(