Skip to content

Commit

Permalink
Merge pull request #2 from Baseflow/all_assets_endppoint
Browse files Browse the repository at this point in the history
All assets endppoint
  • Loading branch information
LeonardTibben authored Nov 9, 2023
2 parents 99c3b79 + 8409de6 commit 693c8c2
Show file tree
Hide file tree
Showing 19 changed files with 2,682 additions and 374 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ Cargo.lock
# Added by cargo

/target

keys.txt

# Ignore IntelliJ IDEA project files
.idea/

# Ignore Visual Studio Code project files
.vscode/
27 changes: 0 additions & 27 deletions .vscode/launch.json

This file was deleted.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ edition = "2021"
reqwest = { version = "0.11.4", features = ["json"] }
url = "2.2.2"
tokio = { version = "1.15.0", features = ["full"] }
xdr-codec = "0.4.4"
xdrgen = "0.4.4"

[build-dependencies]
stellar-xdr = { version = "20.0.0-rc1", features = ["base64"] }
serde_json = "1.0.107"
serde = { version = "1.0.188", features = ["derive"] }
derive-getters = "0.3.0"
hex = "0.4.3"
base64 = "0.21.4"
41 changes: 4 additions & 37 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 Expand Up @@ -168,8 +135,8 @@ impl AccountsRequest {
/// # Returns
/// The request object
/// [AccountsRequest](struct.AccountsRequest.html)
pub fn set_sponsor(&mut self, sponsor: &str) -> &mut Self {
self.sponsor = Some(sponsor.to_owned());
pub fn set_sponsor(&mut self, sponsor: impl Into<String>) -> &mut Self {
self.sponsor = Some(sponsor.into());
self
}

Expand Down
259 changes: 255 additions & 4 deletions src/accounts/accounts_response.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,258 @@
pub struct AccountsResponse {}
use serde::{Deserialize, Serialize};

impl Default for AccountsResponse {
fn default() -> Self {
Self {}
use crate::models::Response;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct SelfLink {
href: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Links {
#[serde(rename = "self")]
self_link: SelfLink,
next: Option<SelfLink>,
prev: Option<SelfLink>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Balances {
balance: String,
buying_liabilities: String,
selling_liabilities: String,
asset_type: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Thresholds {
low_threshold: i32,
med_threshold: i32,
high_threshold: i32,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Flags {
auth_required: bool,
auth_revocable: bool,
auth_immutable: bool,
auth_clawback_enabled: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Signers {
weight: i32,
key: String,
#[serde(rename = "type")]
signer_type: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Record {
#[serde(rename = "_links")]
links: Links,
id: String,
account_id: String,
sequence: String,
subentry_count: i32,
last_modified_ledger: i64,
last_modified_time: String,
thresholds: Thresholds,
flags: Flags,
balances: Vec<Balances>,
signers: Vec<Signers>,
data: serde_json::Value,
num_sponsoring: i32,
num_sponsored: i32,
paging_token: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Embedded {
records: Vec<Record>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AccountsResponse {
_links: Links,
_embedded: Embedded,
}

impl Response for AccountsResponse {
fn from_json(json: String) -> Result<Self, String> {
serde_json::from_str(&json).map_err(|e| e.to_string())
}
}

impl AccountsResponse {
pub fn get__links(&self) -> Links {
self._links.clone()
}

pub fn get__embedded(&self) -> Embedded {
self._embedded.clone()
}
}

impl Links {
pub fn get_self_link(&self) -> SelfLink {
self.self_link.clone()
}

pub fn get_next(&self) -> Option<SelfLink> {
self.next.clone()
}

pub fn get_prev(&self) -> Option<SelfLink> {
self.prev.clone()
}
}

impl Embedded {
pub fn get_records(&self) -> Vec<Record> {
self.records.clone()
}

pub fn get_single_record(&self, index: usize) -> Record {
self.records[index].clone()
}
}

impl SelfLink {
pub fn get_href(&self) -> String {
self.href.clone()
}
}

impl Record {
pub fn get__links(&self) -> Links {
self.links.clone()
}

pub fn get_id(&self) -> String {
self.id.clone()
}

pub fn get_account_id(&self) -> String {
self.account_id.clone()
}

pub fn get_sequence(&self) -> String {
self.sequence.clone()
}

pub fn get_subentry_count(&self) -> i32 {
self.subentry_count.clone()
}

pub fn get_last_modified_ledger(&self) -> i64 {
self.last_modified_ledger.clone()
}

pub fn get_last_modified_time(&self) -> String {
self.last_modified_time.clone()
}

pub fn get_thresholds(&self) -> Thresholds {
self.thresholds.clone()
}

pub fn get_flags(&self) -> Flags {
self.flags.clone()
}

pub fn get_balances(&self) -> Vec<Balances> {
self.balances.clone()
}

pub fn get_single_balance(&self, index: usize) -> Balances {
self.balances[index].clone()
}

pub fn get_signers(&self) -> Vec<Signers> {
self.signers.clone()
}

pub fn get_single_signer(&self, index: usize) -> Signers {
self.signers[index].clone()
}

pub fn get_data(&self) -> serde_json::Value {
self.data.clone()
}

pub fn get_num_sponsoring(&self) -> i32 {
self.num_sponsoring.clone()
}

pub fn get_num_sponsored(&self) -> i32 {
self.num_sponsored.clone()
}

pub fn get_paging_token(&self) -> String {
self.paging_token.clone()
}
}

impl Thresholds {
pub fn get_low_threshold(&self) -> i32 {
self.low_threshold.clone()
}

pub fn get_med_threshold(&self) -> i32 {
self.med_threshold.clone()
}

pub fn get_high_threshold(&self) -> i32 {
self.high_threshold.clone()
}
}

impl Balances {
pub fn get_balance(&self) -> String {
self.balance.clone()
}

pub fn get_buying_liabilities(&self) -> String {
self.buying_liabilities.clone()
}

pub fn get_selling_liabilities(&self) -> String {
self.selling_liabilities.clone()
}

pub fn get_asset_type(&self) -> String {
self.asset_type.clone()
}
}

impl Flags {
pub fn get_auth_required(&self) -> bool {
self.auth_required.clone()
}

pub fn get_auth_revocable(&self) -> bool {
self.auth_revocable.clone()
}

pub fn get_auth_immutable(&self) -> bool {
self.auth_immutable.clone()
}

pub fn get_auth_clawback_enabled(&self) -> bool {
self.auth_clawback_enabled.clone()
}
}

impl Signers {
pub fn get_weight(&self) -> i32 {
self.weight.clone()
}

pub fn get_key(&self) -> String {
self.key.clone()
}

pub fn get_type(&self) -> String {
self.signer_type.clone()
}
}
3 changes: 2 additions & 1 deletion src/accounts/single_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl Request for SingleAccountRequest {
}

impl SingleAccountRequest {
pub fn set_account_id(&mut self, account_id: String) {
pub fn set_account_id(&mut self, account_id: String) -> &mut Self{
self.account_id = Some(account_id);
self
}
}
Loading

0 comments on commit 693c8c2

Please sign in to comment.