diff --git a/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs b/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs index 5c5ba08..523ad4a 100644 --- a/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs +++ b/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs @@ -1,4 +1,4 @@ -use crate::models::*; +use crate::{models::*, BuildQueryParametersExt}; use stellar_rust_sdk_derive::Pagination; use crate::Paginatable; @@ -14,6 +14,8 @@ pub struct NoTransactionsAccountId; pub struct TransactionsForAccountRequest { /// The ID of the account for which the transactions are to be retrieved. account_id: I, + // Indicates whether or not to include failed operations in the response. + include_failed: 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. pub cursor: Option, @@ -43,12 +45,24 @@ impl TransactionsForAccountRequest { self, account_id: String, ) -> Result, String> { - if let Err(e) = is_public_key(&account_id) { - return Err(e.to_string()); - } - Ok(TransactionsForAccountRequest { account_id: TransactionsAccountId(account_id), + include_failed: self.include_failed, + cursor: self.cursor, + limit: self.limit, + order: self.order, + }) + } +} + +impl TransactionsForAccountRequest { + pub fn set_include_failed( + self, + include_failed: bool, + ) -> Result, String> { + Ok(TransactionsForAccountRequest { + account_id: self.account_id, + include_failed: Some(include_failed), cursor: self.cursor, limit: self.limit, order: self.order, @@ -58,23 +72,28 @@ impl TransactionsForAccountRequest { impl Request for TransactionsForAccountRequest { fn get_query_parameters(&self) -> String { - let mut query = String::new(); - query.push_str(&format!("{}", self.account_id.0)); - - query.trim_end_matches('&').to_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 { - // This URL is not built with query paramaters, but with the account ID as addition to the path. - // Therefore there is no `?` but a `/` in the formatted string. - // Additionally, this request uses the API endpoint for `accounts`. + // TODO: Documentation + let account_id = &self.account_id.0; use crate::accounts::ACCOUNTS_PATH; format!( - "{}/{}/{}/{}", + "{}/{}/{}/{}{}", base_url, ACCOUNTS_PATH, + account_id, + super::TRANSACTIONS_PATH, self.get_query_parameters(), - super::TRANSACTIONS_PATH ) } } \ No newline at end of file