[ipfs] Convert to edition 2018 (#10979)
* [ipfs] Converto to edition 2018 Also: whitespace * Review feedback
This commit is contained in:
parent
fbf425c4e2
commit
b1e3acaf0c
@ -4,15 +4,16 @@ name = "parity-ipfs-api"
|
|||||||
version = "1.12.0"
|
version = "1.12.0"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
client-traits = { path = "../ethcore/client-traits" }
|
client-traits = { path = "../ethcore/client-traits" }
|
||||||
common-types = { path = "../ethcore/types" }
|
common-types = { path = "../ethcore/types" }
|
||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
parity-bytes = "0.1"
|
bytes = { package = "parity-bytes", version = "0.1"}
|
||||||
ethereum-types = "0.6.0"
|
ethereum-types = "0.6.0"
|
||||||
jsonrpc-core = "12.0.0"
|
core = { package = "jsonrpc-core", version = "12.0.0"}
|
||||||
jsonrpc-http-server = "12.0.0"
|
http = { package = "jsonrpc-http-server", version = "12.0.0"}
|
||||||
rlp = "0.4.0"
|
rlp = "0.4.0"
|
||||||
cid = "0.3"
|
cid = "0.3"
|
||||||
multihash = "0.8"
|
multihash = "0.8"
|
||||||
|
@ -14,16 +14,15 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use {multihash, cid, http};
|
use crate::route::Out;
|
||||||
use route::Out;
|
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
/// IPFS server error
|
/// IPFS server error
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ServerError {
|
pub enum ServerError {
|
||||||
/// Wrapped `std::io::Error`
|
/// Wrapped `std::io::Error`
|
||||||
IoError(::std::io::Error),
|
IoError(std::io::Error),
|
||||||
/// Other `hyper` error
|
/// Other `hyper` error
|
||||||
Other(http::hyper::error::Error),
|
Other(http::hyper::error::Error),
|
||||||
/// Invalid --ipfs-api-interface
|
/// Invalid --ipfs-api-interface
|
||||||
@ -31,8 +30,8 @@ pub enum ServerError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handle IO errors (ports taken when starting the server).
|
/// Handle IO errors (ports taken when starting the server).
|
||||||
impl From<::std::io::Error> for ServerError {
|
impl From<std::io::Error> for ServerError {
|
||||||
fn from(err: ::std::io::Error) -> ServerError {
|
fn from(err: std::io::Error) -> ServerError {
|
||||||
ServerError::IoError(err)
|
ServerError::IoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,8 +52,8 @@ impl From<ServerError> for String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::fmt::Display for ServerError {
|
impl std::fmt::Display for ServerError {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ServerError::IoError(err) => write!(f, "Io Error: {}", err),
|
ServerError::IoError(err) => write!(f, "Io Error: {}", err),
|
||||||
ServerError::Other(err) => write!(f, "Other error: {}", err),
|
ServerError::Other(err) => write!(f, "Other error: {}", err),
|
||||||
@ -63,7 +62,7 @@ impl ::std::fmt::Display for ServerError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::error::Error for ServerError {}
|
impl std::error::Error for ServerError {}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -14,19 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// 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;
|
pub mod error;
|
||||||
mod route;
|
mod route;
|
||||||
|
|
||||||
@ -53,19 +40,19 @@ pub struct IpfsHandler {
|
|||||||
/// Hostnames allowed in the `Host` request header
|
/// Hostnames allowed in the `Host` request header
|
||||||
allowed_hosts: Option<Vec<Host>>,
|
allowed_hosts: Option<Vec<Host>>,
|
||||||
/// Reference to the Blockchain Client
|
/// Reference to the Blockchain Client
|
||||||
client: Arc<BlockChainClient>,
|
client: Arc<dyn BlockChainClient>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IpfsHandler {
|
impl IpfsHandler {
|
||||||
pub fn client(&self) -> &BlockChainClient {
|
pub fn client(&self) -> &dyn BlockChainClient {
|
||||||
&*self.client
|
&*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 {
|
IpfsHandler {
|
||||||
cors_domains: cors.into(),
|
cors_domains: cors.into(),
|
||||||
allowed_hosts: hosts.into(),
|
allowed_hosts: hosts.into(),
|
||||||
client: client,
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn on_request(&self, req: hyper::Request<Body>) -> (Option<HeaderValue>, Out) {
|
pub fn on_request(&self, req: hyper::Request<Body>) -> (Option<HeaderValue>, Out) {
|
||||||
@ -156,7 +143,7 @@ pub fn start_server(
|
|||||||
interface: String,
|
interface: String,
|
||||||
cors: DomainsValidation<AccessControlAllowOrigin>,
|
cors: DomainsValidation<AccessControlAllowOrigin>,
|
||||||
hosts: DomainsValidation<Host>,
|
hosts: DomainsValidation<Host>,
|
||||||
client: Arc<BlockChainClient>
|
client: Arc<dyn BlockChainClient>
|
||||||
) -> Result<Listening, ServerError> {
|
) -> Result<Listening, ServerError> {
|
||||||
|
|
||||||
let ip: IpAddr = interface.parse().map_err(|_| ServerError::InvalidInterface)?;
|
let ip: IpAddr = interface.parse().map_err(|_| ServerError::InvalidInterface)?;
|
||||||
|
@ -14,14 +14,17 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use {rlp, multihash, IpfsHandler};
|
use crate::{
|
||||||
use error::{Error, Result};
|
IpfsHandler,
|
||||||
use cid::{ToCid, Codec};
|
error::{Error, Result},
|
||||||
|
};
|
||||||
|
|
||||||
use common_types::ids::{BlockId, TransactionId};
|
|
||||||
use multihash::Hash;
|
|
||||||
use ethereum_types::H256;
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use cid::{ToCid, Codec};
|
||||||
|
use common_types::ids::{BlockId, TransactionId};
|
||||||
|
use ethereum_types::H256;
|
||||||
|
use multihash::{self, Hash};
|
||||||
|
use rlp;
|
||||||
|
|
||||||
type Reason = &'static str;
|
type Reason = &'static str;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user