Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@madvas
Created October 3, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madvas/d17e69e07d84437742e69a79c7bf96fc to your computer and use it in GitHub Desktop.
Save madvas/d17e69e07d84437742e69a79c7bf96fc to your computer and use it in GitHub Desktop.
Solidity SimpleTwitter
pragma solidity ^0.4.1;
import "strings.sol";
contract SimpleTwitter {
using strings for *;
address public developer;
uint16 public maxTweetLength;
uint16 public maxNameLength;
struct Tweet {
address authorAddress;
string name;
string text;
uint date;
}
Tweet[] public tweets;
event onTweetAdded(address authorAddress, string name, string text, uint date, uint tweetKey);
modifier onlyDeveloper() {
if (msg.sender != developer) throw;
_;
}
function SimpleTwitter() {
maxTweetLength = 140;
maxNameLength = 20;
developer = msg.sender;
}
function addTweet(string name, string text) {
if (name.toSlice().len() > maxNameLength) throw;
if (text.toSlice().len() > maxTweetLength) throw;
tweets.push(Tweet(msg.sender, name, text, now));
onTweetAdded(msg.sender, name, text, now, tweets.length - 1);
}
function getSettings() constant returns(uint16, uint16) {
return (maxNameLength, maxTweetLength);
}
function setSettings(uint16 _maxNameLength, uint16 _maxTweetLength) onlyDeveloper {
maxNameLength = _maxNameLength;
maxTweetLength = _maxTweetLength;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment