Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create builders from outputs #1340

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bee-message/src/output/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ impl AliasOutputBuilder {
}
}

impl From<&AliasOutput> for AliasOutputBuilder {
fn from(output: &AliasOutput) -> Self {
AliasOutputBuilder {
amount: OutputBuilderAmount::Amount(output.amount),
native_tokens: output.native_tokens.to_vec(),
alias_id: output.alias_id,
state_index: Some(output.state_index),
state_metadata: output.state_metadata.to_vec(),
foundry_counter: Some(output.foundry_counter),
unlock_conditions: output.unlock_conditions.to_vec(),
feature_blocks: output.feature_blocks.to_vec(),
immutable_feature_blocks: output.immutable_feature_blocks.to_vec(),
}
}
}

pub(crate) type StateMetadataLength = BoundedU16<0, { AliasOutput::STATE_METADATA_LENGTH_MAX }>;

/// Describes an alias account in the ledger that can be controlled by the state and governance controllers.
Expand Down
11 changes: 11 additions & 0 deletions bee-message/src/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ impl BasicOutputBuilder {
}
}

impl From<&BasicOutput> for BasicOutputBuilder {
fn from(output: &BasicOutput) -> Self {
BasicOutputBuilder {
amount: OutputBuilderAmount::Amount(output.amount),
native_tokens: output.native_tokens.to_vec(),
unlock_conditions: output.unlock_conditions.to_vec(),
feature_blocks: output.feature_blocks.to_vec(),
}
}
}

/// Describes a basic output with optional features.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down
15 changes: 15 additions & 0 deletions bee-message/src/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ impl FoundryOutputBuilder {
}
}

impl From<&FoundryOutput> for FoundryOutputBuilder {
fn from(output: &FoundryOutput) -> Self {
FoundryOutputBuilder {
amount: OutputBuilderAmount::Amount(output.amount),
native_tokens: output.native_tokens.to_vec(),
serial_number: output.serial_number,
token_tag: output.token_tag,
token_scheme: output.token_scheme.clone(),
unlock_conditions: output.unlock_conditions.to_vec(),
feature_blocks: output.feature_blocks.to_vec(),
immutable_feature_blocks: output.immutable_feature_blocks.to_vec(),
}
}
}

/// Describes a foundry output that is controlled by an alias.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down
13 changes: 13 additions & 0 deletions bee-message/src/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ impl NftOutputBuilder {
}
}

impl From<&NftOutput> for NftOutputBuilder {
fn from(output: &NftOutput) -> Self {
NftOutputBuilder {
amount: OutputBuilderAmount::Amount(output.amount),
native_tokens: output.native_tokens.to_vec(),
nft_id: output.nft_id,
unlock_conditions: output.unlock_conditions.to_vec(),
feature_blocks: output.feature_blocks.to_vec(),
immutable_feature_blocks: output.immutable_feature_blocks.to_vec(),
}
}
}

/// Describes an NFT output, a globally unique token with metadata attached.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down