bee_block/
block_id.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4impl_id!(
5    pub BlockId,
6    32,
7    "A block identifier, the BLAKE2b-256 hash of the block bytes. See <https://www.blake2.net/> for more information."
8);
9
10#[cfg(feature = "serde")]
11string_serde_impl!(BlockId);
12
13#[cfg(feature = "inx")]
14mod inx {
15    use super::*;
16
17    impl From<BlockId> for ::inx::proto::BlockId {
18        fn from(value: BlockId) -> Self {
19            Self { id: value.0.to_vec() }
20        }
21    }
22
23    impl TryFrom<::inx::proto::BlockId> for BlockId {
24        type Error = crate::error::inx::InxError;
25
26        fn try_from(value: ::inx::proto::BlockId) -> Result<Self, Self::Error> {
27            let bytes: [u8; BlockId::LENGTH] = value.id.try_into().map_err(|e| Self::Error::InvalidId("BlockId", e))?;
28            Ok(BlockId::from(bytes))
29        }
30    }
31}