From bee4063dfe0d16008a78926411fa5a50416d9639 Mon Sep 17 00:00:00 2001 From: Thomas Luijken Date: Tue, 10 Sep 2024 16:45:56 +0200 Subject: [PATCH] Impl into string for String parameters --- stellar_rust_sdk/src/accounts/mod.rs | 2 +- .../src/accounts/single_account_request.rs | 5 +++-- .../src/effects/effects_for_account_request.rs | 6 +++--- stellar_rust_sdk/src/horizon_client.rs | 18 ++++++++---------- stellar_rust_sdk/src/offers/mod.rs | 2 +- .../src/offers/offers_for_account_request.rs | 3 ++- stellar_rust_sdk/src/operations/mod.rs | 2 +- .../operations_for_account_request.rs | 4 ++-- .../operations_for_ledger_request.rs | 6 +++--- stellar_rust_sdk/src/payments/mod.rs | 2 +- .../payments/payments_for_account_request.rs | 4 ++-- stellar_rust_sdk/src/trades/mod.rs | 2 +- .../src/trades/trades_for_account_request.rs | 3 ++- stellar_rust_sdk/src/transactions/mod.rs | 2 +- .../transactions_for_account_request.rs | 4 ++-- 15 files changed, 33 insertions(+), 32 deletions(-) diff --git a/stellar_rust_sdk/src/accounts/mod.rs b/stellar_rust_sdk/src/accounts/mod.rs index 2a55d9c..18dcf60 100644 --- a/stellar_rust_sdk/src/accounts/mod.rs +++ b/stellar_rust_sdk/src/accounts/mod.rs @@ -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 diff --git a/stellar_rust_sdk/src/accounts/single_account_request.rs b/stellar_rust_sdk/src/accounts/single_account_request.rs index a98c38b..f8c4efb 100644 --- a/stellar_rust_sdk/src/accounts/single_account_request.rs +++ b/stellar_rust_sdk/src/accounts/single_account_request.rs @@ -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 /// ``` @@ -52,8 +52,9 @@ impl SingleAccountRequest { /// pub fn set_account_id( self, - account_id: String, + account_id: impl Into, ) -> Result, String> { + let account_id = account_id.into(); if let Err(e) = is_public_key(&account_id) { return Err(e.to_string()); } diff --git a/stellar_rust_sdk/src/effects/effects_for_account_request.rs b/stellar_rust_sdk/src/effects/effects_for_account_request.rs index 4101669..fe8a969 100644 --- a/stellar_rust_sdk/src/effects/effects_for_account_request.rs +++ b/stellar_rust_sdk/src/effects/effects_for_account_request.rs @@ -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) -> EffectsForAccountRequest { EffectsForAccountRequest { - account_id: Some(account_id), + account_id: Some(account_id.into()), ..self } } @@ -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) diff --git a/stellar_rust_sdk/src/horizon_client.rs b/stellar_rust_sdk/src/horizon_client.rs index 428195f..5a0cfe6 100644 --- a/stellar_rust_sdk/src/horizon_client.rs +++ b/stellar_rust_sdk/src/horizon_client.rs @@ -68,11 +68,9 @@ impl HorizonClient { /// .expect("Failed to create HorizonClient"); /// ``` pub fn new(base_url: impl Into) -> Result { - 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. @@ -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; @@ -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; /// @@ -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; /// @@ -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; @@ -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; diff --git a/stellar_rust_sdk/src/offers/mod.rs b/stellar_rust_sdk/src/offers/mod.rs index 9221009..2445734 100644 --- a/stellar_rust_sdk/src/offers/mod.rs +++ b/stellar_rust_sdk/src/offers/mod.rs @@ -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 diff --git a/stellar_rust_sdk/src/offers/offers_for_account_request.rs b/stellar_rust_sdk/src/offers/offers_for_account_request.rs index 15f19d7..1fca63d 100644 --- a/stellar_rust_sdk/src/offers/offers_for_account_request.rs +++ b/stellar_rust_sdk/src/offers/offers_for_account_request.rs @@ -24,8 +24,9 @@ impl OffersForAccountRequest { pub fn set_account_id( self, - account_id: String, + account_id: impl Into ) -> Result, String> { + let account_id = account_id.into(); if let Err(e) = is_public_key(&account_id) { return Err(e.to_string()); } diff --git a/stellar_rust_sdk/src/operations/mod.rs b/stellar_rust_sdk/src/operations/mod.rs index b7878b3..0218395 100644 --- a/stellar_rust_sdk/src/operations/mod.rs +++ b/stellar_rust_sdk/src/operations/mod.rs @@ -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) diff --git a/stellar_rust_sdk/src/operations/operations_for_account_request.rs b/stellar_rust_sdk/src/operations/operations_for_account_request.rs index 89ab8cf..667e37c 100644 --- a/stellar_rust_sdk/src/operations/operations_for_account_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_account_request.rs @@ -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) -> OperationsForAccountRequest { OperationsForAccountRequest { - account_id: Some(account_id), + account_id: Some(account_id.into()), ..self } } 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 5c8fb34..c3aa483 100644 --- a/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs +++ b/stellar_rust_sdk/src/operations/operations_for_ledger_request.rs @@ -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) -> OperationsForLedgerRequest { OperationsForLedgerRequest { - ledger_sequence: Some(ledger_sequence), + ledger_sequence: Some(ledger_sequence.into()), ..self } } @@ -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(), diff --git a/stellar_rust_sdk/src/payments/mod.rs b/stellar_rust_sdk/src/payments/mod.rs index b1f989d..bb48fb7 100644 --- a/stellar_rust_sdk/src/payments/mod.rs +++ b/stellar_rust_sdk/src/payments/mod.rs @@ -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 = horizon_client diff --git a/stellar_rust_sdk/src/payments/payments_for_account_request.rs b/stellar_rust_sdk/src/payments/payments_for_account_request.rs index 5995949..37f99c6 100644 --- a/stellar_rust_sdk/src/payments/payments_for_account_request.rs +++ b/stellar_rust_sdk/src/payments/payments_for_account_request.rs @@ -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) -> PaymentsForAccountRequest { + self.account_id = Some(account_id.into()); self } diff --git a/stellar_rust_sdk/src/trades/mod.rs b/stellar_rust_sdk/src/trades/mod.rs index 551ead4..ac9ef7e 100644 --- a/stellar_rust_sdk/src/trades/mod.rs +++ b/stellar_rust_sdk/src/trades/mod.rs @@ -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 diff --git a/stellar_rust_sdk/src/trades/trades_for_account_request.rs b/stellar_rust_sdk/src/trades/trades_for_account_request.rs index 848d177..51c8a2e 100644 --- a/stellar_rust_sdk/src/trades/trades_for_account_request.rs +++ b/stellar_rust_sdk/src/trades/trades_for_account_request.rs @@ -32,8 +32,9 @@ impl TradesForAccountRequest { /// pub fn set_account_id( self, - account_id: String, + account_id: impl Into ) -> Result, String> { + let account_id = account_id.into(); if let Err(e) = is_public_key(&account_id) { return Err(e.to_string()); } diff --git a/stellar_rust_sdk/src/transactions/mod.rs b/stellar_rust_sdk/src/transactions/mod.rs index e22499b..05040ff 100644 --- a/stellar_rust_sdk/src/transactions/mod.rs +++ b/stellar_rust_sdk/src/transactions/mod.rs @@ -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(); 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 6ca9339..9e72445 100644 --- a/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs +++ b/stellar_rust_sdk/src/transactions/transactions_for_account_request.rs @@ -34,10 +34,10 @@ impl TransactionsForAccountRequest { /// pub fn set_account_id( self, - account_id: String, + account_id: impl Into ) -> Result, 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,