Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
qrayven committed Aug 1, 2023
1 parent ab28953 commit 5419ba2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
3 changes: 2 additions & 1 deletion sdk/src/types/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use primitive_types::U256;
use crate::types::block::{
input::UtxoInput,
output::{
feature::block_issuer::PublicKeyCount, feature::FeatureCount, unlock_condition::UnlockConditionCount,
feature::{FeatureCount, PublicKeyCount},
unlock_condition::UnlockConditionCount,
AccountId, ChainId, MetadataFeatureLength, NativeTokenCount, NftId, OutputIndex, StateMetadataLength,
TagFeatureLength,
},
Expand Down
23 changes: 11 additions & 12 deletions sdk/src/types/block/output/feature/block_issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use packable::{bounded::BoundedU8, prefix::BoxedSlicePrefix};

use crate::types::block::{public_key::PublicKey, slot::SlotIndex, Error};

pub type PublicKeyCount = BoundedU8<0, { u8::MAX }>;
const KEY_COUNT_MIN: u8 = 1;
const KEY_COUNT_MAX: u8 = 128;

pub(crate) type PublicKeyCount = BoundedU8<KEY_COUNT_MIN, KEY_COUNT_MAX>;

/// This feature defines the public keys with which a signature to burn Mana from
/// the containing account's Block Issuance Credit can be verified.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, packable::Packable)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[packable(unpack_error = Error)]
pub struct BlockIssuerFeature {
/// The slot index at which the Block Issuer Feature expires and can be removed.
expiry_slot: SlotIndex,
/// The number of Block Issuer Keys.
keys_count: u8,
/// The Block Issuer Keys.
#[packable(unpack_error_with = |e| e.unwrap_item_err_or_else(|p| Error::InvalidPublicKeyCount(p.into())))]
keys: BoxedSlicePrefix<PublicKey, PublicKeyCount>,
Expand All @@ -33,7 +33,6 @@ impl BlockIssuerFeature {

Ok(Self {
expiry_slot: expiry_slot.into(),
keys_count: keys.len() as u8,
keys: keys.try_into().map_err(Error::InvalidPublicKeyCount)?,
})
}
Expand All @@ -45,7 +44,7 @@ impl BlockIssuerFeature {

/// Returns the number of Block Issuer Keys.
pub fn keys_count(&self) -> u8 {
self.keys_count
self.keys.len() as u8
}

/// Returns the Block Issuer Keys.
Expand All @@ -55,17 +54,17 @@ impl BlockIssuerFeature {
}

pub(crate) mod dto {
use packable::bounded::TryIntoBoundedU8Error;
use serde::{Deserialize, Serialize};

use super::BlockIssuerFeature;
use crate::{
types::block::{
public_key::{dto::PublicKeyDto, PublicKey},
Error,
},
utils::serde::string,
};
use packable::bounded::TryIntoBoundedU8Error;
use serde::{Deserialize, Serialize};

use super::BlockIssuerFeature;

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct BlockIssuerFeatureDto {
Expand All @@ -83,7 +82,7 @@ pub(crate) mod dto {
Self {
kind: BlockIssuerFeature::KIND,
expiry_slot: value.expiry_slot.into(),
keys_count: value.keys_count,
keys_count: value.keys_count(),
keys: value.keys.iter().map(|key| key.into()).collect(),

Check failure on line 86 in sdk/src/types/block/output/feature/block_issuer.rs

View workflow job for this annotation

GitHub Actions / Check `no_std` compatability

type annotations needed
}
}
Expand All @@ -96,7 +95,7 @@ pub(crate) mod dto {
let keys = value
.keys
.into_iter()
.map(|key| PublicKey::try_from(key))
.map(PublicKey::try_from)
.collect::<Result<Vec<PublicKey>, Error>>()?;

Check failure on line 99 in sdk/src/types/block/output/feature/block_issuer.rs

View workflow job for this annotation

GitHub Actions / Check `no_std` compatability

cannot find type `Vec` in this scope

if value.keys_count != keys.len() as u8 {
Expand Down
14 changes: 7 additions & 7 deletions sdk/src/types/block/output/feature/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

pub mod block_issuer;
mod block_issuer;
mod issuer;
mod metadata;
mod sender;
Expand All @@ -15,11 +15,11 @@ use derive_more::{Deref, From};
use iterator_sorted::is_unique_sorted;
use packable::{bounded::BoundedU8, prefix::BoxedSlicePrefix, Packable};

use self::block_issuer::BlockIssuerFeature;
pub use self::{
issuer::IssuerFeature, metadata::MetadataFeature, sender::SenderFeature, staking::StakingFeature, tag::TagFeature,
block_issuer::BlockIssuerFeature, issuer::IssuerFeature, metadata::MetadataFeature, sender::SenderFeature,
staking::StakingFeature, tag::TagFeature,
};
pub(crate) use self::{metadata::MetadataFeatureLength, tag::TagFeatureLength};
pub(crate) use self::{block_issuer::PublicKeyCount, metadata::MetadataFeatureLength, tag::TagFeatureLength};
use crate::types::block::{create_bitflags, Error};

///
Expand All @@ -40,12 +40,12 @@ pub enum Feature {
/// A tag feature.
#[packable(tag = TagFeature::KIND)]
Tag(TagFeature),
/// A staking feature.
#[packable(tag = StakingFeature::KIND)]
Staking(StakingFeature),
/// A block issuer feature.
#[packable(tag = BlockIssuerFeature::KIND)]
BlockIssuer(BlockIssuerFeature),
/// A staking feature.
#[packable(tag = StakingFeature::KIND)]
Staking(StakingFeature),
}

impl PartialOrd for Feature {
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/rand/output/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use alloc::vec::Vec;

use crate::types::block::{
output::feature::{
block_issuer::BlockIssuerFeature, Feature, FeatureFlags, IssuerFeature, MetadataFeature, SenderFeature,
StakingFeature, TagFeature,
BlockIssuerFeature, Feature, FeatureFlags, IssuerFeature, MetadataFeature, SenderFeature, StakingFeature,
TagFeature,
},
rand::{
address::rand_address,
Expand Down

0 comments on commit 5419ba2

Please sign in to comment.