Skip to content
Snippets Groups Projects
Commit 8d1c1c0a authored by Éloïs's avatar Éloïs
Browse files

[fix] #55 impl Serialize for WOT Documents & pubkey

parent 4423c287
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@
//!
//! [`KeyPairGenerator`]: struct.KeyPairGenerator.html
extern crate serde;
use std::collections::hash_map::DefaultHasher;
use std::fmt::Display;
use std::fmt::Error;
......@@ -30,6 +32,7 @@ use base58::{FromBase58, FromBase58Error, ToBase58};
use base64;
use base64::DecodeError;
use crypto;
use self::serde::ser::{Serialize, Serializer};
use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as PublicKeyMethods};
......@@ -123,6 +126,15 @@ impl Debug for PublicKey {
}
}
impl Serialize for PublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}", self))
}
}
impl super::PublicKey for PublicKey {
type Signature = Signature;
......
......@@ -15,8 +15,11 @@
//! Wrappers around Certification documents.
extern crate serde;
use duniter_crypto::keys::{PublicKey, Signature, ed25519};
use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use Blockstamp;
use blockchain::{BlockchainProtocol, Document, DocumentBuilder, IntoSpecializedDocument};
......@@ -120,6 +123,15 @@ impl TextDocument for CertificationDocument {
}
}
impl Serialize for CertificationDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for CertificationDocument {
fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Certification(Box::new(self))))
......
......@@ -15,8 +15,11 @@
//! Wrappers around Identity documents.
extern crate serde;
use duniter_crypto::keys::{PublicKey, ed25519};
use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use Blockstamp;
use blockchain::{BlockchainProtocol, Document, DocumentBuilder, IntoSpecializedDocument};
......@@ -100,6 +103,15 @@ impl TextDocument for IdentityDocument {
}
}
impl Serialize for IdentityDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument {
fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Identity(self)))
......
......@@ -15,8 +15,11 @@
//! Wrappers around Membership documents.
extern crate serde;
use duniter_crypto::keys::{PublicKey, ed25519};
use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use Blockstamp;
use blockchain::{BlockchainProtocol, Document, DocumentBuilder, IntoSpecializedDocument};
......@@ -122,6 +125,15 @@ impl TextDocument for MembershipDocument {
}
}
impl Serialize for MembershipDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument {
fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Membership(self)))
......
......@@ -15,8 +15,11 @@
//! Wrappers around Revocation documents.
extern crate serde;
use duniter_crypto::keys::{PublicKey, Signature, ed25519};
use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use Blockstamp;
use blockchain::{BlockchainProtocol, Document, DocumentBuilder, IntoSpecializedDocument};
......@@ -102,6 +105,15 @@ impl TextDocument for RevocationDocument {
}
}
impl Serialize for RevocationDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for RevocationDocument {
fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Revocation(Box::new(self))))
......
......@@ -118,7 +118,7 @@ impl Hash {
/// Wrapper of a block hash.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct BlockHash(Hash);
pub struct BlockHash(pub Hash);
impl Display for BlockHash {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment