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

Remove native tokens from AnchorOutput #1660

Merged
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
46 changes: 3 additions & 43 deletions sdk/src/types/block/output/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::types::block::{
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId,
StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters,
ChainId, MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, StateTransitionError,
StateTransitionVerifier, StorageScore, StorageScoreParameters,
},
payload::signed_transaction::TransactionCapabilityFlag,
protocol::ProtocolParameters,
Expand Down Expand Up @@ -89,7 +89,6 @@ impl core::fmt::Display for AnchorTransition {
pub struct AnchorOutputBuilder {
amount: OutputBuilderAmount,
mana: u64,
native_tokens: BTreeSet<NativeToken>,
anchor_id: AnchorId,
state_index: u32,
unlock_conditions: BTreeSet<UnlockCondition>,
Expand All @@ -114,7 +113,6 @@ impl AnchorOutputBuilder {
Self {
amount,
mana: Default::default(),
native_tokens: BTreeSet::new(),
anchor_id,
state_index: 0,
unlock_conditions: BTreeSet::new(),
Expand Down Expand Up @@ -144,20 +142,6 @@ impl AnchorOutputBuilder {
self
}

///
#[inline(always)]
pub fn add_native_token(mut self, native_token: NativeToken) -> Self {
self.native_tokens.insert(native_token);
self
}

///
#[inline(always)]
pub fn with_native_tokens(mut self, native_tokens: impl IntoIterator<Item = NativeToken>) -> Self {
self.native_tokens = native_tokens.into_iter().collect();
self
}

/// Sets the anchor ID to the provided value.
#[inline(always)]
pub fn with_anchor_id(mut self, anchor_id: AnchorId) -> Self {
Expand Down Expand Up @@ -275,7 +259,6 @@ impl AnchorOutputBuilder {
let mut output = AnchorOutput {
amount: 0,
mana: self.mana,
native_tokens: NativeTokens::from_set(self.native_tokens)?,
anchor_id: self.anchor_id,
state_index: self.state_index,
unlock_conditions,
Expand All @@ -302,7 +285,6 @@ impl From<&AnchorOutput> for AnchorOutputBuilder {
Self {
amount: OutputBuilderAmount::Amount(output.amount),
mana: output.mana,
native_tokens: output.native_tokens.iter().copied().collect(),
anchor_id: output.anchor_id,
state_index: output.state_index,
unlock_conditions: output.unlock_conditions.iter().cloned().collect(),
Expand All @@ -318,8 +300,6 @@ pub struct AnchorOutput {
/// Amount of IOTA coins held by the output.
amount: u64,
mana: u64,
/// Native tokens held by the output.
native_tokens: NativeTokens,
/// Unique identifier of the anchor.
anchor_id: AnchorId,
/// A counter that must increase by 1 every time the anchor is state transitioned.
Expand Down Expand Up @@ -367,12 +347,6 @@ impl AnchorOutput {
self.mana
}

///
#[inline(always)]
pub fn native_tokens(&self) -> &NativeTokens {
&self.native_tokens
}

///
#[inline(always)]
pub fn anchor_id(&self) -> &AnchorId {
Expand Down Expand Up @@ -503,7 +477,7 @@ impl AnchorOutput {
}
} else if next_state.state_index == current_state.state_index {
// Governance transition.
if current_state.amount != next_state.amount || current_state.native_tokens != next_state.native_tokens
if current_state.amount != next_state.amount
// TODO https://github.com/iotaledger/iota-sdk/issues/1650
// || current_state.state_metadata != next_state.state_metadata
{
Expand Down Expand Up @@ -580,7 +554,6 @@ impl Packable for AnchorOutput {
fn pack<P: Packer>(&self, packer: &mut P) -> Result<(), P::Error> {
self.amount.pack(packer)?;
self.mana.pack(packer)?;
self.native_tokens.pack(packer)?;
self.anchor_id.pack(packer)?;
self.state_index.pack(packer)?;
self.unlock_conditions.pack(packer)?;
Expand All @@ -598,7 +571,6 @@ impl Packable for AnchorOutput {

let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?;
let anchor_id = AnchorId::unpack::<_, VERIFY>(unpacker, &()).coerce()?;
let state_index = u32::unpack::<_, VERIFY>(unpacker, &()).coerce()?;

Expand Down Expand Up @@ -628,7 +600,6 @@ impl Packable for AnchorOutput {
Ok(Self {
amount,
mana,
native_tokens,
anchor_id,
state_index,
unlock_conditions,
Expand Down Expand Up @@ -692,8 +663,6 @@ pub(crate) mod dto {
pub amount: u64,
#[serde(with = "string")]
pub mana: u64,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub native_tokens: Vec<NativeToken>,
pub anchor_id: AnchorId,
pub state_index: u32,
pub unlock_conditions: Vec<UnlockConditionDto>,
Expand All @@ -709,7 +678,6 @@ pub(crate) mod dto {
kind: AnchorOutput::KIND,
amount: value.amount(),
mana: value.mana(),
native_tokens: value.native_tokens().to_vec(),
anchor_id: *value.anchor_id(),
state_index: value.state_index(),
unlock_conditions: value.unlock_conditions().iter().map(Into::into).collect::<_>(),
Expand All @@ -726,7 +694,6 @@ pub(crate) mod dto {
let mut builder = AnchorOutputBuilder::new_with_amount(dto.amount, dto.anchor_id)
.with_mana(dto.mana)
.with_state_index(dto.state_index)
.with_native_tokens(dto.native_tokens)
.with_features(dto.features)
.with_immutable_features(dto.immutable_features);

Expand All @@ -743,7 +710,6 @@ pub(crate) mod dto {
pub fn try_from_dtos(
amount: OutputBuilderAmount,
mana: u64,
native_tokens: Option<Vec<NativeToken>>,
anchor_id: &AnchorId,
state_index: u32,
unlock_conditions: Vec<UnlockConditionDto>,
Expand All @@ -759,10 +725,6 @@ pub(crate) mod dto {
.with_mana(mana)
.with_state_index(state_index);

if let Some(native_tokens) = native_tokens {
builder = builder.with_native_tokens(native_tokens);
}

let unlock_conditions = unlock_conditions
.into_iter()
.map(UnlockCondition::from)
Expand Down Expand Up @@ -811,7 +773,6 @@ mod tests {
let output_split = AnchorOutput::try_from_dtos(
OutputBuilderAmount::Amount(output.amount()),
output.mana(),
Some(output.native_tokens().to_vec()),
output.anchor_id(),
output.state_index(),
output.unlock_conditions().iter().map(Into::into).collect(),
Expand All @@ -829,7 +790,6 @@ mod tests {
let output_split = AnchorOutput::try_from_dtos(
builder.amount,
builder.mana,
Some(builder.native_tokens.iter().copied().collect()),
&builder.anchor_id,
builder.state_index,
builder.unlock_conditions.iter().map(Into::into).collect(),
Expand Down
Loading