-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewReddit.sol
37 lines (31 loc) · 1.33 KB
/
newReddit.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
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.13 and less than 0.9.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/utils/Strings.sol";
contract ethersTest {
struct linky {
uint totalBalance;
mapping (address => uint) stakerBalance;
}
mapping (string => linky) urlHolders;
function addToLink (string calldata link, string calldata optionalInput) public payable {
// if url does not exist
if (urlHolders[link].totalBalance == 0){
// if the code gets here, then the url is not found. Add the url and the msg.sender/msg.value
urlHolders[link].stakerBalance[msg.sender] = msg.value;
urlHolders[link].totalBalance = msg.value;
emit Deposit("New Link", msg.value, link);
}
else{
urlHolders[link].stakerBalance[msg.sender] += msg.value;
urlHolders[link].totalBalance += msg.value;
emit Deposit(optionalInput, urlHolders[link].totalBalance, link);
}
}
function withdraw(string calldata url) public payable{
// sends money back to person who staked
msg.sender.call{value: urlHolders[url].stakerBalance[msg.sender]}("");
}
//Declare an Event.
event Deposit(string testMessage, uint msgVal, string relevantUrl);
}