From 80722783a42169543ac19da6c02bde8dd825b72f Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 6 Oct 2020 07:11:17 -0700 Subject: [PATCH] tendermint: improve fmt::UpperHex impl on Transaction The previous implementation would print hex strings like: ``` [FF, 1, FE, 2] ``` This changes the implementation to print the following instead (with test): ``` FF01FE02 ``` --- tendermint/src/abci/transaction.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tendermint/src/abci/transaction.rs b/tendermint/src/abci/transaction.rs index db040594f..b5d50d89b 100644 --- a/tendermint/src/abci/transaction.rs +++ b/tendermint/src/abci/transaction.rs @@ -40,7 +40,11 @@ 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()) + for byte in self.as_bytes() { + write!(f, "{:02X}", byte)?; + } + + Ok(()) } } @@ -97,3 +101,15 @@ impl AsRef<[Transaction]> for Data { self.txs.as_deref().unwrap_or_else(|| &[]) } } + +#[cfg(test)] +mod tests { + use super::Transaction; + + #[test] + fn upper_hex_serialization() { + let tx = Transaction::new(vec![0xFF, 0x01, 0xFE, 0x02]); + let tx_hex = format!("{:X}", &tx); + assert_eq!(&tx_hex, "FF01FE02"); + } +}