Created
April 10, 2023 20:53
-
-
Save iamendy/5519bc43d4fd1f95b1073a3382982d81 to your computer and use it in GitHub Desktop.
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.9; | |
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract TipX is ReentrancyGuard, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter counter; | |
struct Tip{ | |
uint id; | |
string title; | |
string description; | |
uint maxAmount; | |
bool status; | |
} | |
struct Payment{ | |
uint tipId; | |
string customer; | |
string description; | |
uint amount; | |
} | |
//for storing all tips created by a user | |
mapping(address => Tip[]) public allUserTips; | |
//for storing all payments received by a user | |
mapping(uint => Payment[]) public Payments; | |
function createNewTip( | |
string memory _title, | |
string memory _description, | |
uint _maxAmount, | |
bool _status) | |
external returns (Tip memory latestTip){ | |
//require(!_title && !_description && _maxAmount && _status, "All fields are required!"); | |
counter.increment(); | |
//Create a new tip template | |
Tip memory newTip; | |
newTip.id = counter.current(); | |
newTip.title = _title; | |
newTip.description = _description; | |
newTip.maxAmount = _maxAmount; | |
newTip.status = _status; | |
//save new tip template to caller | |
allUserTips[msg.sender].push(newTip); | |
return newTip; | |
} | |
function getUserTips() external view returns ( Tip[] memory) { | |
Tip memory tips = allUserTips[msg.sender]; | |
return tips; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment