use derive_more::From;
use crate::types::block::address::Address;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)]
pub struct StateControllerAddressUnlockCondition(Address);
impl StateControllerAddressUnlockCondition {
pub const KIND: u8 = 4;
#[inline(always)]
pub fn new(address: impl Into<Address>) -> Self {
Self(address.into())
}
#[inline(always)]
pub fn address(&self) -> &Address {
&self.0
}
}
#[cfg(feature = "serde")]
pub(crate) mod dto {
use serde::{Deserialize, Serialize};
use super::*;
use crate::types::block::{address::dto::AddressDto, Error};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct StateControllerAddressUnlockConditionDto {
#[serde(rename = "type")]
pub kind: u8,
pub address: AddressDto,
}
impl From<&StateControllerAddressUnlockCondition> for StateControllerAddressUnlockConditionDto {
fn from(value: &StateControllerAddressUnlockCondition) -> Self {
Self {
kind: StateControllerAddressUnlockCondition::KIND,
address: value.address().into(),
}
}
}
impl TryFrom<StateControllerAddressUnlockConditionDto> for StateControllerAddressUnlockCondition {
type Error = Error;
fn try_from(value: StateControllerAddressUnlockConditionDto) -> Result<Self, Error> {
Ok(Self::new(Address::try_from(value.address).map_err(|_e| {
Error::InvalidField("stateControllerAddressUnlockCondition")
})?))
}
}
}