Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tendermint: improve fmt::UpperHex impl on Transaction #613

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tendermint/src/abci/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

Expand Down Expand Up @@ -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");
}
}