-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW3day2.sol
More file actions
75 lines (61 loc) · 1.93 KB
/
W3day2.sol
File metadata and controls
75 lines (61 loc) · 1.93 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract NormalMapping{
//Normal mapping
mapping(address => uint256) public balance;
function deposit(/*address _addr*/)public payable{
balance[msg.sender] += msg.value;
}
}
contract NestedMapping{
//mapping(keyType => mapping(key => Value)) public allowances;
struct DepositInfo {
uint256 amount;
uint256 timestamp;
}
mapping(address => mapping(uint256 => DepositInfo)) public deposits;
function deposit(uint256 id) public payable {
require(msg.value > 0, "Send ETH");
deposits[msg.sender][id].amount += msg.value;
deposits[msg.sender][id].timestamp = block.timestamp;
}
function getDeposit(address user, uint256 id) public view returns (uint256, uint256) {
DepositInfo memory info = deposits[user][id];
return (info.amount, info.timestamp);
}
}
contract UserItemOwnership{
struct Own {
bool own;
}
mapping(address => mapping(uint256 => Own)) public NFT;
function mint(uint256 _id)public payable returns(bool){
require(msg.value > 0, "Not enough holding");
return NFT[msg.sender][_id].own = true;
}
}
contract RoleUserPermission{
struct Role{
bool admin;
bool moderator;
bool member;
}
enum Permission{
notGrantor,
manage,
Grantor
}
Permission permissions;
mapping(address => mapping(Permission => Role)) public User;
function cpermission(Permission _permission) public{
if(_permission == Permission.notGrantor){
User[msg.sender][_permission].member = true;
}
else if (_permission == Permission.Grantor){
User[msg.sender][_permission].admin = true;
}
else{
User[msg.sender][_permission].moderator = true;
}
}
}