Created
August 13, 2019 16:37
-
-
Save hazae41/f2acdc820a867a93dfc6a50d40bf4437 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.5.11+commit.c082d0b4.js&optimize=false&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
| pragma solidity ^0.5.5; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of "user permissions". | |
| */ | |
| contract Ownable { | |
| address payable private _owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor() internal { | |
| _owner = msg.sender; | |
| emit OwnershipTransferred(address(0), _owner); | |
| } | |
| /** | |
| * @return the address of the owner. | |
| */ | |
| function owner() public view returns(address payable) { | |
| return _owner; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(isOwner()); | |
| _; | |
| } | |
| /** | |
| * @return true if `msg.sender` is the owner of the contract. | |
| */ | |
| function isOwner() public view returns(bool) { | |
| return msg.sender == _owner; | |
| } | |
| /** | |
| * @dev Allows the current owner to relinquish control of the contract. | |
| * @notice Renouncing to ownership will leave the contract without an owner. | |
| * It will not be possible to call the functions with the `onlyOwner` | |
| * modifier anymore. | |
| */ | |
| function renounceOwnership() public onlyOwner { | |
| emit OwnershipTransferred(_owner, address(0)); | |
| _owner = address(0); | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address payable newOwner) public onlyOwner { | |
| _transferOwnership(newOwner); | |
| } | |
| /** | |
| * @dev Transfers control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function _transferOwnership(address payable newOwner) internal { | |
| require(newOwner != address(0)); | |
| emit OwnershipTransferred(_owner, newOwner); | |
| _owner = newOwner; | |
| } | |
| } |
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
| pragma solidity ^0.5.5; | |
| import "./ownable.sol"; | |
| contract Payable is Ownable { | |
| function balance() public view returns(uint){ | |
| return address(this).balance; | |
| } | |
| function withdraw(uint _amount) public onlyOwner { | |
| require(_amount <= address(this).balance); | |
| owner().transfer(_amount); | |
| } | |
| function withdrawAll() public onlyOwner { | |
| withdraw(address(this).balance); | |
| } | |
| function kill() public onlyOwner { | |
| selfdestruct(owner()); | |
| } | |
| } |
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
| pragma solidity >=0.4.22 <0.6.0; | |
| import "./payable.sol"; | |
| contract Utils { | |
| function toString(address addr) public pure returns (string memory) { | |
| bytes memory b = new bytes(20); | |
| for (uint i = 0; i < 20; i++) { | |
| b[i] = byte(uint8(uint(addr) / (2**(8*(19 - i))))); | |
| } | |
| return string(b); | |
| } | |
| function with(string memory str, address addr) internal pure returns (string memory){ | |
| return string(abi.encodePacked(str, "/", toString(addr))); | |
| } | |
| } | |
| contract Latests { | |
| struct Topic { | |
| string addr; | |
| address receiver; | |
| } | |
| Topic[] public latests; | |
| function getLatestsLength() public view returns (uint) { | |
| return latests.length; | |
| } | |
| function getLatest(uint index) public view returns (string memory, address){ | |
| Topic memory topic = latests[index]; | |
| return (topic.addr, topic.receiver); | |
| } | |
| } | |
| contract Counts is Utils { | |
| mapping(string => uint) public counts; | |
| function getCount(string memory hash, address receiver) public view returns (uint) { | |
| return counts[with(hash, receiver)]; | |
| } | |
| } | |
| contract Values is Utils { | |
| mapping(string => uint) public values; | |
| function getValue(string memory hash, address receiver) public view returns (uint) { | |
| return values[with(hash, receiver)]; | |
| } | |
| } | |
| contract Percent is Ownable { | |
| uint public percent = 10; | |
| function setPercent(uint value) public onlyOwner { | |
| percent = value; | |
| } | |
| } | |
| contract Tipping is Payable, Latests, Counts, Values, Percent { | |
| function tip(string memory topic, string memory hash, address payable receiver) public payable { | |
| require(msg.sender != receiver); | |
| require(msg.value >= 1 finney); | |
| string memory post = with(hash, receiver); | |
| counts[post] += 1; | |
| values[post] += msg.value; | |
| latests.push(Topic(topic, receiver)); | |
| uint fee = msg.value / percent; | |
| receiver.transfer(msg.value - fee); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment