Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ipfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ name = "parity-ipfs-api"
version = "1.12.0"
license = "GPL-3.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
client-traits = { path = "../ethcore/client-traits" }
common-types = { path = "../ethcore/types" }
ethcore = { path = "../ethcore" }
parity-bytes = "0.1"
bytes = { package = "parity-bytes", version = "0.1"}
ethereum-types = "0.6.0"
jsonrpc-core = "12.0.0"
jsonrpc-http-server = "12.0.0"
core = { package = "jsonrpc-core", version = "12.0.0"}
http = { package = "jsonrpc-http-server", version = "12.0.0"}
rlp = "0.4.0"
cid = "0.3"
multihash = "0.8"
Expand Down
29 changes: 14 additions & 15 deletions ipfs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

use {multihash, cid, http};
use route::Out;
use crate::route::Out;

pub type Result<T> = ::std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;

/// IPFS server error
#[derive(Debug)]
pub enum ServerError {
/// Wrapped `std::io::Error`
IoError(::std::io::Error),
IoError(std::io::Error),
/// Other `hyper` error
Other(http::hyper::error::Error),
/// Invalid --ipfs-api-interface
InvalidInterface
}

/// Handle IO errors (ports taken when starting the server).
impl From<::std::io::Error> for ServerError {
fn from(err: ::std::io::Error) -> ServerError {
impl From<std::io::Error> for ServerError {
fn from(err: std::io::Error) -> ServerError {
ServerError::IoError(err)
}
}
Expand All @@ -53,17 +52,17 @@ impl From<ServerError> for String {
}
}

impl ::std::fmt::Display for ServerError {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match self {
ServerError::IoError(err) => write!(f, "Io Error: {}", err),
ServerError::Other(err) => write!(f, "Other error: {}", err),
ServerError::InvalidInterface => write!(f, "Invalid interface"),
}
}
impl std::fmt::Display for ServerError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
ServerError::IoError(err) => write!(f, "Io Error: {}", err),
ServerError::Other(err) => write!(f, "Other error: {}", err),
ServerError::InvalidInterface => write!(f, "Invalid interface"),
}
}
}

impl ::std::error::Error for ServerError {}
impl std::error::Error for ServerError {}

#[derive(Debug, PartialEq)]
pub enum Error {
Expand Down
33 changes: 10 additions & 23 deletions ipfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

extern crate multihash;
extern crate cid;
extern crate unicase;

extern crate rlp;
extern crate client_traits;
extern crate common_types;
extern crate ethcore;
extern crate parity_bytes as bytes;
extern crate ethereum_types;
extern crate jsonrpc_core as core;
extern crate jsonrpc_http_server as http;

pub mod error;
mod route;

Expand All @@ -53,19 +40,19 @@ pub struct IpfsHandler {
/// Hostnames allowed in the `Host` request header
allowed_hosts: Option<Vec<Host>>,
/// Reference to the Blockchain Client
client: Arc<BlockChainClient>,
client: Arc<dyn BlockChainClient>,
}

impl IpfsHandler {
pub fn client(&self) -> &BlockChainClient {
pub fn client(&self) -> &dyn BlockChainClient {
&*self.client
}

pub fn new(cors: DomainsValidation<AccessControlAllowOrigin>, hosts: DomainsValidation<Host>, client: Arc<BlockChainClient>) -> Self {
pub fn new(cors: DomainsValidation<AccessControlAllowOrigin>, hosts: DomainsValidation<Host>, client: Arc<dyn BlockChainClient>) -> Self {
IpfsHandler {
cors_domains: cors.into(),
allowed_hosts: hosts.into(),
client: client,
client,
}
}
pub fn on_request(&self, req: hyper::Request<Body>) -> (Option<HeaderValue>, Out) {
Expand Down Expand Up @@ -156,7 +143,7 @@ pub fn start_server(
interface: String,
cors: DomainsValidation<AccessControlAllowOrigin>,
hosts: DomainsValidation<Host>,
client: Arc<BlockChainClient>
client: Arc<dyn BlockChainClient>
) -> Result<Listening, ServerError> {

let ip: IpAddr = interface.parse().map_err(|_| ServerError::InvalidInterface)?;
Expand Down Expand Up @@ -184,12 +171,12 @@ pub fn start_server(
};

let server = server_bldr
.serve(new_service)
.map_err(|_| ())
.select(shutdown_signal.map_err(|_| ()))
.then(|_| Ok(()));
.serve(new_service)
.map_err(|_| ())
.select(shutdown_signal.map_err(|_| ()))
.then(|_| Ok(()));

hyper::rt::run(server);
hyper::rt::run(server);
send(Ok(()));
});

Expand Down
13 changes: 8 additions & 5 deletions ipfs/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

use {rlp, multihash, IpfsHandler};
use error::{Error, Result};
use cid::{ToCid, Codec};
use crate::{
IpfsHandler,
error::{Error, Result},
};

use bytes::Bytes;
use cid::{ToCid, Codec};
use common_types::ids::{BlockId, TransactionId};
use multihash::Hash;
use ethereum_types::H256;
use bytes::Bytes;
use multihash::{self, Hash};
use rlp;

type Reason = &'static str;

Expand Down