bee_block/unlock/
alias.rs1use crate::{unlock::UnlockIndex, Error};
5
6#[derive(Clone, Debug, Eq, PartialEq, Hash, packable::Packable)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[packable(unpack_error = Error, with = Error::InvalidAliasIndex)]
10pub struct AliasUnlock(
11 UnlockIndex,
13);
14
15impl TryFrom<u16> for AliasUnlock {
16 type Error = Error;
17
18 fn try_from(index: u16) -> Result<Self, Self::Error> {
19 Self::new(index)
20 }
21}
22
23impl AliasUnlock {
24 pub const KIND: u8 = 2;
26
27 #[inline(always)]
29 pub fn new(index: u16) -> Result<Self, Error> {
30 index.try_into().map(Self).map_err(Error::InvalidAliasIndex)
31 }
32
33 #[inline(always)]
35 pub fn index(&self) -> u16 {
36 self.0.get()
37 }
38}
39
40#[cfg(feature = "dto")]
41#[allow(missing_docs)]
42pub mod dto {
43 use serde::{Deserialize, Serialize};
44
45 #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
47 pub struct AliasUnlockDto {
48 #[serde(rename = "type")]
49 pub kind: u8,
50 #[serde(rename = "reference")]
51 pub index: u16,
52 }
53}