Skip to content

Commit

Permalink
tendermint: impl fmt::UpperHex for abci::Transaction (#610)
Browse files Browse the repository at this point in the history
Found myself wanting it today. I imagine you could use similar impls
throughout this crate, which allow you to do things like:

    println!("tx: {:X}", tx);
  • Loading branch information
tony-iqlusion authored Oct 6, 2020
1 parent 8ec241f commit e3821ff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tendermint/src/abci/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
mod hash;

pub use self::hash::Hash;
use std::slice;
use {
serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer},
subtle_encoding::base64,
};
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::{fmt, slice};
use subtle_encoding::base64;

/// Transactions are arbitrary byte arrays whose contents are validated by the
/// underlying Tendermint application.
Expand Down Expand Up @@ -40,6 +38,12 @@ impl AsRef<[u8]> for Transaction {
}
}

impl fmt::UpperHex for Transaction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:X?}", self.as_bytes())
}
}

impl<'de> Deserialize<'de> for Transaction {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let bytes = base64::decode(String::deserialize(deserializer)?.as_bytes())
Expand Down

0 comments on commit e3821ff

Please sign in to comment.