Skip to content

Commit

Permalink
require(success) instead of manual state revert
Browse files Browse the repository at this point in the history
  • Loading branch information
yakuhito committed Aug 26, 2021
1 parent 1c0a71a commit 77c2e58
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions contracts/yakuSwap.sol
Expand Up @@ -63,9 +63,8 @@ contract yakuSwap is Ownable {

swap.status = SwapStatus.Completed;
(bool success,) = swap.toAddress.call{value: swap.amount}("");
if(!success) {
swap.status = SwapStatus.Created;
}

require(success);
}

function cancelSwap(bytes32 _swapId) public {
Expand All @@ -76,17 +75,14 @@ contract yakuSwap is Ownable {

swap.status = SwapStatus.Cancelled;
(bool success,) = swap.fromAddress.call{value: swap.amount}("");
if(!success) {
swap.status = SwapStatus.Created;
}

require(success);
}

function getFees() public onlyOwner {
uint oldTotalFees = totalFees;
totalFees = 0;
(bool success,) = owner().call{value: totalFees}("");
if(!success) {
totalFees = oldTotalFees;
}

require(success);
}
}

0 comments on commit 77c2e58

Please sign in to comment.