40 lines
1.0 KiB
Solidity
40 lines
1.0 KiB
Solidity
// SPDX-License-Identifier: Apache 2.0
|
|
pragma solidity 0.8.19;
|
|
contract TestSlot {
|
|
// 0
|
|
uint public count = 123;
|
|
// 1.1
|
|
address public owner = msg.sender;
|
|
// 1.2
|
|
bool public isTrue = true;
|
|
// 1.3
|
|
uint16 public u16 = 31;
|
|
// 2
|
|
bytes32 private password;
|
|
uint public constant someConst = 123;
|
|
// 3, 4, 5
|
|
bytes32[3] public data;
|
|
struct User {
|
|
uint id;
|
|
bytes32 password;
|
|
}
|
|
// 6: length of users
|
|
User[] private users;
|
|
// 7: empty,
|
|
mapping(uint => User) private idToUser;
|
|
constructor(bytes32 _password) {
|
|
password = _password;
|
|
}
|
|
function addUser(bytes32 _password) public {
|
|
User memory user = User({id: users.length, password: _password});
|
|
users.push(user);
|
|
idToUser[user.id] = user;
|
|
}
|
|
function getArrayLocation(uint slot, uint index, uint elementSize) public pure returns (uint) {
|
|
return uint(keccak256(abi.encodePacked(slot))) + (index * elementSize);
|
|
}
|
|
function getMapLocation(uint slot, uint key) public pure returns (uint) {
|
|
return uint(keccak256(abi.encodePacked(key, slot)));
|
|
}
|
|
}
|