Switch to bs (#150)

* Switch to `bs`

* fmt
This commit is contained in:
Jef 2018-03-17 15:32:12 +01:00 committed by Pierre Krieger
parent d6f1b9bf5b
commit 1e86c6ed35
5 changed files with 9 additions and 10 deletions

View File

@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
arrayvec = "0.4.7"
base58 = "0.1.0"
bs58 = "0.2.0"
bigint = "4.2"
bytes = "0.4"
datastore = { path = "../datastore" }

View File

@ -62,8 +62,8 @@
//
extern crate arrayvec;
extern crate base58;
extern crate bigint;
extern crate bs58;
extern crate bytes;
extern crate datastore;
extern crate fnv;

View File

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
base58 = "0.1.0"
bs58 = "0.2.0"
datastore = { path = "../datastore" }
futures = "0.1.0"
owning_ref = "0.3.3"

View File

@ -22,7 +22,6 @@
use super::TTL;
use PeerId;
use base58::{FromBase58, ToBase58};
use datastore::{Datastore, JsonFileDatastore, JsonFileDatastoreEntry, Query};
use futures::{Future, Stream};
use multiaddr::Multiaddr;
@ -32,6 +31,7 @@ use std::io::Error as IoError;
use std::iter;
use std::path::PathBuf;
use std::vec::IntoIter as VecIntoIter;
use bs58;
/// Peerstore backend that uses a Json file.
pub struct JsonPeerstore {
@ -70,13 +70,13 @@ impl<'a> Peerstore for &'a JsonPeerstore {
#[inline]
fn peer(self, peer_id: &PeerId) -> Option<Self::PeerAccess> {
let hash = peer_id.as_bytes().to_base58();
let hash = bs58::encode(peer_id.as_bytes()).into_string();
self.store.lock(hash.into()).map(JsonPeerstoreAccess)
}
#[inline]
fn peer_or_create(self, peer_id: &PeerId) -> Self::PeerAccess {
let hash = peer_id.as_bytes().to_base58();
let hash = bs58::encode(peer_id.as_bytes()).into_string();
JsonPeerstoreAccess(self.store.lock_or_create(hash.into()))
}
@ -94,7 +94,7 @@ impl<'a> Peerstore for &'a JsonPeerstore {
.filter_map(|(key, _)| {
// We filter out invalid elements. This can happen if the JSON storage file was
// corrupted or manually modified by the user.
PeerId::from_bytes(key.from_base58().ok()?).ok()
PeerId::from_bytes(bs58::decode(key).into_vec().ok()?).ok()
})
.collect()
.wait(); // Wait can never block for the JSON datastore.

View File

@ -67,7 +67,7 @@
//! # }
//! ```
extern crate base58;
extern crate bs58;
extern crate datastore;
extern crate futures;
extern crate multiaddr;
@ -78,7 +78,6 @@ extern crate serde;
extern crate serde_derive;
use std::fmt;
use base58::ToBase58;
pub use self::peerstore::{PeerAccess, Peerstore};
@ -103,7 +102,7 @@ pub struct PeerId {
impl fmt::Debug for PeerId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "PeerId({})", self.multihash.to_base58())
write!(f, "PeerId({})", bs58::encode(&self.multihash).into_string())
}
}