Skip to content

Commit

Permalink
Simplify SDRUC syntactic validation rules (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Apr 5, 2022
1 parent 0c37b57 commit 86a5eb9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
8 changes: 0 additions & 8 deletions bee-message/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub enum Error {
InsufficientStorageDepositAmount { amount: u64, required: u64 },
StorageDepositReturnExceedsOutputAmount { deposit: u64, amount: u64 },
InsufficientStorageDepositReturnAmount { deposit: u64, required: u64 },
UnnecessaryStorageDepositReturnCondition { logical_amount: u64, required: u64 },
InvalidEssenceKind(u8),
InvalidFeatureBlockCount(<FeatureBlockCount as TryFrom<usize>>::Error),
InvalidFeatureBlockKind(u8),
Expand Down Expand Up @@ -170,13 +169,6 @@ impl fmt::Display for Error {
f,
"storage deposit return of {deposit} exceeds the original output amount of {amount}"
),
Error::UnnecessaryStorageDepositReturnCondition {
logical_amount,
required,
} => write!(
f,
"no storage deposit return is needed, the logical output amount {logical_amount} already covers the required deposit {required}"
),
Error::InvalidEssenceKind(k) => write!(f, "invalid essence kind: {}", k),
Error::InvalidFeatureBlockCount(count) => write!(f, "invalid feature block count: {}", count),
Error::InvalidFeatureBlockKind(k) => write!(f, "invalid feature block kind: {}", k),
Expand Down
13 changes: 2 additions & 11 deletions bee-message/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Output {
.and_then(UnlockConditions::storage_deposit_return)
{
// We can't return more tokens than were originally contained in the output.
// `0` ≤ `Amount` - `Return Amount`
// `Return Amount` ≤ `Amount`.
if return_condition.amount() > self.amount() {
return Err(Error::StorageDepositReturnExceedsOutputAmount {
deposit: return_condition.amount(),
Expand All @@ -244,22 +244,13 @@ impl Output {

let minimum_deposit = minimum_storage_deposit(config, return_condition.return_address());

// `Return Amount` must be ≥ than `Minimum Storage Deposit`
// `Minimum Storage Deposit` ≤ `Return Amount`
if return_condition.amount() < minimum_deposit {
return Err(Error::InsufficientStorageDepositReturnAmount {
deposit: return_condition.amount(),
required: minimum_deposit,
});
}

// Check if the storage deposit return was required in the first place.
// `Amount` - `Return Amount` ≤ `Required Storage Deposit of the Output`
if self.amount() - return_condition.amount() > required_output_amount {
return Err(Error::UnnecessaryStorageDepositReturnCondition {
logical_amount: self.amount() - return_condition.amount(),
required: required_output_amount,
});
}
}

Ok(())
Expand Down

0 comments on commit 86a5eb9

Please sign in to comment.