Skip to content

Commit

Permalink
Add sender check
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Mar 14, 2022
1 parent 06d893b commit 42e5c96
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions bee-ledger/src/workers/consensus/white_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bee_message::{
address::Address,
input::Input,
output::{
AliasId, AliasOutput, BasicOutput, FeatureBlock, FoundryOutput, NftId, NftOutput, Output, OutputId,
AliasId, AliasOutput, BasicOutput, FoundryOutput, NftId, NftOutput, Output, OutputId,
UnlockCondition,
},
payload::{
Expand Down Expand Up @@ -70,24 +70,6 @@ fn check_input_unlock_conditions(
Ok(())
}

fn check_output_feature_blocks(
feature_blocks: &[FeatureBlock],
context: &ValidationContext,
) -> Result<(), ConflictReason> {
for feature_block in feature_blocks {
match feature_block {
FeatureBlock::Sender(sender) => {
if !context.unlocked_addresses.contains(sender.address()) {
return Err(ConflictReason::UnverifiedSender);
}
}
_ => {}
}
}

Ok(())
}

fn unlock_address(
address: &Address,
unlock_block: &UnlockBlock,
Expand Down Expand Up @@ -288,15 +270,20 @@ fn apply_regular_essence<B: StorageBackend>(

// Validation of outputs.
for created_output in essence.outputs() {
// TODO also check feature blocks ?
let (amount, created_native_tokens) = match created_output {
Output::Basic(output) => (output.amount(), output.native_tokens()),
Output::Alias(output) => (output.amount(), output.native_tokens()),
Output::Foundry(output) => (output.amount(), output.native_tokens()),
Output::Nft(output) => (output.amount(), output.native_tokens()),
let (amount, created_native_tokens, feature_blocks) = match created_output {
Output::Basic(output) => (output.amount(), output.native_tokens(), output.feature_blocks()),
Output::Alias(output) => (output.amount(), output.native_tokens(), output.feature_blocks()),
Output::Foundry(output) => (output.amount(), output.native_tokens(), output.feature_blocks()),
Output::Nft(output) => (output.amount(), output.native_tokens(), output.feature_blocks()),
_ => return Err(Error::UnsupportedOutputKind(created_output.kind())),
};

if let Some(sender) = feature_blocks.sender() {
if !context.unlocked_addresses.contains(sender.address()) {
return Ok(ConflictReason::UnverifiedSender);
}
}

context.output_amount = context
.output_amount
.checked_sub(amount)
Expand Down

0 comments on commit 42e5c96

Please sign in to comment.