-
Notifications
You must be signed in to change notification settings - Fork 2
/
contract.sol
52 lines (40 loc) · 1.51 KB
/
contract.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
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract SpotifyClone {
function getBalance() external view returns (uint256) {
uint256 EthBalance = address(msg.sender).balance;
return EthBalance; }
address public admin;
uint256 public premiumAccessThreshold = 2;
struct User {
uint256 EthBalance;
bool hasPremiumAccess;
bool isSearching;
bool canSearchSong;
}
mapping(address => User) public users;
event PremiumAccessGranted(address indexed user);
event SongSearched(address indexed user);
modifier hasPremiumAccess() {
require(users[msg.sender].hasPremiumAccess, "Premium access required");
_;
}
modifier canSearchSong() {
require(users[msg.sender].isSearching || users[msg.sender].EthBalance >= premiumAccessThreshold, "Insufficient tokens");
_;
}
function setUserEthBalance(address user, uint256 balance) external {
users[msg.sender].EthBalance = balance;
if (balance >= premiumAccessThreshold && !users[msg.sender].hasPremiumAccess) {
users[msg.sender].hasPremiumAccess = true;
emit PremiumAccessGranted(user);
}
}
function searchSong() external {
uint256 balance = users[msg.sender].EthBalance;
if (balance >= 4 && users[msg.sender].hasPremiumAccess) {
users[msg.sender].canSearchSong = true;
emit SongSearched(msg.sender);
}
}
}