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

Add non unique token id for foundry check #1336

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
17 changes: 14 additions & 3 deletions bee-message/src/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum ConflictReason {
AddressNotUnlocked = 14,
/// Too many native tokens.
TooManyNativeTokens = 15,
/// Non unique token id for founfry.
NonUniqueTokenIdForFoundry = 16,
/// The semantic validation failed for a reason not covered by the previous variants.
SemanticValidationFailed = 255,
}
Expand Down Expand Up @@ -103,6 +105,7 @@ impl TryFrom<u8> for ConflictReason {
13 => Self::UnlockAddressMismatch,
14 => Self::AddressNotUnlocked,
15 => Self::TooManyNativeTokens,
16 => Self::NonUniqueTokenIdForFoundry,
255 => Self::SemanticValidationFailed,
x => return Err(Self::Error::InvalidConflict(x)),
})
Expand Down Expand Up @@ -330,7 +333,7 @@ pub fn semantic_validation(
return Ok(ConflictReason::CreatedConsumedAmountMismatch);
}

let mut native_token_ids = HashSet::new();
let mut native_token_ids = HashMap::new();

// Validation of input native tokens.
for (token_id, input_amount) in context.input_native_tokens.iter() {
Expand All @@ -344,7 +347,11 @@ pub fn semantic_validation(
return Ok(ConflictReason::CreatedConsumedNativeTokensAmountMismatch);
}

native_token_ids.insert(token_id);
if let Some(token_tag) = native_token_ids.insert(token_id.foundry_id(), token_id.token_tag()) {
if token_tag != token_id.token_tag() {
return Ok(ConflictReason::NonUniqueTokenIdForFoundry);
}
}
}

// Validation of output native tokens.
Expand All @@ -359,7 +366,11 @@ pub fn semantic_validation(
return Ok(ConflictReason::CreatedConsumedNativeTokensAmountMismatch);
}

native_token_ids.insert(token_id);
if let Some(token_tag) = native_token_ids.insert(token_id.foundry_id(), token_id.token_tag()) {
if token_tag != token_id.token_tag() {
return Ok(ConflictReason::NonUniqueTokenIdForFoundry);
}
}
}

if native_token_ids.len() > NativeTokens::COUNT_MAX as usize {
Expand Down