-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add block issuer feature (#984)
* init * init * feat: block issuer feature * add rand * some fixes * fix more issues * change order in rand * fix no_std for box * fix no_std for macro * remove unnecessary imports * too much * fix error order * addressing comments * Update sdk/src/types/block/rand/public_key.rs Co-authored-by: Thoralf-M <[email protected]> * Update sdk/src/types/block/output/feature/block_issuer.rs Co-authored-by: Thoralf-M <[email protected]> * Update sdk/src/types/block/output/feature/block_issuer.rs Co-authored-by: Thoralf-M <[email protected]> * Update sdk/src/types/block/output/feature/block_issuer.rs Co-authored-by: Thoralf-M <[email protected]> * fixing issues * unused imports * remove alloc * add string ser-de for slot index * fmt * clippyt * Update sdk/src/types/block/rand/output/feature.rs Co-authored-by: Thoralf-M <[email protected]> * Update sdk/src/types/block/output/feature/block_issuer.rs Co-authored-by: Alexandcoats <[email protected]> * Update sdk/src/types/block/output/feature/block_issuer.rs Co-authored-by: Alexandcoats <[email protected]> * address issues * use btreeset * fix * add uniq and sorted public keys * fmt * fmt * clippy * fix non-std * fmt * remove default --------- Co-authored-by: Thoralf-M <[email protected]> Co-authored-by: Alexandcoats <[email protected]>
- Loading branch information
1 parent
46578d4
commit 901d363
Showing
34 changed files
with
270 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use alloc::vec::Vec; | ||
|
||
use crate::types::block::{ | ||
public_key::{PublicKey, PublicKeys}, | ||
slot::SlotIndex, | ||
Error, | ||
}; | ||
|
||
/// This feature defines the public keys with which a signature from the containing | ||
/// account's Block Issuance Credit can be verified in order to burn Mana. | ||
#[derive(Clone, Debug, Eq, PartialEq, Hash, packable::Packable)] | ||
#[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 Block Issuer Keys. | ||
public_keys: PublicKeys, | ||
} | ||
|
||
impl BlockIssuerFeature { | ||
/// The [`Feature`](crate::types::block::output::Feature) kind of a [`BlockIssuerFeature`]. | ||
pub const KIND: u8 = 4; | ||
|
||
/// Creates a new [`BlockIssuerFeature`]. | ||
#[inline(always)] | ||
pub fn new( | ||
expiry_slot: impl Into<SlotIndex>, | ||
public_keys: impl IntoIterator<Item = PublicKey>, | ||
) -> Result<Self, Error> { | ||
let public_keys = PublicKeys::from_vec(public_keys.into_iter().collect::<Vec<PublicKey>>())?; | ||
Ok(Self { | ||
expiry_slot: expiry_slot.into(), | ||
public_keys, | ||
}) | ||
} | ||
|
||
/// Returns the Slot Index at which the Block Issuer Feature expires and can be removed. | ||
pub fn expiry_slot(&self) -> SlotIndex { | ||
self.expiry_slot | ||
} | ||
|
||
/// Returns the Block Issuer Keys. | ||
pub fn public_keys(&self) -> &[PublicKey] { | ||
&self.public_keys | ||
} | ||
} | ||
|
||
mod dto { | ||
use alloc::vec::Vec; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::BlockIssuerFeature; | ||
use crate::types::block::{ | ||
public_key::{dto::PublicKeyDto, PublicKey}, | ||
slot::SlotIndex, | ||
Error, | ||
}; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct BlockIssuerFeatureDto { | ||
#[serde(rename = "type")] | ||
kind: u8, | ||
expiry_slot: SlotIndex, | ||
keys: Vec<PublicKeyDto>, | ||
} | ||
|
||
impl From<&BlockIssuerFeature> for BlockIssuerFeatureDto { | ||
fn from(value: &BlockIssuerFeature) -> Self { | ||
Self { | ||
kind: BlockIssuerFeature::KIND, | ||
expiry_slot: value.expiry_slot, | ||
keys: value.public_keys.iter().map(|key| key.into()).collect(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<BlockIssuerFeatureDto> for BlockIssuerFeature { | ||
type Error = Error; | ||
|
||
fn try_from(value: BlockIssuerFeatureDto) -> Result<Self, Self::Error> { | ||
let keys = value | ||
.keys | ||
.into_iter() | ||
.map(PublicKey::try_from) | ||
.collect::<Result<Vec<PublicKey>, Error>>()?; | ||
|
||
Self::new(value.expiry_slot, keys) | ||
} | ||
} | ||
|
||
impl_serde_typed_dto!(BlockIssuerFeature, BlockIssuerFeatureDto, "block issuer feature"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.