shuttle-sdk 0.1.0

Stellar Horizon Server client.
Documentation
use std::collections::HashMap;
use shuttle_core::{Amount, PublicKey};
use error::Result;
use client::{self, InnerClient};
use link::Link;
use deserialize;

/// Entry point for accounts requests.
#[derive(Debug, Clone)]
pub struct AccountsRequest {
    inner: InnerClient,
}

impl AccountsRequest {
    /// Create a new `AccountsRequest`.
    pub fn new(inner: InnerClient) -> AccountsRequest {
        AccountsRequest { inner }
    }

    /// Return a request for a specific account.
    pub fn account_id(self, account_id: &PublicKey) -> Result<AccountIdRequest> {
        AccountIdRequest::new(self.inner, &account_id)
    }
}

/// Account details request.
#[derive(Debug, Clone)]
pub struct AccountIdRequest {
    inner: InnerClient,
    account_id: String,
}

impl AccountIdRequest {
    /// Create a new `AccountIdRequest`.
    pub fn new(inner: InnerClient, key: &PublicKey) -> Result<AccountIdRequest> {
        let account_id = key.account_id()?;
        Ok(AccountIdRequest { inner, account_id })
    }

    /// Send the request to the server.
    pub fn send(&self) -> Result<AccountIdResponse> {
        client::parse_response(&mut self.inner.get(&["accounts", &self.account_id])?.send()?)
    }
}

/// Response to an `AccountIdRequest`.
#[derive(Debug, Clone, Deserialize)]
pub struct AccountIdResponse {
    #[serde(rename = "_links")] links: AccountIdLinks,
    id: String,
    paging_token: String,
    account_id: String,
    /// Sequence number
    #[serde(deserialize_with = "deserialize::from_str")]
    pub sequence: u64,
    subentry_count: u64,
    thresholds: Thresholds,
    flags: Flags,
    balances: Vec<Balance>,
    signers: Vec<Signer>,
    data: HashMap<String, String>,
}

/// Links of an `AccountIdRequest`.
#[derive(Debug, Clone, Deserialize)]
pub struct AccountIdLinks {
    #[serde(rename = "self")] self_: Link,
    pub transactions: Link,
    pub operations: Link,
    pub payments: Link,
    pub effects: Link,
    pub offers: Link,
}

// Account thresholds.
#[derive(Debug, Clone, Deserialize)]
pub struct Thresholds {
    low_threshold: u64,
    med_threshold: u64,
    high_threshold: u64,
}

/// Account flags.
#[derive(Debug, Clone, Deserialize)]
pub struct Flags {
    auth_required: bool,
    auth_revocable: bool,
}

/// Account balance.
#[derive(Debug, Clone, Deserialize)]
pub struct Balance {
    #[serde(deserialize_with = "deserialize::from_str")] balance: Amount,
    limit: Option<String>,
    asset_type: String,
    asset_code: Option<String>,
    asset_issuer: Option<String>,
}

/// Account signer.
#[derive(Debug, Clone, Deserialize)]
pub struct Signer {
    #[serde(deserialize_with = "deserialize::account_id")] public_key: PublicKey,
    weight: u64,
}