-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-Storage.sol
56 lines (45 loc) · 1.27 KB
/
3-Storage.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
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract EmployeeStorage {
error TooManyShares(uint totalShares);
uint16 private shares;
uint32 private salary;
uint256 public idNumber;
string public name;
constructor(
uint16 _shares,
uint32 _salary,
uint256 _idNumber,
string memory _name
) {
require(_shares <= 5000, "Too many shares");
require(_salary <= 1_000_000, "Salary exceeds limit");
shares = _shares;
salary = _salary;
idNumber = _idNumber;
name = _name;
}
function viewSalary() public view returns (uint32) {
return salary;
}
function viewShares() public view returns (uint16) {
return shares;
}
function grantShares(uint16 _newShares) public {
uint16 newTotalShares = shares + _newShares;
if (_newShares > 5000) {
revert("Too many shares");
} else if (newTotalShares > 5000) {
revert TooManyShares(newTotalShares);
}
shares = newTotalShares;
}
function checkForPacking(uint _slot) public view returns (uint r) {
assembly {
r := sload(_slot)
}
}
function debugResetShares() public {
shares = 1000;
}
}