Created
December 14, 2017 00:17
-
-
Save richardartoul/1534170fbd939df33147c9ca68687eaa to your computer and use it in GitHub Desktop.
SingleMessage Solidity Contract
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
contract SingleMessage is Ownable { | |
string public message; | |
uint256 public priceInWei; | |
uint256 public maxLength; | |
event MessageSet(string message, uint256 priceInWei, uint256 newPriceInWei, address payer); | |
function SingleMessage(string initialMessage, uint256 initialPriceInWei, uint256 maxLengthArg) public { | |
message = initialMessage; | |
priceInWei = initialPriceInWei; | |
maxLength = maxLengthArg; | |
} | |
function set(string newMessage) external payable { | |
require(msg.value >= priceInWei); | |
require(bytes(newMessage).length <= maxLength); | |
uint256 newPrice = priceInWei * 2; | |
MessageSet(newMessage, priceInWei, newPrice, msg.sender); | |
priceInWei = newPrice; | |
message = newMessage; | |
} | |
function withdraw(address destination, uint256 amountInWei) external onlyOwner { | |
require(this.balance >= amountInWei); | |
require(destination != address(0)); | |
destination.transfer(amountInWei); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment