Skip to content

Commit

Permalink
Merge branch '2.0' into refactor-MetadataFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 authored Dec 28, 2023
2 parents 64bf548 + bf43541 commit 70a88cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
15 changes: 11 additions & 4 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 19 additions & 11 deletions sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ impl DelegationOutputBuilder {

/// Finishes the builder into a [`DelegationOutput`] without parameters verification.
pub fn finish(self) -> Result<DelegationOutput, Error> {
verify_validator_address::<true>(&self.validator_address)?;
let validator_address = Address::from(self.validator_address);

verify_validator_address::<true>(&validator_address)?;

let unlock_conditions = UnlockConditions::from_set(self.unlock_conditions)?;

Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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.
Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -350,16 +352,22 @@ impl WorkScore for DelegationOutput {

impl MinimumOutputAmount for DelegationOutput {}

fn verify_validator_address<const VERIFY: bool>(validator_address: &AccountAddress) -> Result<(), Error> {
if VERIFY && validator_address.is_null() {
Err(Error::NullDelegationValidatorId)
} else {
Ok(())
fn verify_validator_address<const VERIFY: bool>(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<const VERIFY: bool>(
validator_address: &AccountAddress,
validator_address: &Address,
_: &ProtocolParameters,
) -> Result<(), Error> {
verify_validator_address::<VERIFY>(validator_address)
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/feature/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"))
Expand Down

0 comments on commit 70a88cf

Please sign in to comment.