-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path2. Own a(n) Storage Pin NFT
More file actions
46 lines (38 loc) · 1.18 KB
/
Copy path2. Own a(n) Storage Pin NFT
File metadata and controls
46 lines (38 loc) · 1.18 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract EmployeeStorage {
error TooManyShares(uint _updatedShares);
// Packing tối ưu: shares (2 bytes) + salary (3 bytes) trong slot 0
uint16 private shares;
uint24 private salary;
uint256 public idNumber;
string public name;
constructor(uint16 _shares, string memory _name, uint24 _salary, uint256 _idNumber) {
shares = _shares;
name = _name;
salary = _salary;
idNumber = _idNumber;
}
function viewSalary() external view returns (uint24) {
return salary;
}
function viewShares() external view returns (uint16) {
return shares;
}
function grantShares(uint16 _newShares) external {
require(_newShares < 5001, "Too many shares");
uint16 _updatedShares = shares + _newShares;
if (_updatedShares > 5000) {
revert TooManyShares(_updatedShares);
}
shares = _updatedShares;
}
function checkForPacking(uint _slot) public view returns (uint r) {
assembly {
r := sload(_slot)
}
}
function debugResetShares() public {
shares = 1000;
}
}