Created
October 18, 2021 09:35
-
-
Save alex-damjanovic/45a7c80593ea45e36313447f8fe9f9dd to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT; | |
| pragma solidity ^0.8.0; | |
| /// @title DonationPlatform | |
| /// @author Aleksandar Damjanivic | |
| /// @notice Can only be used for the most basic simulation | |
| /// @dev Currently facing issues with gas expenditure, deadline implementation, donation exceeding goal | |
| import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; | |
| contract DonationPlatform is Ownable{ | |
| /// @notice Campaign count so that the index of campaigns starts with 1 | |
| uint256 campaignCount = 0; | |
| mapping (uint => Campaign) public campaigns; | |
| /// @notice Grouping campaign attributes | |
| struct Campaign { | |
| uint256 id; | |
| string name; | |
| string desc; | |
| uint256 goal; | |
| uint256 deadline; | |
| uint256 raised; | |
| bool isComplete; | |
| } | |
| /// @notice addingCampaign and storing it, it accesses blockchain variables too often.. | |
| function addCampaign( | |
| string memory name, string memory desc, | |
| uint goal, uint deadline, | |
| uint raised, bool isComplete | |
| ) | |
| public onlyOwner { | |
| campaignCount +=1; | |
| campaigns[campaignCount] = Campaign(campaignCount, name, desc, goal,deadline, raised, isComplete); | |
| } | |
| /// @notice Donate function, changes is complete if raised = goal, problem when it exceeds | |
| function donate(uint id) payable public { | |
| require(msg.value > 0, "Donation must be larger than 0!!"); | |
| require((campaigns[id].raised + msg.value) <= campaigns[id].goal, "Target amount exceded"); | |
| campaigns[id].raised = campaigns[id].raised + msg.value; | |
| if (campaigns[id].raised == campaigns[id].goal) { | |
| campaigns[id].isComplete = true; | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment