This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ArkEcosystem/develop
merge develop into master
- Loading branch information
Showing
94 changed files
with
1,536 additions
and
2,510 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
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,7 +1,7 @@ | ||
[package] | ||
name = "arkecosystem-client" | ||
version = "0.1.0" | ||
authors = ["Joshua Noack <[email protected]>"] | ||
version = "1.0.0" | ||
authors = ["Joshua Noack <[email protected]>, Juan A. Martín <[email protected]>"] | ||
description = "A simple Rust API client for the ARK Blockchain." | ||
license = "MIT" | ||
|
||
|
@@ -11,11 +11,11 @@ path = "src/lib.rs" | |
doctest = false | ||
|
||
[dependencies] | ||
failure = "0.1.3" | ||
reqwest = "0.9.5" | ||
serde = "1.0.80" | ||
serde_derive = "1.0.80" | ||
serde = "1.0.82" | ||
serde_derive = "1.0.82" | ||
serde_json = "1.0.32" | ||
|
||
[dev-dependencies] | ||
mockito = "0.13.0" | ||
mockito = "0.14.0" | ||
assert_float_eq = "1.1.3" |
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 was deleted.
Oops, something went wrong.
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,60 @@ | ||
use http::client::Client; | ||
use std::borrow::Borrow; | ||
|
||
use api::models::{Block, Transaction}; | ||
use api::Result; | ||
|
||
pub struct Blocks { | ||
client: Client, | ||
} | ||
|
||
impl Blocks { | ||
pub fn new(client: Client) -> Blocks { | ||
Blocks { client } | ||
} | ||
|
||
pub fn all(&self) -> Result<Vec<Block>> { | ||
self.all_params(Vec::<(String, String)>::new()) | ||
} | ||
|
||
pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Block>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
self.client.get_with_params("blocks", parameters) | ||
} | ||
|
||
pub fn show(&self, id: &str) -> Result<Block> { | ||
let endpoint = format!("blocks/{}", id); | ||
|
||
self.client.get(&endpoint) | ||
} | ||
|
||
pub fn transactions(&self, id: &str) -> Result<Vec<Transaction>> { | ||
self.transactions_params(id, Vec::<(String, String)>::new()) | ||
} | ||
|
||
pub fn transactions_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Transaction>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
let endpoint = format!("blocks/{}/transactions", id); | ||
self.client.get_with_params(&endpoint, parameters) | ||
} | ||
|
||
pub fn search<I, K, V>(&self, parameters: I) -> Result<Vec<Block>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
self.client.get_with_params("blocks/search", parameters) | ||
} | ||
} |
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,120 @@ | ||
use http::client::Client; | ||
use std::borrow::Borrow; | ||
use std::collections::HashMap; | ||
|
||
use api::models::{Balances, Block, Delegate, Wallet}; | ||
use api::Result; | ||
|
||
pub struct Delegates { | ||
client: Client, | ||
} | ||
|
||
impl Delegates { | ||
pub fn new(client: Client) -> Delegates { | ||
Delegates { client } | ||
} | ||
|
||
pub fn all(&self) -> Result<Vec<Delegate>> { | ||
self.all_params(Vec::<(String, String)>::new()) | ||
} | ||
|
||
pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Delegate>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
self.client.get_with_params("delegates", parameters) | ||
} | ||
|
||
pub fn show(&self, id: &str) -> Result<Delegate> { | ||
let endpoint = format!("delegates/{}", id); | ||
self.client.get(&endpoint) | ||
} | ||
|
||
pub fn blocks(&self, id: &str) -> Result<Vec<Block>> { | ||
self.blocks_params(id, Vec::<(String, String)>::new()) | ||
} | ||
|
||
pub fn blocks_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Block>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
let endpoint = format!("delegates/{}/blocks", id); | ||
self.client.get_with_params(&endpoint, parameters) | ||
} | ||
|
||
pub fn voters(&self, id: &str) -> Result<Vec<Wallet>> { | ||
self.voters_params(id, Vec::<(String, String)>::new()) | ||
} | ||
|
||
pub fn voters_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Wallet>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
let endpoint = format!("delegates/{}/voters", id); | ||
self.client.get_with_params(&endpoint, parameters) | ||
} | ||
|
||
/// Returns the voters of a delegate and their balances | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// # extern crate serde_json; | ||
/// # extern crate arkecosystem_client; | ||
/// | ||
/// # use serde_json::to_string_pretty; | ||
/// # use arkecosystem_client::connection::Connection; | ||
/// | ||
/// # fn main() { | ||
/// # let client = Connection::new("http://167.114.43.38:4003/api/"); | ||
/// let delegate_id = "yo"; | ||
/// let voters_balances = client.delegates.voters_balances(&delegate_id).unwrap(); | ||
/// println!("{}", to_string_pretty(&voters_balances).unwrap()); | ||
/// # } | ||
/// ``` | ||
pub fn voters_balances(&self, id: &str) -> Result<Balances> { | ||
let endpoint = format!("delegates/{}/voters/balances", id); | ||
self.client.get(&endpoint) | ||
} | ||
|
||
/// Searches the delegates | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// # extern crate serde_json; | ||
/// # extern crate arkecosystem_client; | ||
/// | ||
/// # use serde_json::to_string_pretty; | ||
/// # use arkecosystem_client::connection::Connection; | ||
/// | ||
/// # fn main() { | ||
/// # let client = Connection::new("http://167.114.43.38:4003/api/"); | ||
/// let payload = [("username", "p")].iter(); | ||
/// let params = [("limit", "2")].iter(); | ||
/// let search = client.delegates.search(Some(payload), params).unwrap(); | ||
/// println!("{}", to_string_pretty(&search).unwrap()); | ||
/// # } | ||
/// ``` | ||
pub fn search<I, K, V>( | ||
&self, | ||
payload: Option<HashMap<&str, &str>>, | ||
parameters: I, | ||
) -> Result<Vec<Delegate>> | ||
where | ||
I: IntoIterator, | ||
I::Item: Borrow<(K, V)>, | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
self.client | ||
.post_with_params("delegates/search", payload, parameters) | ||
} | ||
} |
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,7 +1,59 @@ | ||
pub mod api; | ||
pub mod one; | ||
pub mod two; | ||
pub mod blocks; | ||
pub mod delegates; | ||
pub mod models; | ||
pub mod node; | ||
pub mod peers; | ||
pub mod transactions; | ||
pub mod votes; | ||
pub mod wallets; | ||
|
||
pub use self::api::{Api, Version}; | ||
pub use self::one::One; | ||
pub use self::two::Two; | ||
use self::blocks::Blocks; | ||
use self::delegates::Delegates; | ||
use self::models::Response; | ||
use self::node::Node; | ||
use self::peers::Peers; | ||
use self::transactions::Transactions; | ||
use self::votes::Votes; | ||
use self::wallets::Wallets; | ||
|
||
use super::error::Error; | ||
use http::client::Client; | ||
|
||
pub type Result<T> = std::result::Result<Response<T>, Error>; | ||
|
||
pub struct Api { | ||
pub blocks: Blocks, | ||
pub delegates: Delegates, | ||
pub node: Node, | ||
pub peers: Peers, | ||
pub transactions: Transactions, | ||
pub votes: Votes, | ||
pub wallets: Wallets, | ||
pub client: Client, | ||
} | ||
|
||
impl Api { | ||
fn version() -> &'static str { | ||
"2" | ||
} | ||
|
||
pub fn new(host: &str) -> Api { | ||
Api::new_with_client(&Client::new(host)) | ||
} | ||
|
||
pub fn new_with_client(client: &Client) -> Api { | ||
let mut client = client.clone(); | ||
client.set_version(&Api::version()); | ||
|
||
Api { | ||
blocks: Blocks::new(client.clone()), | ||
delegates: Delegates::new(client.clone()), | ||
node: Node::new(client.clone()), | ||
peers: Peers::new(client.clone()), | ||
transactions: Transactions::new(client.clone()), | ||
votes: Votes::new(client.clone()), | ||
wallets: Wallets::new(client.clone()), | ||
client, | ||
} | ||
} | ||
} |
Oops, something went wrong.