bee_block/payload/transaction/
transaction_id.rs1use core::ops::Deref;
5
6use crate::payload::milestone::MilestoneId;
7
8impl_id!(
9 pub TransactionId,
10 32,
11 "A transaction identifier, the BLAKE2b-256 hash of the transaction bytes. See <https://www.blake2.net/> for more information."
12);
13
14#[cfg(feature = "serde")]
15string_serde_impl!(TransactionId);
16
17impl From<MilestoneId> for TransactionId {
18 fn from(milestone_id: MilestoneId) -> Self {
19 Self::new(*milestone_id.deref())
20 }
21}
22
23#[cfg(feature = "inx")]
24mod inx {
25 use super::*;
26
27 impl From<TransactionId> for ::inx::proto::TransactionId {
28 fn from(value: TransactionId) -> Self {
29 Self { id: value.0.to_vec() }
30 }
31 }
32
33 impl TryFrom<::inx::proto::TransactionId> for TransactionId {
34 type Error = crate::error::inx::InxError;
35
36 fn try_from(value: ::inx::proto::TransactionId) -> Result<Self, Self::Error> {
37 let bytes: [u8; TransactionId::LENGTH] = value
38 .id
39 .try_into()
40 .map_err(|e| Self::Error::InvalidId("TransactionId", e))?;
41 Ok(TransactionId::from(bytes))
42 }
43 }
44}