// SPDX-License-Identifier: MIT pragma solidity ^0.5.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/PullPayment.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; contract DApping is ERC 721, Ownable, PullPayment, AccessControl, ERC721URIStorage, Counters { using Counters for Counters.Counter; Counters.Counter private _tokenIds; string public name; uint public postCount = 0; mapping(uint => Post) public posts; struct Post { uint id; string content; uint tipAmount; address payable _author; } event PostCreated( uint id, string content, uint tipAmount, address payable author ); event PostTipped( uint id, string content, uint tipAmount, address payable author ); constructor() public { name = "DApping"; } function createPost(string memory _content) public { // Require valid content require(bytes(_content).length > 0); // Increment the post count postCount ++; // Create the post posts[postCount] = Post(postCount, _content, 0, msg.sender); // Trigger event emit PostCreated(postCount, _content, 0, msg.sender); } function set(uint x) public { storeddata = x; } function get() public view returns(uint) { return storeddata; } function tipPost(uint _id) public payable { // Make sure the id is valid require(_id > 0 && _id <= postCount); // Fetch the post Post memory _post = posts[_id]; // Fetch the author address payable _author = _post.author; // Pay the author by sending them Ether address(_author).transfer(msg.value); // Incremet the tip amount _post.tipAmount = _post.tipAmount + msg.value; // Update the post posts[_id] = _post; // Trigger an event emit PostTipped(postCount, _post.content, _post.tipAmount, _author); } event Paused(address account); event Unpaused(address account); bool private _paused; constructor() { _paused = false; } modifier whenNotPaused() { _requireNotPaused(); _; } modifier whenPaused() { _requirePaused(); _; } function paused() public view virtual returns (bool) { return _paused; } function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } function normalThing() public { // anyone can call this normalThing() } function specialThing() public onlyOwner { // only the owner can call specialThing()! } }
0.4.18