-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a0fb3c
commit 5aa447b
Showing
8 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ Cargo.lock | |
# Added by cargo | ||
|
||
/target | ||
|
||
keys.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug unit tests in library 'stellar-rust-sdk'", | ||
"cargo": { | ||
"args": [ | ||
"test", | ||
"--no-run", | ||
"--lib", | ||
"--package=stellar-rust-sdk" | ||
], | ||
"filter": { | ||
"name": "stellar-rust-sdk", | ||
"kind": "lib" | ||
} | ||
}, | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
use crate::models::Request; | ||
|
||
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 { | ||
asset_code: Option<String>, | ||
asset_issuer: Option<String>, | ||
cursor: Option<u32>, | ||
limit: Option<u32>, | ||
order: Option<Order>, | ||
} | ||
|
||
impl Request for AllAssetsRequest { | ||
fn new() -> Self { | ||
AllAssetsRequest { | ||
asset_code: None, | ||
asset_issuer: None, | ||
cursor: None, | ||
limit: None, | ||
order: None, | ||
} | ||
} | ||
|
||
fn get_path(&self) -> &str { | ||
"/assets" | ||
} | ||
|
||
fn get_query_parameters(&self) -> String { | ||
let mut query = String::new(); | ||
if let Some(asset_code) = &self.asset_code { | ||
query.push_str(&format!("asset_code={}&", asset_code)); | ||
} | ||
if let Some(asset_issuer) = &self.asset_issuer { | ||
query.push_str(&format!("asset_issuer={}&", asset_issuer)); | ||
} | ||
if let Some(cursor) = &self.cursor { | ||
query.push_str(&format!("cursor={}&", cursor)); | ||
} | ||
if let Some(limit) = &self.limit { | ||
query.push_str(&format!("limit={}&", limit)); | ||
} | ||
if let Some(order) = &self.order { | ||
query.push_str(&format!("order={}&", order)); | ||
} | ||
|
||
query.trim_end_matches('&').to_string() | ||
} | ||
|
||
fn validate(&self) -> Result<(), String> { | ||
if let Some(asset_code) = &self.asset_code { | ||
// TODO: implement full asset code regex | ||
if asset_code.len() > 12 { | ||
return Err("asset_code must be 12 characters or less".to_string()); | ||
} | ||
} | ||
|
||
if let Some(asset_issuer) = &self.asset_issuer { | ||
// TODO: implement full asset issuer regex | ||
if asset_issuer.len() != 56 { | ||
return Err("asset_issuer must be 56 characters".to_string()); | ||
} | ||
} | ||
|
||
if let Some(limit) = &self.limit { | ||
if *limit < 1 || *limit > 200 { | ||
return Err("limit must be between 1 and 200".to_string()); | ||
} | ||
} | ||
|
||
if let Some(cursor) = &self.cursor { | ||
if *cursor < 1 { | ||
return Err("cursor must be greater than or equal to 1".to_string()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn build_url(&self, base_url: &str) -> String { | ||
format!( | ||
"{}{}?{}", | ||
base_url, | ||
self.get_path(), | ||
self.get_query_parameters() | ||
) | ||
} | ||
} | ||
|
||
impl AllAssetsRequest { | ||
pub fn set_asset_code(&mut self, asset_code: String) { | ||
self.asset_code = Some(asset_code); | ||
} | ||
|
||
pub fn set_asset_issuer(&mut self, asset_issuer: String) { | ||
self.asset_issuer = Some(asset_issuer); | ||
} | ||
|
||
pub fn set_cursor(&mut self, cursor: u32) { | ||
self.cursor = Some(cursor); | ||
} | ||
|
||
pub fn set_limit(&mut self, limit: u32) { | ||
self.limit = Some(limit); | ||
} | ||
|
||
pub fn set_order(&mut self, order: Order) { | ||
self.order = Some(order); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub struct AllAssetsResponse {} | ||
|
||
impl Default for AllAssetsResponse { | ||
fn default() -> Self { | ||
Self {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod all_assets_request; | ||
mod all_assets_response; | ||
|
||
pub mod prelude { | ||
pub use super::all_assets_request::*; | ||
pub use super::all_assets_response::*; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,41 @@ | ||
mod assets; | ||
mod accounts; | ||
mod horizon_client; | ||
mod models; | ||
mod xdr; | ||
|
||
/// 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"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters