Contract
Create a single contract calledEmployeeStorage. It should not inherit from any other contracts. It should have the following functions:
State Variables
The contract should have the following state variables, optimized to minimize storage:- A private variable
sharesstoring the employee’s number of shares owned- Employees with more than 5,000 shares count as directors and are stored in another contract
- Public variable
namewhich stores the employee’s name - A private variable
salarystoring the employee’s salary- Salaries range from 0 to 1,000,000 dollars
- A public variable
idNumberstoring the employee’s ID number- Employee numbers are not sequential, so this field should allow any number up to 2^256-1
Constructor
When deploying the contract, utilize theconstructor to set:
sharesnamesalaryidNumber
shares- 1000name- Patsalary- 50000idNumber- 112358132134
View Salary and View Shares
In the world of blockchain, nothing is ever secret!*
private variables prevent other contracts from reading the value. You should use them as a part of clean programming practices, but marking a variable as private does not hide the value. All data is trivially available to anyone who knows how to fetch data from the chain.*You can make clever use of encryption though!viewSalary that returns the value in salary.
Write a function called viewShares that returns the value in shares.
Grant Shares
Add a public function calledgrantShares that increases the number of shares allocated to an employee by _newShares. It should:
- Add the provided number of shares to the
shares- If this would result in more than 5000 shares, revert with a custom error called
TooManySharesthat returns the number of shares the employee would have with the new amount added - If the number of
_newSharesis greater than 5000, revert with a string message, “Too many shares”
- If this would result in more than 5000 shares, revert with a custom error called