hiero_sdk/
transaction_hash.rs1use std::fmt::{
4 self,
5 Debug,
6 Display,
7 Formatter,
8};
9
10use sha2::{
11 Digest,
12 Sha384,
13};
14
15#[derive(Copy, Clone, Hash)]
19pub struct TransactionHash(pub [u8; 48]);
20
21impl TransactionHash {
22 #[must_use]
23 pub(crate) fn new(bytes: &[u8]) -> Self {
24 Self(Sha384::digest(bytes).into())
25 }
26}
27
28impl Debug for TransactionHash {
29 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
30 write!(f, "\"{self}\"")
31 }
32}
33
34impl Display for TransactionHash {
35 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
36 f.pad(&hex::encode(self.0))
37 }
38}