From 361d36f7d69fba569da962ff621a4f3e1f0be8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 17 May 2016 16:55:08 +0200 Subject: [PATCH 1/3] Webapps details --- Cargo.lock | 35 ++++++++++++++++------------- webapp/Cargo.toml | 20 ++++++++++++----- webapp/build.rs | 45 +++++++++++++++++++++++++++++++++++++ webapp/src/{ => api}/api.rs | 38 +++++++++++++++++++++---------- webapp/src/api/mod.rs | 28 +++++++++++++++++++++++ webapp/src/api/mod.rs.in | 20 +++++++++++++++++ webapp/src/api/response.rs | 23 +++++++++++++++++++ webapp/src/endpoint.rs | 11 +++++++++ webapp/src/lib.rs | 2 ++ webapp/src/page/mod.rs | 22 ++++++++++++++++-- 10 files changed, 210 insertions(+), 34 deletions(-) create mode 100644 webapp/build.rs rename webapp/src/{ => api}/api.rs (59%) create mode 100644 webapp/src/api/mod.rs create mode 100644 webapp/src/api/mod.rs.in create mode 100644 webapp/src/api/response.rs diff --git a/Cargo.lock b/Cargo.lock index b0c9e5eb3..d463dafe6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,10 +356,15 @@ dependencies = [ "jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-idmanager 0.1.3 (git+https://github.com/ethcore/parity-idmanager-rs.git)", - "parity-status 0.4.1 (git+https://github.com/ethcore/parity-status.git)", - "parity-wallet 0.3.0 (git+https://github.com/ethcore/parity-wallet.git)", - "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", + "parity-idmanager 0.2.0 (git+https://github.com/ethcore/parity-idmanager-rs.git)", + "parity-status 0.4.0 (git+https://github.com/ethcore/parity-status.git)", + "parity-wallet 0.4.0 (git+https://github.com/ethcore/parity-wallet.git)", + "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_codegen 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -831,32 +836,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-idmanager" -version = "0.1.3" -source = "git+https://github.com/ethcore/parity-idmanager-rs.git#efb69592b87854f41d8882de75982c8f1e748666" +version = "0.2.0" +source = "git+https://github.com/ethcore/parity-idmanager-rs.git#be59a97cdd15dd733583938973ef65ff3beab463" dependencies = [ - "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", + "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ] [[package]] name = "parity-status" -version = "0.4.1" -source = "git+https://github.com/ethcore/parity-status.git#f121ebd1f49986545d9fc262ba210cdf07039e6d" +version = "0.4.0" +source = "git+https://github.com/ethcore/parity-status.git#0ab708f869366543a8de953300e49098be0b7dbd" dependencies = [ - "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", + "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ] [[package]] name = "parity-wallet" -version = "0.3.0" -source = "git+https://github.com/ethcore/parity-wallet.git#664fd2b85dd94ca184868bd3965e14a4ba68c03f" +version = "0.4.0" +source = "git+https://github.com/ethcore/parity-wallet.git#5391a89dc5dbf162d1beeba555f03c24bfd619bd" dependencies = [ - "parity-webapp 0.1.0 (git+https://github.com/ethcore/parity-webapp.git)", + "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ] [[package]] name = "parity-webapp" -version = "0.1.0" -source = "git+https://github.com/ethcore/parity-webapp.git#0bf133f193863ba0e88b0b824a5c330037cce3f1" +version = "0.2.0" +source = "git+https://github.com/ethcore/parity-webapp.git#f31681af69631bcadfbef89a7e60dcc49552f7c6" [[package]] name = "primal" diff --git a/webapp/Cargo.toml b/webapp/Cargo.toml index fe6fb9bf6..1d71a9126 100644 --- a/webapp/Cargo.toml +++ b/webapp/Cargo.toml @@ -4,6 +4,7 @@ name = "ethcore-webapp" version = "1.2.0" license = "GPL-3.0" authors = ["Ethcore . + +#[cfg(not(feature = "serde_macros"))] +mod inner { + extern crate syntex; + extern crate serde_codegen; + + use std::env; + use std::path::Path; + + pub fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + let src = Path::new("./src/api/mod.rs.in"); + let dst = Path::new(&out_dir).join("mod.rs"); + + let mut registry = syntex::Registry::new(); + + serde_codegen::register(&mut registry); + registry.expand("", &src, &dst).unwrap(); + } +} + +#[cfg(feature = "serde_macros")] +mod inner { + pub fn main() {} +} + +fn main() { + inner::main(); +} diff --git a/webapp/src/api.rs b/webapp/src/api/api.rs similarity index 59% rename from webapp/src/api.rs rename to webapp/src/api/api.rs index 75cdb4c58..fdfef1394 100644 --- a/webapp/src/api.rs +++ b/webapp/src/api/api.rs @@ -14,15 +14,26 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -//! Simple REST API - use std::sync::Arc; -use endpoint::{Endpoint, Endpoints, ContentHandler, Handler, EndpointPath}; +use endpoint::{Endpoint, Endpoints, Handler, EndpointPath}; + +use api::response::as_json; pub struct RestApi { endpoints: Arc, } +#[derive(Debug, PartialEq, Serialize)] +struct App { + pub id: String, + pub name: String, + pub description: String, + pub version: String, + pub author: String, + #[serde(rename="iconUrl")] + pub icon_url: String, +} + impl RestApi { pub fn new(endpoints: Arc) -> Box { Box::new(RestApi { @@ -30,20 +41,23 @@ impl RestApi { }) } - fn list_pages(&self) -> String { - let mut s = "[".to_owned(); - for name in self.endpoints.keys() { - s.push_str(&format!("\"{}\",", name)); - } - s.push_str("\"rpc\""); - s.push_str("]"); - s + fn list_apps(&self) -> Vec { + self.endpoints.iter().filter_map(|(ref k, ref e)| { + e.info().map(|ref info| App { + id: k.to_owned().clone(), + name: info.name.clone(), + description: info.description.clone(), + version: info.version.clone(), + author: info.author.clone(), + icon_url: info.icon_url.clone(), + }) + }).collect() } } impl Endpoint for RestApi { fn to_handler(&self, _path: EndpointPath) -> Box { - Box::new(ContentHandler::new(self.list_pages(), "application/json".to_owned())) + as_json(&self.list_apps()) } } diff --git a/webapp/src/api/mod.rs b/webapp/src/api/mod.rs new file mode 100644 index 000000000..088d7f6b2 --- /dev/null +++ b/webapp/src/api/mod.rs @@ -0,0 +1,28 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! REST API + +#![warn(missing_docs)] +#![cfg_attr(feature="nightly", feature(custom_derive, custom_attribute, plugin))] +#![cfg_attr(feature="nightly", plugin(serde_macros, clippy))] + +#[cfg(feature = "serde_macros")] +include!("mod.rs.in"); + +#[cfg(not(feature = "serde_macros"))] +include!(concat!(env!("OUT_DIR"), "/mod.rs")); + diff --git a/webapp/src/api/mod.rs.in b/webapp/src/api/mod.rs.in new file mode 100644 index 000000000..0eff6b397 --- /dev/null +++ b/webapp/src/api/mod.rs.in @@ -0,0 +1,20 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +mod api; +mod response; + +pub use self::api::RestApi; diff --git a/webapp/src/api/response.rs b/webapp/src/api/response.rs new file mode 100644 index 000000000..345b8a6ee --- /dev/null +++ b/webapp/src/api/response.rs @@ -0,0 +1,23 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +use serde::Serialize; +use serde_json; +use endpoint::{ContentHandler, Handler}; + +pub fn as_json(val: &T) -> Box { + Box::new(ContentHandler::new(serde_json::to_string(val).unwrap(), "application/json".to_owned())) +} diff --git a/webapp/src/endpoint.rs b/webapp/src/endpoint.rs index d367734c4..ebb665b9d 100644 --- a/webapp/src/endpoint.rs +++ b/webapp/src/endpoint.rs @@ -30,7 +30,18 @@ pub struct EndpointPath { pub port: u16, } +#[derive(Debug, PartialEq)] +pub struct EndpointInfo { + pub name: String, + pub description: String, + pub version: String, + pub author: String, + pub icon_url: String, +} + pub trait Endpoint : Send + Sync { + fn info(&self) -> Option { None } + fn to_handler(&self, path: EndpointPath) -> Box>; } diff --git a/webapp/src/lib.rs b/webapp/src/lib.rs index 819e9d362..4cf8f0764 100644 --- a/webapp/src/lib.rs +++ b/webapp/src/lib.rs @@ -47,6 +47,8 @@ extern crate log; extern crate url; extern crate hyper; +extern crate serde; +extern crate serde_json; extern crate jsonrpc_core; extern crate jsonrpc_http_server; extern crate parity_webapp; diff --git a/webapp/src/page/mod.rs b/webapp/src/page/mod.rs index 1d987c393..c4e39161c 100644 --- a/webapp/src/page/mod.rs +++ b/webapp/src/page/mod.rs @@ -22,8 +22,8 @@ use hyper::header; use hyper::status::StatusCode; use hyper::net::HttpStream; use hyper::{Decoder, Encoder, Next}; -use endpoint::{Endpoint, EndpointPath}; -use parity_webapp::WebApp; +use endpoint::{Endpoint, EndpointInfo, EndpointPath}; +use parity_webapp::{WebApp, Info}; pub struct PageEndpoint { /// Content of the files @@ -39,6 +39,7 @@ impl PageEndpoint { prefix: None, } } + pub fn with_prefix(app: T, prefix: String) -> Self { PageEndpoint { app: Arc::new(app), @@ -48,6 +49,11 @@ impl PageEndpoint { } impl Endpoint for PageEndpoint { + + fn info(&self) -> Option { + Some(EndpointInfo::from(self.app.info())) + } + fn to_handler(&self, path: EndpointPath) -> Box> { Box::new(PageHandler { app: self.app.clone(), @@ -59,6 +65,18 @@ impl Endpoint for PageEndpoint { } } +impl From for EndpointInfo { + fn from(info: Info) -> Self { + EndpointInfo { + name: info.name, + description: info.description, + author: info.author, + icon_url: info.icon_url, + version: info.version, + } + } +} + struct PageHandler { app: Arc, prefix: Option, From b9febdda3449ce1c409e5d54f945c3b52c6a892d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 18 May 2016 11:54:15 +0200 Subject: [PATCH 2/3] Home page --- Cargo.lock | 12 ++++++------ webapp/Cargo.toml | 4 ++-- webapp/src/apps.rs | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d463dafe6..4ed88790c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,8 +356,8 @@ dependencies = [ "jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-idmanager 0.2.0 (git+https://github.com/ethcore/parity-idmanager-rs.git)", - "parity-status 0.4.0 (git+https://github.com/ethcore/parity-status.git)", + "parity-idmanager 0.2.2 (git+https://github.com/ethcore/parity-idmanager-rs.git)", + "parity-status 0.4.3 (git+https://github.com/ethcore/parity-status.git)", "parity-wallet 0.4.0 (git+https://github.com/ethcore/parity-wallet.git)", "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -836,16 +836,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-idmanager" -version = "0.2.0" -source = "git+https://github.com/ethcore/parity-idmanager-rs.git#be59a97cdd15dd733583938973ef65ff3beab463" +version = "0.2.2" +source = "git+https://github.com/ethcore/parity-idmanager-rs.git#a1c2ab1893d4abe801c821eb49247d89ab016d44" dependencies = [ "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ] [[package]] name = "parity-status" -version = "0.4.0" -source = "git+https://github.com/ethcore/parity-status.git#0ab708f869366543a8de953300e49098be0b7dbd" +version = "0.4.3" +source = "git+https://github.com/ethcore/parity-status.git#1d383d74010f6ebcd712b60b8fc5ff547b44f4e5" dependencies = [ "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ] diff --git a/webapp/Cargo.toml b/webapp/Cargo.toml index 1d71a9126..8f9353386 100644 --- a/webapp/Cargo.toml +++ b/webapp/Cargo.toml @@ -22,8 +22,8 @@ ethcore-rpc = { path = "../rpc" } ethcore-util = { path = "../util" } parity-webapp = { git = "https://github.com/ethcore/parity-webapp.git", version = "0.2" } # List of apps -parity-status = { git = "https://github.com/ethcore/parity-status.git", version = "0.4.0" } -parity-idmanager = { git = "https://github.com/ethcore/parity-idmanager-rs.git", version = "0.2.0" } +parity-status = { git = "https://github.com/ethcore/parity-status.git", version = "0.4.3" } +parity-idmanager = { git = "https://github.com/ethcore/parity-idmanager-rs.git", version = "0.2.2" } parity-wallet = { git = "https://github.com/ethcore/parity-wallet.git", version = "0.4.0", optional = true } clippy = { version = "0.0.67", optional = true} diff --git a/webapp/src/apps.rs b/webapp/src/apps.rs index 1c9b7e5a8..410a5bc2c 100644 --- a/webapp/src/apps.rs +++ b/webapp/src/apps.rs @@ -30,7 +30,7 @@ pub const API_PATH : &'static str = "api"; pub const UTILS_PATH : &'static str = "parity-utils"; pub fn main_page() -> &'static str { - "/status/" + "/home/" } pub fn utils() -> Box { @@ -43,6 +43,7 @@ pub fn all_endpoints() -> Endpoints { insert::(&mut pages, "status"); insert::(&mut pages, "parity"); + insert::(&mut pages, "home"); wallet_page(&mut pages); pages From ef38d9c769510e018e9331eb198aac827890f7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 18 May 2016 12:19:40 +0200 Subject: [PATCH 3/3] Updating idmanager --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4ed88790c..932b077fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -837,7 +837,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-idmanager" version = "0.2.2" -source = "git+https://github.com/ethcore/parity-idmanager-rs.git#a1c2ab1893d4abe801c821eb49247d89ab016d44" +source = "git+https://github.com/ethcore/parity-idmanager-rs.git#e93ef48a78722561d52ab88c3dfcc5c1465558ac" dependencies = [ "parity-webapp 0.2.0 (git+https://github.com/ethcore/parity-webapp.git)", ]