diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index 18c32126f3..00c909c919 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -165,7 +165,9 @@ impl DelegationOutputBuilder { /// Finishes the builder into a [`DelegationOutput`] without parameters verification. pub fn finish(self) -> Result { - verify_validator_address::(&self.validator_address)?; + let validator_address = Address::from(self.validator_address); + + verify_validator_address::(&validator_address)?; let unlock_conditions = UnlockConditions::from_set(self.unlock_conditions)?; @@ -175,7 +177,7 @@ impl DelegationOutputBuilder { amount: 0, delegated_amount: self.delegated_amount, delegation_id: self.delegation_id, - validator_address: self.validator_address, + validator_address, start_epoch: self.start_epoch, end_epoch: self.end_epoch, unlock_conditions, @@ -201,7 +203,7 @@ impl From<&DelegationOutput> for DelegationOutputBuilder { amount: OutputBuilderAmount::Amount(output.amount), delegated_amount: output.delegated_amount, delegation_id: output.delegation_id, - validator_address: output.validator_address, + validator_address: *output.validator_address.as_account(), start_epoch: output.start_epoch, end_epoch: output.end_epoch, unlock_conditions: output.unlock_conditions.iter().cloned().collect(), @@ -222,7 +224,7 @@ pub struct DelegationOutput { delegation_id: DelegationId, /// Account address of the validator to which this output is delegating. #[packable(verify_with = verify_validator_address_packable)] - validator_address: AccountAddress, + validator_address: Address, /// Index of the first epoch for which this output delegates. start_epoch: EpochIndex, /// Index of the last epoch for which this output delegates. @@ -281,7 +283,7 @@ impl DelegationOutput { /// Returns the validator address of the [`DelegationOutput`]. pub fn validator_address(&self) -> &AccountAddress { - &self.validator_address + &self.validator_address.as_account() } /// Returns the start epoch of the [`DelegationOutput`]. @@ -350,16 +352,22 @@ impl WorkScore for DelegationOutput { impl MinimumOutputAmount for DelegationOutput {} -fn verify_validator_address(validator_address: &AccountAddress) -> Result<(), Error> { - if VERIFY && validator_address.is_null() { - Err(Error::NullDelegationValidatorId) - } else { - Ok(()) +fn verify_validator_address(validator_address: &Address) -> Result<(), Error> { + if VERIFY { + if let Address::Account(validator_address) = validator_address { + if validator_address.is_null() { + return Err(Error::NullDelegationValidatorId); + } + } else { + return Err(Error::InvalidAddressKind(validator_address.kind())); + } } + + Ok(()) } fn verify_validator_address_packable( - validator_address: &AccountAddress, + validator_address: &Address, _: &ProtocolParameters, ) -> Result<(), Error> { verify_validator_address::(validator_address) diff --git a/sdk/src/types/block/output/feature/metadata.rs b/sdk/src/types/block/output/feature/metadata.rs index 434235ff5b..090e5ebda7 100644 --- a/sdk/src/types/block/output/feature/metadata.rs +++ b/sdk/src/types/block/output/feature/metadata.rs @@ -268,7 +268,7 @@ pub(crate) mod irc_27 { use pretty_assertions::assert_eq; use super::*; - use crate::types::block::{address::ToBech32Ext, rand::address::rand_address}; + use crate::types::block::{address::ToBech32Ext, rand::address::rand_base_address}; #[test] fn serialization() { @@ -278,8 +278,8 @@ pub(crate) mod irc_27 { "My NFT #0001", ) .with_collection_name("My Collection of Art") - .add_royalty(rand_address().to_bech32_unchecked("iota1"), 0.025) - .add_royalty(rand_address().to_bech32_unchecked("iota1"), 0.025) + .add_royalty(rand_base_address().to_bech32_unchecked("iota1"), 0.025) + .add_royalty(rand_base_address().to_bech32_unchecked("iota1"), 0.025) .with_issuer_name("My Artist Name") .with_description("A little information about my NFT collection") .add_attribute(Attribute::new("Background", "Purple"))