I need code of solidity for donation app using ethereum
pragma solidity ^0.8.0;
contract DonationApp {
// Variables
address payable public owner;
mapping(address => uint) public donations;
// Constructor
constructor() {
owner = payable(msg.sender);
}
// Functions
// Modifier to check if the caller is the owner of the contract
modifier onlyOwner {
require(msg.sender == owner, “Caller is not the owner.”);
_;
}
// Function to donate ether to the contract
function donate() public payable {
require(msg.value > 0, “Donation amount must be greater than 0.”);
uint newDonation = msg.value;
donations[msg.sender] += newDonation;
}
// Function to withdraw all donations from the contract
function withdrawDonations() public onlyOwner {
uint balance = address(this).balance;
owner.transfer(balance);
}
// Function to view total donations for the contract
function viewTotalDonations() public view returns(uint) {
return address(this).balance;
}
// Function to view a specific donation amount by address
function viewDonation(address donor) public view returns(uint) {
return donations[donor];
}
// Function to reset donations
function resetDonations() public onlyOwner {
// Reset all donations
for (uint i=0; i < donations.length; i++) {
donations[i] = 0;
}
}
}
