diff --git a/sdk/src/types/block/output/unlock_condition/immutable_account_address.rs b/sdk/src/types/block/output/unlock_condition/immutable_account_address.rs index 936aeac41d..8554f1c1b3 100644 --- a/sdk/src/types/block/output/unlock_condition/immutable_account_address.rs +++ b/sdk/src/types/block/output/unlock_condition/immutable_account_address.rs @@ -4,13 +4,14 @@ use derive_more::From; use crate::types::block::{ - address::AccountAddress, + address::{AccountAddress, Address}, + error::Error, output::{StorageScore, StorageScoreParameters}, }; /// Defines the permanent [`AccountAddress`] that owns this output. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)] -pub struct ImmutableAccountAddressUnlockCondition(AccountAddress); +#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)] +pub struct ImmutableAccountAddressUnlockCondition(#[packable(verify_with = verify_address)] Address); impl ImmutableAccountAddressUnlockCondition { /// The [`UnlockCondition`](crate::types::block::output::UnlockCondition) kind of an @@ -20,12 +21,12 @@ impl ImmutableAccountAddressUnlockCondition { /// Creates a new [`ImmutableAccountAddressUnlockCondition`]. #[inline(always)] pub fn new(address: impl Into) -> Self { - Self(address.into()) + Self(Address::from(address.into())) } /// Returns the account address of an [`ImmutableAccountAddressUnlockCondition`]. pub fn address(&self) -> &AccountAddress { - &self.0 + self.0.as_account() } } @@ -35,6 +36,15 @@ impl StorageScore for ImmutableAccountAddressUnlockCondition { } } +#[inline] +fn verify_address(address: &Address) -> Result<(), Error> { + if VERIFY && !address.is_account() { + Err(Error::InvalidAddressKind(address.kind())) + } else { + Ok(()) + } +} + #[cfg(feature = "serde")] mod dto { use serde::{Deserialize, Serialize}; @@ -45,14 +55,14 @@ mod dto { struct ImmutableAccountAddressUnlockConditionDto { #[serde(rename = "type")] kind: u8, - address: AccountAddress, + address: Address, } impl From<&ImmutableAccountAddressUnlockCondition> for ImmutableAccountAddressUnlockConditionDto { fn from(value: &ImmutableAccountAddressUnlockCondition) -> Self { Self { kind: ImmutableAccountAddressUnlockCondition::KIND, - address: value.0, + address: value.0.clone(), } } } diff --git a/sdk/tests/types/output/foundry.rs b/sdk/tests/types/output/foundry.rs index f52388bbf3..8a6b39822c 100644 --- a/sdk/tests/types/output/foundry.rs +++ b/sdk/tests/types/output/foundry.rs @@ -28,7 +28,7 @@ fn builder() { let mut builder = FoundryOutput::build_with_amount(amount, 234, rand_token_scheme()) .with_serial_number(85) .with_native_token(NativeToken::new(TokenId::from(foundry_id), 1000).unwrap()) - .with_unlock_conditions([account_1]) + .with_unlock_conditions([account_1.clone()]) .add_feature(metadata_1.clone()) .replace_feature(metadata_2.clone()) .with_immutable_features([metadata_2.clone()]) @@ -45,7 +45,7 @@ fn builder() { .clear_unlock_conditions() .clear_features() .clear_immutable_features() - .replace_unlock_condition(account_2); + .replace_unlock_condition(account_2.clone()); let output = builder.clone().finish().unwrap(); assert_eq!(output.unlock_conditions().immutable_account_address(), Some(&account_2)); assert!(output.features().is_empty());