-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstorage-exercise.sol
More file actions
66 lines (54 loc) · 1.8 KB
/
storage-exercise.sol
File metadata and controls
66 lines (54 loc) · 1.8 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
https://docs.base.org/base-camp/docs/storage/storage-exercise/
DEPLY STRING: 1000,"Pat",50000,112358132134
CODE:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract EmployeeStorage {
error TooManyShares(uint _updatedShares);
uint16 private shares; // 2 bytes
uint24 private salary; // 3 bytes
uint256 public idNumber; // 32 bytes
string public name; // dynamically sized
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;
}
/**
* Do not modify this function. It is used to enable the unit test for this pin
* to check whether or not you have configured your storage variables to make
* use of packing.
*
* If you wish to cheat, simply modify this function to always return `0`
* I'm not your boss ¯\_(ツ)_/¯
*
* Fair warning though, if you do cheat, it will be on the blockchain having been
* deployed by you wallet....FOREVER!
*/
function checkForPacking(uint _slot) public view returns (uint r) {
assembly {
r := sload (_slot)
}
}
/**
* Warning: Anyone can use this function at any time!
*/
function debugResetShares() public {
shares = 1000;
}
}