-
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.
* add commitment and block issuance credit inputs * add tests * add fn documentation * improve test * fix * fmt * remove spaces between fields * imporve order of methods * improve panic message * alternate `is_` and `as_` methods * fix commitment documentation * improve DTOs * fix missing import * fix macro call * fix macro calls * Update sdk/src/types/block/context_input/block_issuance_credit.rs Co-authored-by: Alexandcoats <[email protected]> --------- Co-authored-by: Alexandcoats <[email protected]>
- Loading branch information
Showing
4 changed files
with
267 additions
and
31 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
sdk/src/types/block/context_input/block_issuance_credit.rs
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,65 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use derive_more::{Display, From}; | ||
|
||
use crate::types::block::output::AccountId; | ||
|
||
/// A Block Issuance Credit (BIC) Input provides the VM with context for the value of | ||
/// the BIC vector of a specific slot. | ||
#[derive(Clone, Copy, Debug, Display, Eq, PartialEq, Hash, Ord, PartialOrd, From, packable::Packable)] | ||
pub struct BlockIssuanceCreditContextInput(AccountId); | ||
|
||
impl BlockIssuanceCreditContextInput { | ||
/// The context input kind of a [`BlockIssuanceCreditContextInput`]. | ||
pub const KIND: u8 = 1; | ||
|
||
/// Creates a new [`BlockIssuanceCreditContextInput`]. | ||
pub fn new(account_id: AccountId) -> Self { | ||
Self(account_id) | ||
} | ||
|
||
/// Returns the account id of the [`BlockIssuanceCreditContextInput`]. | ||
pub fn account_id(&self) -> AccountId { | ||
self.0 | ||
} | ||
} | ||
|
||
mod dto { | ||
use alloc::format; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::*; | ||
|
||
/// A Block Issuance Credit Input provides the VM with context for the value of | ||
/// the BIC vector of a specific slot. | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct BlockIssuanceCreditContextInputDto { | ||
#[serde(rename = "type")] | ||
kind: u8, | ||
account_id: AccountId, | ||
} | ||
|
||
impl From<&BlockIssuanceCreditContextInput> for BlockIssuanceCreditContextInputDto { | ||
fn from(value: &BlockIssuanceCreditContextInput) -> Self { | ||
Self { | ||
kind: BlockIssuanceCreditContextInput::KIND, | ||
account_id: value.account_id(), | ||
} | ||
} | ||
} | ||
|
||
impl From<BlockIssuanceCreditContextInputDto> for BlockIssuanceCreditContextInput { | ||
fn from(value: BlockIssuanceCreditContextInputDto) -> Self { | ||
Self::new(value.account_id) | ||
} | ||
} | ||
|
||
impl_serde_typed_dto!( | ||
BlockIssuanceCreditContextInput, | ||
BlockIssuanceCreditContextInputDto, | ||
"block issuance credit context input" | ||
); | ||
} |
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,62 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use derive_more::{Display, From}; | ||
|
||
use crate::types::block::slot::SlotCommitmentId; | ||
|
||
/// A Commitment Input indicates that the input references a commitment to a certain slot. | ||
#[derive(Clone, Copy, Display, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, From, packable::Packable)] | ||
pub struct CommitmentContextInput(SlotCommitmentId); | ||
|
||
impl CommitmentContextInput { | ||
/// The context input kind of a [`CommitmentContextInput`]. | ||
pub const KIND: u8 = 0; | ||
|
||
/// Creates a new [`CommitmentContextInput`]. | ||
pub fn new(commitment_id: SlotCommitmentId) -> Self { | ||
Self(commitment_id) | ||
} | ||
|
||
/// Returns the commitment id of the [`CommitmentContextInput`]. | ||
pub fn commitment_id(&self) -> SlotCommitmentId { | ||
self.0 | ||
} | ||
} | ||
|
||
mod dto { | ||
use alloc::format; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::*; | ||
|
||
/// A Commitment Input indicates that the input references a commitment to a certain slot. | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct CommitmentContextInputDto { | ||
#[serde(rename = "type")] | ||
kind: u8, | ||
commitment_id: SlotCommitmentId, | ||
} | ||
|
||
impl From<&CommitmentContextInput> for CommitmentContextInputDto { | ||
fn from(value: &CommitmentContextInput) -> Self { | ||
Self { | ||
kind: CommitmentContextInput::KIND, | ||
commitment_id: value.commitment_id(), | ||
} | ||
} | ||
} | ||
|
||
impl From<CommitmentContextInputDto> for CommitmentContextInput { | ||
fn from(value: CommitmentContextInputDto) -> Self { | ||
Self::new(value.commitment_id) | ||
} | ||
} | ||
impl_serde_typed_dto!( | ||
CommitmentContextInput, | ||
CommitmentContextInputDto, | ||
"commitment context input" | ||
); | ||
} |
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