diff --git a/sdk/src/types/api/core.rs b/sdk/src/types/api/core.rs index 39cee0fb51..83f6391c68 100644 --- a/sdk/src/types/api/core.rs +++ b/sdk/src/types/api/core.rs @@ -220,14 +220,21 @@ pub struct ValidatorsResponse { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ManaRewardsResponse { - /// The starting epoch index for which the mana rewards are returned. + /// First epoch for which rewards can be claimed. + /// This value is useful for checking if rewards have expired (by comparing against the staking or delegation + /// start) or would expire soon (by checking its relation to the rewards retention period). pub start_epoch: EpochIndex, - /// The ending epoch index for which the mana rewards are returned, the decay is applied up to this point - /// included. + /// Last epoch for which rewards can be claimed. pub end_epoch: EpochIndex, - /// The amount of totally available rewards the requested output may claim. + /// Amount of totally available decayed rewards the requested output may claim. #[serde(with = "string")] pub rewards: u64, + /// Rewards of the latest committed epoch of the staking pool to which this validator or delegator belongs. + /// The ratio of this value and the maximally possible rewards for the latest committed epoch can be used to + /// determine how well the validator of this staking pool performed in that epoch. + /// Note that if the pool was not part of the committee in the latest committed epoch, this value is 0. + #[serde(with = "string")] + pub latest_committed_epoch_pool_rewards: u64, } /// Response of GET /api/core/v3/committee 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 d48b5bcbd2..f65a8d32a0 100644 --- a/sdk/src/types/block/output/feature/metadata.rs +++ b/sdk/src/types/block/output/feature/metadata.rs @@ -304,7 +304,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() { @@ -314,8 +314,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"))