bee_block/unlock/
signature.rs

1// Copyright 2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use derive_more::{Deref, From};
5
6use crate::signature::Signature;
7
8/// An [`Unlock`](crate::unlock::Unlock) which is used to unlock a signature locked
9/// [`Input`](crate::input::Input).
10#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, Deref, packable::Packable)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct SignatureUnlock(Signature);
13
14impl SignatureUnlock {
15    /// The [`Unlock`](crate::unlock::Unlock) kind of a [`SignatureUnlock`].
16    pub const KIND: u8 = 0;
17
18    /// Creates a new [`SignatureUnlock`].
19    #[inline(always)]
20    pub fn new(signature: Signature) -> Self {
21        Self(signature)
22    }
23
24    /// Returns the actual [`Signature`] of the [`SignatureUnlock`].
25    #[inline(always)]
26    pub fn signature(&self) -> &Signature {
27        &self.0
28    }
29}
30
31#[cfg(feature = "dto")]
32#[allow(missing_docs)]
33pub mod dto {
34    use serde::{Deserialize, Serialize};
35
36    use crate::signature::dto::SignatureDto;
37
38    /// Defines an unlock containing signature(s) unlocking input(s).
39    #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
40    pub struct SignatureUnlockDto {
41        #[serde(rename = "type")]
42        pub kind: u8,
43        pub signature: SignatureDto,
44    }
45}