Skip to content

Commit a1f69df

Browse files
committed
Merge branch 'develop'
2 parents d4db7c3 + e9d22ce commit a1f69df

4 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎contracts/escrow/src/core/dispute.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ impl DisputeManager {
3131
let token_client = TokenClient::new(&e, &escrow.trustline.address);
3232
let current_balance = token_client.balance(&contract_address);
3333

34+
let mut total: i128 = 0;
35+
for (_addr, amount) in distributions.iter() {
36+
if amount <= 0 {
37+
return Err(ContractError::AmountsToBeTransferredShouldBePositive);
38+
}
39+
total = BasicMath::safe_add(total, amount)?;
40+
}
41+
3442
validate_dispute_resolution_conditions(
3543
&escrow,
3644
&dispute_resolver,
37-
&distributions,
3845
current_balance,
46+
total,
3947
)?;
4048

41-
let mut total: i128 = 0;
42-
for (_addr, amount) in distributions.iter() {
43-
total = BasicMath::safe_add(total, amount)?;
44-
}
4549
let fee_result = FeeCalculator::calculate_standard_fees(total, escrow.platform_fee)?;
4650
let total_fees =
4751
BasicMath::safe_add(fee_result.trustless_work_fee, fee_result.platform_fee)?;

‎contracts/escrow/src/core/validators/dispute.rs‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use soroban_sdk::{Address, Map};
1+
use soroban_sdk::Address;
22

3-
use crate::modules::math::{BasicArithmetic, BasicMath};
43
use crate::{
54
error::ContractError,
65
storage::types::{Escrow, Roles},
@@ -10,8 +9,8 @@ use crate::{
109
pub fn validate_dispute_resolution_conditions(
1110
escrow: &Escrow,
1211
dispute_resolver: &Address,
13-
distributions: &Map<Address, i128>,
1412
current_balance: i128,
13+
total: i128,
1514
) -> Result<(), ContractError> {
1615
if dispute_resolver != &escrow.roles.dispute_resolver {
1716
return Err(ContractError::OnlyDisputeResolverCanExecuteThisFunction);
@@ -21,23 +20,18 @@ pub fn validate_dispute_resolution_conditions(
2120
return Err(ContractError::EscrowNotInDispute);
2221
}
2322

24-
let mut total: i128 = 0;
25-
for (_addr, amount) in distributions.iter() {
26-
if amount < 0 {
27-
return Err(ContractError::AmountsToBeTransferredShouldBePositive);
28-
}
29-
total = BasicMath::safe_add(total, amount)?;
30-
}
31-
if total <= 0 {
32-
return Err(ContractError::AmountCannotBeZero);
33-
}
3423
if current_balance < total {
3524
return Err(ContractError::InsufficientFundsForResolution);
3625
}
26+
3727
if total != current_balance {
3828
return Err(ContractError::DistributionsMustEqualEscrowBalance);
3929
}
4030

31+
if total <= 0 {
32+
return Err(ContractError::TotalAmountCannotBeZero);
33+
}
34+
4135
Ok(())
4236
}
4337

‎contracts/escrow/src/error.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum ContractError {
4444
IncompatibleEscrowWasmHash = 36,
4545
PlatformAddressCannotBeChanged = 37,
4646
DisputeResolverCannotDisputeTheEscrow = 40,
47+
TotalAmountCannotBeZero = 41,
4748
}
4849

4950
impl fmt::Display for ContractError {
@@ -122,7 +123,7 @@ impl fmt::Display for ContractError {
122123
ContractError::AmountsToBeTransferredShouldBePositive => {
123124
write!(
124125
f,
125-
"None of the amounts to be transferred should be less than 0."
126+
"None of the amounts to be transferred should be less or equal than 0."
126127
)
127128
}
128129
ContractError::DistributionsMustEqualEscrowBalance => {
@@ -170,6 +171,9 @@ impl fmt::Display for ContractError {
170171
ContractError::DisputeResolverCannotDisputeTheEscrow => {
171172
write!(f, "The dispute resolver cannot dispute the escrow.")
172173
}
174+
ContractError::TotalAmountCannotBeZero => {
175+
write!(f, "The total amount to be distributed cannot be equal to zero.")
176+
}
173177
}
174178
}
175179
}

‎contracts/escrow/src/tests/test.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ fn test_dispute_management() {
892892
let escrow = escrow_approver.get_escrow();
893893
assert!(!escrow.flags.disputed);
894894

895-
escrow_approver.dispute_escrow(&dispute_resolver_address);
895+
escrow_approver.dispute_escrow(&approver_address);
896896

897897
let escrow_after_change = escrow_approver.get_escrow();
898898
assert!(escrow_after_change.flags.disputed);
@@ -903,7 +903,7 @@ fn test_dispute_management() {
903903
escrow_approver.try_release_funds(&release_signer_address);
904904
assert!(result.is_err());
905905

906-
let _ = escrow_approver.try_dispute_escrow(&dispute_resolver_address);
906+
let _ = escrow_approver.try_dispute_escrow(&approver_address);
907907

908908
let escrow_after_second_change = escrow_approver.get_escrow();
909909
assert!(escrow_after_second_change.flags.disputed);

0 commit comments

Comments
 (0)