Skip to content

Commit c78fd9d

Browse files
committed
Add to transactions for account request
1 parent e9dd0c6 commit c78fd9d

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

stellar_rust_sdk/src/transactions/transactions_for_account_request.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::models::*;
1+
use crate::{models::*, BuildQueryParametersExt};
22
use stellar_rust_sdk_derive::Pagination;
33
use crate::Paginatable;
44

@@ -14,6 +14,8 @@ pub struct NoTransactionsAccountId;
1414
pub struct TransactionsForAccountRequest<I> {
1515
/// The ID of the account for which the transactions are to be retrieved.
1616
account_id: I,
17+
// Indicates whether or not to include failed operations in the response.
18+
include_failed: Option<bool>,
1719
/// A pointer to a specific location in a collection of responses, derived from the
1820
/// `paging_token` value of a record. Used for pagination control in the API response.
1921
pub cursor: Option<u32>,
@@ -43,12 +45,24 @@ impl TransactionsForAccountRequest<NoTransactionsAccountId> {
4345
self,
4446
account_id: String,
4547
) -> Result<TransactionsForAccountRequest<TransactionsAccountId>, String> {
46-
if let Err(e) = is_public_key(&account_id) {
47-
return Err(e.to_string());
48-
}
49-
5048
Ok(TransactionsForAccountRequest {
5149
account_id: TransactionsAccountId(account_id),
50+
include_failed: self.include_failed,
51+
cursor: self.cursor,
52+
limit: self.limit,
53+
order: self.order,
54+
})
55+
}
56+
}
57+
58+
impl TransactionsForAccountRequest<TransactionsAccountId> {
59+
pub fn set_include_failed(
60+
self,
61+
include_failed: bool,
62+
) -> Result<TransactionsForAccountRequest<TransactionsAccountId>, String> {
63+
Ok(TransactionsForAccountRequest {
64+
account_id: self.account_id,
65+
include_failed: Some(include_failed),
5266
cursor: self.cursor,
5367
limit: self.limit,
5468
order: self.order,
@@ -58,23 +72,28 @@ impl TransactionsForAccountRequest<NoTransactionsAccountId> {
5872

5973
impl Request for TransactionsForAccountRequest<TransactionsAccountId> {
6074
fn get_query_parameters(&self) -> String {
61-
let mut query = String::new();
62-
query.push_str(&format!("{}", self.account_id.0));
63-
64-
query.trim_end_matches('&').to_string()
75+
vec![
76+
self.cursor.as_ref().map(|c| format!("cursor={}", c)),
77+
self.limit.as_ref().map(|l| format!("limit={}", l)),
78+
self.order.as_ref().map(|o| format!("order={}", o)),
79+
self.include_failed
80+
.as_ref()
81+
.map(|i| format!("include_failed={}", i)),
82+
]
83+
.build_query_parameters()
6584
}
6685

6786
fn build_url(&self, base_url: &str) -> String {
68-
// This URL is not built with query paramaters, but with the account ID as addition to the path.
69-
// Therefore there is no `?` but a `/` in the formatted string.
70-
// Additionally, this request uses the API endpoint for `accounts`.
87+
// TODO: Documentation
88+
let account_id = &self.account_id.0;
7189
use crate::accounts::ACCOUNTS_PATH;
7290
format!(
73-
"{}/{}/{}/{}",
91+
"{}/{}/{}/{}{}",
7492
base_url,
7593
ACCOUNTS_PATH,
94+
account_id,
95+
super::TRANSACTIONS_PATH,
7696
self.get_query_parameters(),
77-
super::TRANSACTIONS_PATH
7897
)
7998
}
8099
}

0 commit comments

Comments
 (0)