Skip to content

Commit

Permalink
Merge branch '2.0' into native-token-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 20, 2023
2 parents abdd9bc + e595d73 commit ad96d8e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ enum UnlockType {
* An NFT unlock.
*/
Nft = 4,
/**
* A multi unlock.
*/
Multi = 5,
/**
* An empty unlock.
*/
Empty = 6,
}

/**
Expand Down Expand Up @@ -139,6 +147,64 @@ class NftUnlock extends Unlock {
}
}

/**
* Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked.
*/
class EmptyUnlock extends Unlock {
constructor() {
super(UnlockType.Empty);
}
}

/**
* Unlocks a MultiAddress with a list of other unlocks.
*/
class MultiUnlock extends Unlock {
/**
* The inner unlocks.
*/
@Type(() => Unlock, {
discriminator: {
property: 'type',
subTypes: [
{
value: SignatureUnlock,
name: UnlockType.Signature as any,
},
{
value: ReferenceUnlock,
name: UnlockType.Reference as any,
},
{
value: AccountUnlock,
name: UnlockType.Account as any,
},
{
value: AnchorUnlock,
name: UnlockType.Anchor as any,
},
{
value: NftUnlock,
name: UnlockType.Nft as any,
},
{
value: EmptyUnlock,
name: UnlockType.Empty as any,
},
],
},
})
readonly unlocks: Unlock[];

/**
* @param unlocks The inner unlocks.
*/
constructor(unlocks: Unlock[]) {
super(UnlockType.Multi);
this.unlocks = unlocks;
}
}

const UnlockDiscriminator = {
property: 'type',
subTypes: [
Expand All @@ -162,6 +228,14 @@ const UnlockDiscriminator = {
value: NftUnlock,
name: UnlockType.Nft as any,
},
{
value: MultiUnlock,
name: UnlockType.Multi as any,
},
{
value: EmptyUnlock,
name: UnlockType.Empty as any,
},
],
};

Expand All @@ -173,5 +247,7 @@ export {
AccountUnlock,
AnchorUnlock,
NftUnlock,
MultiUnlock,
EmptyUnlock,
UnlockDiscriminator,
};
2 changes: 1 addition & 1 deletion sdk/src/types/block/payload/candidacy_announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ use packable::Packable;
pub struct CandidacyAnnouncementPayload;

impl CandidacyAnnouncementPayload {
/// The payload kind of a [`CandidacyAnnouncementPayload`].
/// The [`Payload`](crate::types::block::payload::Payload) kind of a [`CandidacyAnnouncementPayload`].
pub const KIND: u8 = 2;
}
2 changes: 1 addition & 1 deletion sdk/src/types/block/payload/signed_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct SignedTransactionPayload {
}

impl SignedTransactionPayload {
/// The payload kind of a [`SignedTransactionPayload`].
/// The [`Payload`](crate::types::block::payload::Payload) kind of a [`SignedTransactionPayload`].
pub const KIND: u8 = 1;

/// Creates a new [`SignedTransactionPayload`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use packable::{
Packable,
};

use crate::types::block::{Block, Error};
use crate::types::block::Error;

pub(crate) type TagLength =
BoundedU8<{ *TaggedDataPayload::TAG_LENGTH_RANGE.start() }, { *TaggedDataPayload::TAG_LENGTH_RANGE.end() }>;
Expand All @@ -30,15 +30,12 @@ pub struct TaggedDataPayload {
}

impl TaggedDataPayload {
/// The payload kind of a [`TaggedDataPayload`].
/// The [`Payload`](crate::types::block::payload::Payload) kind of a [`TaggedDataPayload`].
pub const KIND: u8 = 0;
/// Valid lengths for the tag.
/// Valid length range for the tag.
pub const TAG_LENGTH_RANGE: RangeInclusive<u8> = 0..=64;
/// Valid lengths for the data.
// Less than max block length, because of the other fields in the block and payload kind, tagged payload field
// lengths.
// TODO https://github.com/iotaledger/iota-sdk/issues/1226
pub const DATA_LENGTH_RANGE: RangeInclusive<u32> = 0..=(Block::LENGTH_MAX - Block::LENGTH_MIN - 9) as u32;
/// Valid length range for the data.
pub const DATA_LENGTH_RANGE: RangeInclusive<u32> = 0..=8192;

/// Creates a new [`TaggedDataPayload`].
pub fn new(tag: impl Into<Box<[u8]>>, data: impl Into<Box<[u8]>>) -> Result<Self, Error> {
Expand Down

0 comments on commit ad96d8e

Please sign in to comment.