Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #30 from ArkEcosystem/develop
Browse files Browse the repository at this point in the history
merge develop into master
  • Loading branch information
faustbrian authored Dec 24, 2018
2 parents 2d40cff + 2c2e616 commit 059e325
Show file tree
Hide file tree
Showing 94 changed files with 1,536 additions and 2,510 deletions.
38 changes: 36 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ jobs:
rustup install nightly
rustup run nightly rustc --version --verbose
rustup run nightly cargo --version --verbose
# Currently only nightly supports this tool
RUSTFLAGS="--cfg procmacro2_semver_exempt" rustup run nightly cargo install cargo-tarpaulin
rustup run nightly cargo tarpaulin --out Xml
- run:
name: Clippy
command: |
rustup component add --toolchain nightly clippy
rustup run nightly cargo clippy --all-targets --all-features -- -D warnings
- run:
name: rustfmt
command: |
rustup component add --toolchain nightly rustfmt
rustup run nightly cargo fmt -- --check
- run:
name: Codecov
when: on_success
Expand All @@ -30,6 +41,16 @@ jobs:
rustup install beta
rustup run beta cargo build
rustup run beta cargo test
- run:
name: Clippy
command: |
rustup component add --toolchain beta clippy
rustup run beta cargo clippy --all-targets --all-features -- -D warnings
- run:
name: rustfmt
command: |
rustup component add --toolchain beta rustfmt
rustup run beta cargo fmt -- --check
build-stable:
docker:
- image: circleci/rust:latest
Expand All @@ -41,11 +62,24 @@ jobs:
cargo clean
cargo build
cargo test
- run:
name: Clippy
command: |
rustup update
rustup install stable
# Clippy is no longer available via crates.io
rustup component add --toolchain stable clippy
rustup run stable cargo clippy --all-targets --all-features -- -D warnings
- run:
name: rustfmt
command: |
rustup component add --toolchain stable rustfmt
rustup run stable cargo fmt -- --check
workflows:
version: 2
build_and_test:
jobs:
- build-nightly
# - build-nightly
- build-beta
- build-stable
- build-stable
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## 0.1.0 - 2018-09-03
## 1.0.0 - 2018-12-19
- Initial Release
12 changes: 6 additions & 6 deletions Cargo.toml
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"

Expand All @@ -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"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ If you discover a security vulnerability within this package, please send an e-m
## Credits

- [Joshua Noack](https://github.com/supaiku0)
- [Juan A. Martín](https://github.com/j-a-m-l)
- [All Contributors](../../contributors)

## License
Expand Down
20 changes: 0 additions & 20 deletions src/api/api.rs

This file was deleted.

60 changes: 60 additions & 0 deletions src/api/blocks.rs
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)
}
}
120 changes: 120 additions & 0 deletions src/api/delegates.rs
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)
}
}
64 changes: 58 additions & 6 deletions src/api/mod.rs
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,
}
}
}
Loading

0 comments on commit 059e325

Please sign in to comment.