Skip to content

Commit

Permalink
Impl into string for String parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Luijken committed Sep 10, 2024
1 parent 0aefc0e commit bee4063
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub mod test {

// construct request
let single_account_request = SingleAccountRequest::new()
.set_account_id(ACCOUNT_ID.to_string())
.set_account_id(ACCOUNT_ID)
.unwrap();

let single_account_response = horizon_client
Expand Down
5 changes: 3 additions & 2 deletions stellar_rust_sdk/src/accounts/single_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct NoAccountId;
/// # use stellar_rs::accounts::prelude::SingleAccountRequest;
/// # use stellar_rs::models::Request;
/// let request = SingleAccountRequest::new()
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
/// .unwrap();
/// // Use with HorizonClient::get_single_account
/// ```
Expand All @@ -52,8 +52,9 @@ impl SingleAccountRequest<NoAccountId> {
///
pub fn set_account_id(
self,
account_id: String,
account_id: impl Into<String>,
) -> Result<SingleAccountRequest<AccountId>, String> {
let account_id = account_id.into();
if let Err(e) = is_public_key(&account_id) {
return Err(e.to_string());
}
Expand Down
6 changes: 3 additions & 3 deletions stellar_rust_sdk/src/effects/effects_for_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl EffectsForAccountRequest {
/// # Arguments
/// * `account_id` - A `String` value representing the account id.
///
pub fn set_account_id(self, account_id: String) -> EffectsForAccountRequest {
pub fn set_account_id(self, account_id: impl Into<String>) -> EffectsForAccountRequest {
EffectsForAccountRequest {
account_id: Some(account_id),
account_id: Some(account_id.into()),
..self
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ mod tests {
#[test]
fn test_effects_for_account_request_with_params() {
let request = EffectsForAccountRequest::new()
.set_account_id("GBL3QJ2MB3KJ7YV7YVXJ5ZL5V6Z5ZL5V6Z5ZL5V6Z5ZL5V6Z5ZL5V6Z".to_string())
.set_account_id("GBL3QJ2MB3KJ7YV7YVXJ5ZL5V6Z5ZL5V6Z5ZL5V6Z5ZL5V6Z5ZL5V6Z")
.set_cursor(1)
.unwrap()
.set_limit(10)
Expand Down
18 changes: 8 additions & 10 deletions stellar_rust_sdk/src/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ impl HorizonClient {
/// .expect("Failed to create HorizonClient");
/// ```
pub fn new(base_url: impl Into<String>) -> Result<Self, String> {
let base_url_val = base_url.into();
url_validate(&base_url_val)?;
Ok(Self {
base_url: base_url_val,
})
let base_url = base_url.into();
url_validate(&base_url)?;
Ok(Self { base_url })
}

/// Sends a GET request to the Horizon server and retrieves a specified response type.
Expand Down Expand Up @@ -266,7 +264,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = SingleAccountRequest::new()
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
/// .unwrap();
///
/// let response = horizon_client.get_single_account(&request).await;
Expand Down Expand Up @@ -476,7 +474,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = EffectsForAccountRequest::new()
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string());
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7");
///
/// let response = horizon_client.get_effects_for_account(&request).await;
///
Expand Down Expand Up @@ -527,7 +525,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = EffectsForAccountRequest::new()
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string());
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7");
///
/// let response = horizon_client.get_effects_for_account(&request).await;
///
Expand Down Expand Up @@ -1508,7 +1506,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = TradesForAccountRequest::new()
/// .set_account_id("GCUOMNFW7YG55YHY5S5W7FE247PWODUDUZ4SOVZFEON47KZ7AXFG6D6A".to_string())
/// .set_account_id("GCUOMNFW7YG55YHY5S5W7FE247PWODUDUZ4SOVZFEON47KZ7AXFG6D6A")
/// .unwrap();
///
/// let response = horizon_client.get_trades_for_account(&request).await;
Expand Down Expand Up @@ -1864,7 +1862,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = TransactionsForAccountRequest::new()
/// .set_account_id("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H".to_string()).unwrap()
/// .set_account_id("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H").unwrap()
/// .set_include_failed(true).unwrap();
///
/// let response = horizon_client.get_transactions_for_account(&request).await;
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/offers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub mod test {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

let offers_for_account_request = OffersForAccountRequest::new()
.set_account_id(ACCOUNT_ID.to_string())
.set_account_id(ACCOUNT_ID)
.unwrap();

let offers_for_account_response = horizon_client
Expand Down
3 changes: 2 additions & 1 deletion stellar_rust_sdk/src/offers/offers_for_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ impl OffersForAccountRequest<NoOfferAccountId> {

pub fn set_account_id(
self,
account_id: String,
account_id: impl Into<String>
) -> Result<OffersForAccountRequest<OfferAccountId>, String> {
let account_id = account_id.into();
if let Err(e) = is_public_key(&account_id) {
return Err(e.to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub mod tests {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

let operations_for_account_request = OperationsForAccountRequest::new()
.set_account_id(ACCOUNT_ID.to_string())
.set_account_id(ACCOUNT_ID)
.set_limit(2)
.unwrap()
.set_cursor(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl OperationsForAccountRequest {
/// # Arguments
/// * `account_id` - A `String` representing the account ID.
///
pub fn set_account_id(self, account_id: String) -> OperationsForAccountRequest {
pub fn set_account_id(self, account_id: impl Into<String>) -> OperationsForAccountRequest {
OperationsForAccountRequest {
account_id: Some(account_id),
account_id: Some(account_id.into()),
..self
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl OperationsForLedgerRequest {
/// # Arguments
/// * `account_id` - A `String` representing the account ID.
///
pub fn set_account_id(self, ledger_sequence: String) -> OperationsForLedgerRequest {
pub fn set_account_id(self, ledger_sequence: impl Into<String>) -> OperationsForLedgerRequest {
OperationsForLedgerRequest {
ledger_sequence: Some(ledger_sequence),
ledger_sequence: Some(ledger_sequence.into()),
..self
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
.set_order(Order::Desc)
.unwrap()
.set_include_failed(IncludeFailed::True)
.set_account_id("00000000".to_string());
.set_account_id("00000000");

assert_eq!(
request.get_query_parameters(),
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/payments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub mod test {

let payments_for_account_request: PaymentsForAccountRequest =
PaymentsForAccountRequest::new().set_account_id(
"GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H".to_string(),
"GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H",
);

let response: Result<PaymentsResponse, String> = horizon_client
Expand Down
4 changes: 2 additions & 2 deletions stellar_rust_sdk/src/payments/payments_for_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl PaymentsForAccountRequest {
/// # Arguments
/// * `account_id` - The Stellar address of the account for which you want to retrieve payments.
///
pub fn set_account_id(mut self, account_id: String) -> PaymentsForAccountRequest {
self.account_id = Some(account_id);
pub fn set_account_id(mut self, account_id: impl Into<String>) -> PaymentsForAccountRequest {
self.account_id = Some(account_id.into());
self
}

Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/trades/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub mod test {
const PRICE_R: &str = "10";

let trades_for_account_request = TradesForAccountRequest::new()
.set_account_id(ACCOUNT_ID.to_string())
.set_account_id(ACCOUNT_ID)
.unwrap();
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();
let trades_for_account_response = horizon_client
Expand Down
3 changes: 2 additions & 1 deletion stellar_rust_sdk/src/trades/trades_for_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ impl TradesForAccountRequest<NoTradeAccountId> {
///
pub fn set_account_id(
self,
account_id: String,
account_id: impl Into<String>
) -> Result<TradesForAccountRequest<TradeAccountId>, String> {
let account_id = account_id.into();
if let Err(e) = is_public_key(&account_id) {
return Err(e.to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub mod test {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

let transactions_for_account_request = TransactionsForAccountRequest::new()
.set_account_id("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H".to_string())
.set_account_id("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H")
.unwrap()
.set_include_failed(true)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ impl TransactionsForAccountRequest<NoTransactionsAccountId> {
///
pub fn set_account_id(
self,
account_id: String,
account_id: impl Into<String>
) -> Result<TransactionsForAccountRequest<TransactionsAccountId>, String> {
Ok(TransactionsForAccountRequest {
account_id: TransactionsAccountId(account_id),
account_id: TransactionsAccountId(account_id.into()),
include_failed: self.include_failed,
cursor: self.cursor,
limit: self.limit,
Expand Down

0 comments on commit bee4063

Please sign in to comment.