Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardTibben committed Oct 4, 2023
1 parent 5aa447b commit a936590
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/stellar-rust-sdk.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 2 additions & 35 deletions src/accounts/accounts_request.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
use crate::models::*;

/// The asset type
/// Native - The native asset
/// Issued - An issued asset
/// [AccountsRequest](struct.AccountsRequest.html)
pub enum AssetType {
Native,
Issued,
}

impl std::fmt::Display for AssetType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
AssetType::Native => write!(f, "native"),
AssetType::Issued => write!(f, "issued"),
}
}
}

/// The order of the records
/// Asc - Ascending order
/// Desc - Descending order
/// [AccountsRequest](struct.AccountsRequest.html)
pub enum Order {
Asc,
Desc,
}

impl std::fmt::Display for Order {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Order::Asc => write!(f, "asc"),
Order::Desc => write!(f, "desc"),
}
}
}
use super::super::Order;
use super::super::AssetType;

/// AccountsRequest is the request object for the /accounts endpoint
/// [More Details](https://www.stellar.org/developers/horizon/reference/endpoints/accounts.html "Accounts")
Expand Down
50 changes: 50 additions & 0 deletions src/assets/all_assets_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ use super::super::Order;
// AllAssetsRequest is the request for the /assets endpoint
// [More Details] https://www.stellar.org/developers/horizon/reference/endpoints/assets-all.html "Assets"
pub struct AllAssetsRequest {

/// The assets identifying code. For example, if the asset is a credit issued on the Stellar network,
/// the code will be the asset’s code. If the asset is a native asset, the code will be XLM.
asset_code: Option<String>,
/// The account ID of the asset’s issuer. For example, if the asset is a credit issued on the Stellar
/// network, the issuer will be the account ID of the credit’s issuer.
asset_issuer: Option<String>,
/// The paging token of the next page of results. If this value is not provided, the results will
/// begin at the first page.
cursor: Option<u32>,
/// The maximum number of records returned. The limit can range from 1 to 200 - an upper limit that
/// is hardcoded in Horizon for performance reasons. If this argument isn’t designated, it defaults
/// to 10.
limit: Option<u32>,
/// A designation of the order in which records should appear. Options include asc (ascending) or
/// desc (descending). If this argument isn’t set, it defaults to asc.
order: Option<Order>,
}

impl Request for AllAssetsRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
fn new() -> Self {
AllAssetsRequest {
asset_code: None,
Expand All @@ -23,10 +39,12 @@ impl Request for AllAssetsRequest {
}
}

/// Gets the relative URL for the request
fn get_path(&self) -> &str {
"/assets"
}

/// Gets the query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(asset_code) = &self.asset_code {
Expand All @@ -48,6 +66,7 @@ impl Request for AllAssetsRequest {
query.trim_end_matches('&').to_string()
}

/// Validates the request
fn validate(&self) -> Result<(), String> {
if let Some(asset_code) = &self.asset_code {
// TODO: implement full asset code regex
Expand Down Expand Up @@ -78,6 +97,7 @@ impl Request for AllAssetsRequest {
Ok(())
}

/// Builds the URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}?{}",
Expand All @@ -89,22 +109,52 @@ impl Request for AllAssetsRequest {
}

impl AllAssetsRequest {
/// Sets the asset code
/// # Arguments
/// * `asset_code` - The asset code
/// # Returns
/// The request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
pub fn set_asset_code(&mut self, asset_code: String) {

Check warning on line 118 in src/assets/all_assets_request.rs

View workflow job for this annotation

GitHub Actions / Build and test Stellar SDK

methods `set_asset_code`, `set_asset_issuer`, `set_cursor`, `set_limit`, and `set_order` are never used

Check warning on line 118 in src/assets/all_assets_request.rs

View workflow job for this annotation

GitHub Actions / Build and test Stellar SDK

methods `set_asset_code`, `set_cursor`, `set_limit`, and `set_order` are never used
self.asset_code = Some(asset_code);
}

/// Sets the asset issuer
/// # Arguments
/// * `asset_issuer` - The asset issuer
/// # Returns
/// The request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
pub fn set_asset_issuer(&mut self, asset_issuer: String) {
self.asset_issuer = Some(asset_issuer);
}

/// Sets the cursor
/// # Arguments
/// * `cursor` - The cursor
/// # Returns
/// The request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
pub fn set_cursor(&mut self, cursor: u32) {
self.cursor = Some(cursor);
}

/// Sets the limit
/// # Arguments
/// * `limit` - The limit
/// # Returns
/// The request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
pub fn set_limit(&mut self, limit: u32) {
self.limit = Some(limit);
}

/// Sets the order
/// # Arguments
/// * `order` - The order
/// # Returns
/// The request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
pub fn set_order(&mut self, order: Order) {
self.order = Some(order);
}
Expand Down
9 changes: 9 additions & 0 deletions src/horizon_client/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ impl HorizonClient {
self.get::<SingleAccountsResponse>(request).await
}

/// Gets the base URL for the Horizon server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The all assets request
/// # Returns
/// The all assets response
/// # Errors
/// Returns an error if the request fails
/// [GET /assets](https://www.stellar.org/developers/horizon/reference/endpoints/assets-all.html)
pub async fn get_all_assets(
&self,
request: &AllAssetsRequest,
Expand Down

0 comments on commit a936590

Please sign in to comment.