-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW3day4.sol
More file actions
87 lines (68 loc) · 2.48 KB
/
W3day4.sol
File metadata and controls
87 lines (68 loc) · 2.48 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
//Contract from chatgpt example
/*contract EventExample {
mapping(address => uint256) public balances;
event Deposit(address indexed user, uint256 amount);
event Withdraw(address indexed user, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 amount);
function deposit() public payable {
require(msg.value > 0, "Send ETH");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Withdrawal not successful");
emit Withdraw(msg.sender, amount);
}
function transfer(address to, uint amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
balances[to] += amount;
emit Transfer(msg.sender, to, amount);
}
}*/
//Create events for:
//User registration
contract registration{
mapping(address => uint256) public balance;
mapping(address => bool) public isRegistered;
uint256 private id = 0;
string private username;
address public admin;
constructor() {
admin = msg.sender;
}
enum Role {
none,
admin,
member
}
mapping(address => Role) public roles;
event Register(address indexed user, uint256 indexed uid);
event Roole(address indexed user, Role roles);
event Balance(address indexed user, uint256 amount);
function RegisterNow(string memory _username) external {
require(!isRegistered[msg.sender], "Account already exist");
isRegistered[msg.sender] = true;
username = _username;
uint256 uid = id++;
emit Register(msg.sender, uid);
}
modifier OnlyAdmin(){
require(msg.sender == admin, "Not an admin");
_;
}
function ChangeRole(address _user, Role _roles) external OnlyAdmin {
roles[_user] = _roles;
emit Roole(_user, _roles);
}
function IncreaseBalance(address _user)public payable {
require(msg.value > 0, "Deposit something you piss of shite");
balance[_user] += msg.value;
emit Balance(_user, msg.value);
}
}