-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15-Twitter-Require-Exercise.sol
43 lines (31 loc) · 1014 Bytes
/
15-Twitter-Require-Exercise.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// 1️⃣ Use require to limit the length of the tweet to be only 280 characters
// HINT: use bytes to length of tweet
contract Twitter {
struct Tweet {
address author;
string content;
uint256 timestamp;
uint256 likes;
}
// add our code
mapping(address => Tweet[] ) public tweets;
function createTweet(string memory _tweet) public {
// conditional
// if tweet length <= 280 then we are good, otherwise we revert
Tweet memory newTweet = Tweet({
author: msg.sender,
content: _tweet,
timestamp: block.timestamp,
likes: 0
});
tweets[msg.sender].push(newTweet);
}
function getTweet( uint _i) public view returns (Tweet memory) {
return tweets[msg.sender][_i];
}
function getAllTweets(address _owner) public view returns (Tweet[] memory ){
return tweets[_owner];
}
}