Skip to content

Commit

Permalink
More into string signature changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Luijken committed Sep 10, 2024
1 parent 3775dd0 commit 4512050
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 81 deletions.
11 changes: 5 additions & 6 deletions stellar_rust_sdk/src/accounts/accounts_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ macro_rules! valid_generic_account_request_impl {
/// # use stellar_rs::models::Request;
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();
/// let request = AccountsRequest::new()
/// .set_sponsor_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .set_sponsor_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
/// .unwrap();
/// // Now, you can pass `request` to `horizon_client.get_account_list`.
/// ```
Expand Down Expand Up @@ -345,11 +345,12 @@ impl AccountsRequest<NoSponsorFilter, NoSignerFilter, NoAssetFilter, NoLiquidity
///
pub fn set_sponsor_filter(
self,
sponsor: String,
sponsor: impl Into<String>
) -> Result<
AccountsRequest<SponsorFilter, NoSignerFilter, NoAssetFilter, NoLiquidityPoolFilter>,
String,
> {
let sponsor = sponsor.into();
if let Err(e) = is_public_key(&sponsor) {
return Err(e.to_string());
}
Expand Down Expand Up @@ -437,17 +438,15 @@ mod tests {

#[test]
fn test_accounts_request_set_sponsor_filter() {
let request = AccountsRequest::new().set_sponsor_filter("sponsor".to_string());
let request = AccountsRequest::new().set_sponsor_filter("sponsor");

assert!(request.is_err());
}

#[test]
fn test_accounts_set_sponsor_valid() {
let request = AccountsRequest::new()
.set_sponsor_filter(
"GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string(),
)
.set_sponsor_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
.unwrap();
assert_eq!(
request.sponsor.0,
Expand Down
5 changes: 5 additions & 0 deletions stellar_rust_sdk/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ pub mod test {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

// construct request
AllAssetsRequest::new()
.set_asset_code(ASSET_CODE)
.unwrap()
.set_asset_issuer(ASSET_ISSUER)
.unwrap();
let all_assets_request: AllAssetsRequest = AllAssetsRequest::new().set_limit(1).unwrap();

let response = horizon_client.get_all_assets(&all_assets_request).await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use stellar_rust_sdk_derive::pagination;
/// # use stellar_rs::models::{Asset, Order, IssuedAsset};
///
/// let request = AllClaimableBalancesRequest::new()
/// .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()).unwrap() // Optional sponsor filter
/// .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap() // Optional sponsor filter
/// .set_asset(Asset::new().set_issued("USD", "GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap()) // Optional asset filter
/// .set_claimant("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string()).unwrap() // Optional claimant filter
/// .set_claimant("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap() // Optional claimant filter
/// .set_cursor(123).unwrap() // Optional cursor for pagination
/// .set_limit(100).unwrap() // Optional limit for response records
/// .set_order(Order::Desc); // Optional order of records
Expand Down Expand Up @@ -81,7 +81,8 @@ impl AllClaimableBalancesRequest {
/// # Arguments
/// * `sponsor` - A Stellar public key of the sponsor whose claimable balances are to be retrieved.
///
pub fn set_sponsor(self, sponsor: String) -> Result<AllClaimableBalancesRequest, String> {
pub fn set_sponsor(self, sponsor: impl Into<String>) -> Result<AllClaimableBalancesRequest, String> {
let sponsor = sponsor.into();
if let Err(e) = is_public_key(&sponsor) {
return Err(e.to_string());
}
Expand Down Expand Up @@ -109,7 +110,8 @@ impl AllClaimableBalancesRequest {
/// # Arguments
/// * `claimant` - A Stellar public key of the claimant whose claimable balances are to be retrieved.
///
pub fn set_claimant(self, claimant: String) -> Result<AllClaimableBalancesRequest, String> {
pub fn set_claimant(self, claimant: impl Into<String>) -> Result<AllClaimableBalancesRequest, String> {
let claimant = claimant.into();
if let Err(e) = is_public_key(&claimant) {
return Err(e.to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/claimable_balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

let single_claimable_balance_request = SingleClaimableBalanceRequest::new()
.set_claimable_balance_id(CLAIMABLE_BALANCE_ID.to_string());
.set_claimable_balance_id(CLAIMABLE_BALANCE_ID);

let single_claimable_balance_response = horizon_client
.get_single_claimable_balance(&single_claimable_balance_request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct NoClaimableBalanceId;
/// # async fn fetch_single_claimable_balance() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
/// let request = SingleClaimableBalanceRequest::new()
/// .set_claimable_balance_id("00000000".to_string()); // Example claimable balance ID
/// .set_claimable_balance_id("00000000"); // Example claimable balance ID
///
/// let response = horizon_client.get_single_claimable_balance(&request).await?;
/// // Process the response
Expand All @@ -59,10 +59,10 @@ impl SingleClaimableBalanceRequest<NoClaimableBalanceId> {
///
pub fn set_claimable_balance_id(
self,
claimable_balance_id: String,
claimable_balance_id: impl Into<String>,
) -> SingleClaimableBalanceRequest<ClaimableBalanceId> {
SingleClaimableBalanceRequest {
claimable_balance_id: ClaimableBalanceId(claimable_balance_id),
claimable_balance_id: ClaimableBalanceId(claimable_balance_id.into()),
}
}
}
Expand Down Expand Up @@ -91,13 +91,13 @@ mod tests {
#[test]
fn test_single_claimable_balance_request() {
let request =
SingleClaimableBalanceRequest::new().set_claimable_balance_id("00000000".to_string());
SingleClaimableBalanceRequest::new().set_claimable_balance_id("00000000");

assert_eq!(request.get_query_parameters(), "00000000".to_string());
assert_eq!(request.get_query_parameters(), "00000000");

assert_eq!(
request.build_url("https://horizon-testnet.stellar.org"),
"https://horizon-testnet.stellar.org/claimable_balances/00000000".to_string()
"https://horizon-testnet.stellar.org/claimable_balances/00000000"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use stellar_rust_sdk_derive::pagination;
/// # use stellar_rs::models::*;
///
/// let request = EffectsForLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("01c58ab8fb283c8b083a26bf2fe06b7b6c6304c13f9d29d956cdf15a48bea72d".to_string())
/// .set_liquidity_pool_id("01c58ab8fb283c8b083a26bf2fe06b7b6c6304c13f9d29d956cdf15a48bea72d")
/// .set_cursor(1234).unwrap()
/// .set_limit(20).unwrap()
/// .set_order(Order::Desc);
Expand Down Expand Up @@ -53,10 +53,10 @@ impl EffectsForLiquidityPoolRequest {
///
pub fn set_liquidity_pool_id(
self,
liquidity_pool_id: String,
liquidity_pool_id: impl Into<String>,
) -> EffectsForLiquidityPoolRequest {
EffectsForLiquidityPoolRequest {
liquidity_pool_id: Some(liquidity_pool_id),
liquidity_pool_id: Some(liquidity_pool_id.into()),
..self
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ mod tests {
#[test]
fn test_effects_for_liquidity_pools_request() {
let request = EffectsForLiquidityPoolRequest::new()
.set_liquidity_pool_id("liquidity_pool_id".to_string())
.set_liquidity_pool_id("liquidity_pool_id")
.set_cursor(1)
.unwrap()
.set_limit(10)
Expand Down
4 changes: 2 additions & 2 deletions stellar_rust_sdk/src/effects/effects_for_operation_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl EffectsForOperationRequest {
EffectsForOperationRequest::default()
}

pub fn set_operation_id(self, operation_id: &str) -> EffectsForOperationRequest {
pub fn set_operation_id(self, operation_id: impl Into<String>) -> EffectsForOperationRequest {
EffectsForOperationRequest {
operation_id: Some(operation_id.to_string()),
operation_id: Some(operation_id.into()),
..self
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use stellar_rust_sdk_derive::pagination;
/// # use stellar_rs::models::*;
///
/// let request = EffectForTransactionRequest::new()
/// .set_transaction_hash("transaction_hash".to_string())
/// .set_transaction_hash("transaction_hash")
/// .set_cursor(1234).unwrap()
/// .set_limit(20).unwrap()
/// .set_order(Order::Desc);
Expand All @@ -46,9 +46,9 @@ impl EffectForTransactionRequest {
/// # Arguments
/// * `liquidity_pool_id` - A `String` value representing the liquidity pool id.
///
pub fn set_transaction_hash(self, transaction_hash: String) -> EffectForTransactionRequest {
pub fn set_transaction_hash(self, transaction_hash: impl Into<String>) -> EffectForTransactionRequest {
EffectForTransactionRequest {
transaction_hash: Some(transaction_hash),
transaction_hash: Some(transaction_hash.into()),
..self
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ mod tests {
#[test]
fn test_effects_for_liquidity_pools_request() {
let request = EffectForTransactionRequest::new()
.set_transaction_hash("transaction_hash".to_string())
.set_transaction_hash("transaction_hash")
.set_cursor(1)
.unwrap()
.set_limit(10)
Expand Down
4 changes: 2 additions & 2 deletions stellar_rust_sdk/src/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ mod tests {
let _effects_for_liquidity_pools_request_with_id = EffectsForLiquidityPoolRequest::new()
.set_limit(2)
.expect("REASON")
.set_liquidity_pool_id("0000000459561504769-0000000001".to_string());
.set_liquidity_pool_id("0000000459561504769-0000000001");
let effects_for_liquidity_pools_response = horizon_client
.get_effects_for_liquidity_pools(&effects_for_liquidity_pools_request)
.await;
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org").unwrap();

let effects_for_transaction_request = EffectForTransactionRequest::new()
.set_transaction_hash(TRANSACTION_HASH.to_string())
.set_transaction_hash(TRANSACTION_HASH)
.set_limit(2)
.unwrap();

Expand Down
26 changes: 13 additions & 13 deletions stellar_rust_sdk/src/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = AllClaimableBalancesRequest::new()
/// .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
/// .unwrap();
///
/// let response = horizon_client.get_all_claimable_balances(&request).await;
Expand Down Expand Up @@ -425,7 +425,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = SingleClaimableBalanceRequest::new()
/// .set_claimable_balance_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string());
/// .set_claimable_balance_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca");
///
/// let response = horizon_client.get_single_claimable_balance(&request).await;
///
Expand Down Expand Up @@ -627,7 +627,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = EffectForTransactionRequest::new()
/// .set_transaction_hash("transaction_hash".to_string());
/// .set_transaction_hash("transaction_hash");
///
/// let response = horizon_client.get_effects_for_transaction(&request).await;
///
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = SingleOperationRequest::new()
/// .set_operation_id("459561504769".to_string());
/// .set_operation_id("459561504769");
///
/// let response = horizon_client.get_single_operation(&request).await;
///
Expand Down Expand Up @@ -1261,7 +1261,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = OperationsForLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string());
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca");
///
/// let response = horizon_client.get_operations_for_liquidity_pool(&request).await;
///
Expand Down Expand Up @@ -1312,7 +1312,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = OperationsForTransactionRequest::new()
/// .set_transaction_hash("b9d0b2292c4e09e8eb22d036171491e87b8d2086bf8b265874c8d182cb9c9020".to_string());
/// .set_transaction_hash("b9d0b2292c4e09e8eb22d036171491e87b8d2086bf8b265874c8d182cb9c9020");
///
/// let response = horizon_client.get_operations_for_transaction(&request).await;
///
Expand Down Expand Up @@ -1557,7 +1557,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = TradesForLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("0b3c88caa5aeada296646c1810893e3b04cba0426cff8ff6a63cf6f35cc7f5b3".to_string())
/// .set_liquidity_pool_id("0b3c88caa5aeada296646c1810893e3b04cba0426cff8ff6a63cf6f35cc7f5b3")
/// .unwrap();
///
/// let response = horizon_client.get_trades_for_liquidity_pool(&request).await;
Expand Down Expand Up @@ -1707,7 +1707,7 @@ impl HorizonClient {
/// # let base_url = "https://horizon-testnet.stellar.org";
/// # let horizon_client = HorizonClient::new(base_url)?;
/// let request = SingleLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string()).unwrap();
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca").unwrap();
///
/// let response = horizon_client.get_single_liquidity_pool(&request).await;
///
Expand Down Expand Up @@ -1762,7 +1762,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = SingleTransactionRequest::new()
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f".to_string()) // example transaction hash
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f") // example transaction hash
/// .unwrap();
///
/// let response = horizon_client.get_single_transaction(&request).await;
Expand Down Expand Up @@ -1913,7 +1913,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = TransactionsForLedgerRequest::new()
/// .set_ledger_sequence("539".to_string()).unwrap()
/// .set_ledger_sequence("539").unwrap()
/// .set_include_failed(true).unwrap();
///
/// let response = horizon_client.get_transactions_for_ledger(&request).await;
Expand Down Expand Up @@ -1964,7 +1964,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = TransactionsForLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("0066b15f5d0dc0be771209c33f3e4126383e58183a598eae8b3813024c6a6d10".to_string()).unwrap()
/// .set_liquidity_pool_id("0066b15f5d0dc0be771209c33f3e4126383e58183a598eae8b3813024c6a6d10").unwrap()
/// .set_include_failed(true).unwrap();
///
/// let response = horizon_client.get_transactions_for_liquidity_pool(&request).await;
Expand Down Expand Up @@ -2189,7 +2189,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = PaymentsForLedgerRequest::new()
/// .set_ledger_sequence("48483".to_string());
/// .set_ledger_sequence("48483");
///
/// let response = horizon_client.get_payments_for_ledger(&request).await;
///
Expand Down Expand Up @@ -2240,7 +2240,7 @@ impl HorizonClient {
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request = PaymentsForTransactionRequest::new()
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f".to_string());
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f");
///
/// let response = horizon_client.get_payments_for_transaction(&request).await;
///
Expand Down
4 changes: 2 additions & 2 deletions stellar_rust_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub mod fee_stats;
///
/// // Example: Fetching fee stats
/// let single_lp_request = SingleLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string())
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca")
/// .unwrap();
/// let lp_response = horizon_client.get_single_liquidity_pool(&single_lp_request).await?;
///
Expand Down Expand Up @@ -571,7 +571,7 @@ pub mod trade_aggregations;
///
/// // Example: Fetching a transaction
/// let single_transaction_request = SingleTransactionRequest::new()
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f".to_string())
/// .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f")
/// .unwrap();
/// let single_transaction_response = horizon_client.get_single_transaction(&single_transaction_request).await?;
///
Expand Down
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/liquidity_pools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ async fn test_get_single_liquidity_pool() {

let single_liquidity_pool_request = SingleLiquidityPoolRequest::new()
.set_liquidity_pool_id(
"03eac63a834b31201652ed575c816b4e7beb0c4eece47caf956ff83648f486d0".to_string(),
"03eac63a834b31201652ed575c816b4e7beb0c4eece47caf956ff83648f486d0"
)
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct NoLiquidityPoolId;
/// # use stellar_rs::liquidity_pools::prelude::SingleLiquidityPoolRequest;
/// # use stellar_rs::models::Request;
/// let request = SingleLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string())
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca")
/// .unwrap();
/// // Use with HorizonClient::get_single_liquidity_pool
/// ```
Expand All @@ -53,10 +53,10 @@ impl SingleLiquidityPoolRequest<NoLiquidityPoolId> {
///
pub fn set_liquidity_pool_id(
self,
liquidity_pool_id: String,
liquidity_pool_id: impl Into<String>,
) -> Result<SingleLiquidityPoolRequest<LiquidityPoolId>, String> {
Ok(SingleLiquidityPoolRequest {
liquidity_pool_id: LiquidityPoolId(liquidity_pool_id),
liquidity_pool_id: LiquidityPoolId(liquidity_pool_id.into()),
})
}
}
Expand Down
Loading

0 comments on commit 4512050

Please sign in to comment.