Manual review.
- uint256 public totalAmountGivenToRam;
+ mapping(address organiserOrRam => uint256 amount) public amountToWithdraw;
function killRavana() public RamIsSelected {
.
.
.
- totalAmountGivenToRam = (totalAmountByThePeople * 50) / 100;
+ uint256 reward = (totalAmountByThePeople * 50) / 100;
+ amountToWithdraw[organiser] = reward;
+ amountToWithdraw[choosingRamContract.selectedRam()] = reward;
- (bool success,) = organiser.call{value: totalAmountGivenToRam}("");
- require(success, "Failed to send money to organiser");
}
- function withdraw() public RamIsSelected OnlyRam RavanKilled {
- if (totalAmountGivenToRam == 0) {
- revert Dussehra__AlreadyClaimedAmount();
- }
- uint256 amount = totalAmountGivenToRam;
- (bool success,) = msg.sender.call{value: amount}("");
- require(success, "Failed to send money to Ram");
- totalAmountGivenToRam = 0;
- }
+ function organiserWithdraw() public RamIsSelected RavanKilled {
+ if (msg.sender != organiser) {
+ revert();
+ }
+ if (amountToWithdraw[organiser] == 0) {
+ revert();
+ }
+ uint256 amount = amountToWithdraw[organiser];
+ amountToWithdraw[organiser] = 0;
+ (bool success,) = msg.sender.call{value: amount}("");
+ require(success, "Failed to send money to organiser");
+ }
+ function ramWithdraw() public RamIsSelected OnlyRam RavanKilled {
+ address ram = choosingRamContract.selectedRam();
+ if (amountToWithdraw[ram] == 0) {
+ revert();
+ }
+ uint256 amount = amountToWithdraw[ram];
+ amountToWithdraw[ram] = 0;
+ (bool success,) = msg.sender.call{value: amount}("");
+ require(success, "Failed to send money to Ram");
+ }