-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileStorage.sol
More file actions
55 lines (48 loc) · 1.5 KB
/
ProfileStorage.sol
File metadata and controls
55 lines (48 loc) · 1.5 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/// @title Profile Storage (Mini Project)
/// @author Rasheed
/// @notice Profile Onchain
/// @dev Stores profile details
contract ProfileStorage{
enum AccountStatus{
Unregistered,
Active,
Inactive
}
struct User{
string username;
uint256 age;
address wallet;
uint256 creationTime;
AccountStatus status;
uint256 balance;
}
mapping(address => User) stored;
function createProfile(string memory _username, uint256 _age) public {
require(stored[msg.sender].status == AccountStatus.Unregistered, "Account already exist!");
stored[msg.sender] = User({
username: _username,
age: _age,
wallet: msg.sender,
creationTime: block.timestamp,
status: AccountStatus.Active,
balance: msg.sender.balance
});
}
function suspendAcct(address _inactive) public{
require(stored[msg.sender].status == AccountStatus.Active, "Account is inactive");
stored[_inactive].status = AccountStatus.Inactive;
}
function getProfile(address _user) public view returns(string memory, uint256, address, uint256, AccountStatus, uint256){
User memory u = stored[_user];
return (
u.username,
u.age,
u.wallet,
u.creationTime,
u.status,
u.balance
);
}
}