impl Display for BlockHash and TxId

This commit is contained in:
Jack Grigg
2018-10-11 23:16:48 +01:00
parent 20d5cdc571
commit a1664c6bbc
5 changed files with 29 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ authors = [
[dependencies]
byteorder = "1"
ff = { path = "../ff" }
hex = "0.3"
lazy_static = "1"
pairing = { path = "../pairing" }
rand = "0.4"

View File

@@ -1,8 +1,18 @@
use hex;
use std::fmt;
use std::ops::Deref;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct BlockHash(pub [u8; 32]);
impl fmt::Display for BlockHash {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let mut data = self.0.to_vec();
data.reverse();
formatter.write_str(&hex::encode(data))
}
}
/// A Zcash block header.
pub struct BlockHeader(BlockHeaderData);

View File

@@ -4,6 +4,7 @@ extern crate lazy_static;
extern crate blake2_rfc;
extern crate byteorder;
extern crate ff;
extern crate hex;
extern crate pairing;
extern crate rand;
extern crate sapling_crypto;

View File

@@ -1,5 +1,7 @@
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use hex;
use sapling_crypto::redjubjub::Signature;
use std::fmt;
use std::io::{self, Read, Write};
use std::ops::Deref;
@@ -23,6 +25,14 @@ const SAPLING_TX_VERSION: u32 = 4;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TxId(pub [u8; 32]);
impl fmt::Display for TxId {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let mut data = self.0.to_vec();
data.reverse();
formatter.write_str(&hex::encode(data))
}
}
/// A Zcash transaction.
#[derive(Debug)]
pub struct Transaction(TransactionData);