diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..202f0f7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/stellar-rust-sdk.iml b/.idea/stellar-rust-sdk.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/.idea/stellar-rust-sdk.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/accounts/accounts_request.rs b/src/accounts/accounts_request.rs index 3e4e2ad..7af4e85 100644 --- a/src/accounts/accounts_request.rs +++ b/src/accounts/accounts_request.rs @@ -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") diff --git a/src/assets/all_assets_request.rs b/src/assets/all_assets_request.rs index 512972a..77cee5d 100644 --- a/src/assets/all_assets_request.rs +++ b/src/assets/all_assets_request.rs @@ -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, + /// 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, + /// 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, + /// 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, + /// 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, } 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, @@ -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 { @@ -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 @@ -78,6 +97,7 @@ impl Request for AllAssetsRequest { Ok(()) } + /// Builds the URL for the request fn build_url(&self, base_url: &str) -> String { format!( "{}{}?{}", @@ -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) { 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); } diff --git a/src/horizon_client/horizon_client.rs b/src/horizon_client/horizon_client.rs index 947e1d0..954134f 100644 --- a/src/horizon_client/horizon_client.rs +++ b/src/horizon_client/horizon_client.rs @@ -52,6 +52,15 @@ impl HorizonClient { self.get::(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,