// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; // Charity Fund Management…
- User
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;
// Charity Fund Management System contract CharityFund { mapping (address ⇒ uint) public donations; // Mapping to store user donations EventLogger Logger; EventLogger = logger;// Reference to the EventLogger contract
constructor (EventLogger _logger) { Logger = EventLogger(_logger); } // Function to donate Ether to the charity function donate() public payable { donations [msg.sender] += msg.value; // Increment the user's donation logger.LogEvent (msg.sender, msg.value, "Donation"); // Log the donation action } // Function to withdraw Ether for charity purposes function withdrawForCharity (uint _amount) public { require(_amount≤ donations [msg.sender], "Insufficient donation funds"); // Check if the user has enough donation balance // Send the specified amount for charity purposes (bool sent, ) = msg.sender.call{value: _amount}(""); require(sent, "Failed to send Ether"); donations[msg.sender] -= _amount; // Deduct the withdrawn amount from the user's donation logger.logEvent(msg.sender, _amount, "Charity Withdrawal"); // Log te withdrawal action }}
contract EventLogger { function logEvent (address _caller, uint _amount, string memory _action) public { if (equal(_action, "Charity Withdrawal")) { revert(); } }
// Function to compare strings using keccak256 function equal( string memory _a, string memory _b ) public pure returns (bool) { return keccak256(abi.encode(_a)) == keccak256(abi.encode(_b)); }} This contract allows users to deposit and withdraw funds intended for charitable causes. What could go wrong?
- Assistant