Add string and bytes support to the StorageSlots library (#4008)
Co-authored-by: Francisco <frangio.1@gmail.com>
This commit is contained in:
@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
|
||||
import "../utils/StorageSlot.sol";
|
||||
|
||||
contract StorageSlotMock {
|
||||
using StorageSlot for bytes32;
|
||||
using StorageSlot for *;
|
||||
|
||||
function setBoolean(bytes32 slot, bool value) public {
|
||||
slot.getBooleanSlot().value = value;
|
||||
@ -38,4 +38,40 @@ contract StorageSlotMock {
|
||||
function getUint256(bytes32 slot) public view returns (uint256) {
|
||||
return slot.getUint256Slot().value;
|
||||
}
|
||||
|
||||
mapping(uint256 => string) public stringMap;
|
||||
|
||||
function setString(bytes32 slot, string calldata value) public {
|
||||
slot.getStringSlot().value = value;
|
||||
}
|
||||
|
||||
function setStringStorage(uint256 key, string calldata value) public {
|
||||
stringMap[key].getStringSlot().value = value;
|
||||
}
|
||||
|
||||
function getString(bytes32 slot) public view returns (string memory) {
|
||||
return slot.getStringSlot().value;
|
||||
}
|
||||
|
||||
function getStringStorage(uint256 key) public view returns (string memory) {
|
||||
return stringMap[key].getStringSlot().value;
|
||||
}
|
||||
|
||||
mapping(uint256 => bytes) public bytesMap;
|
||||
|
||||
function setBytes(bytes32 slot, bytes calldata value) public {
|
||||
slot.getBytesSlot().value = value;
|
||||
}
|
||||
|
||||
function setBytesStorage(uint256 key, bytes calldata value) public {
|
||||
bytesMap[key].getBytesSlot().value = value;
|
||||
}
|
||||
|
||||
function getBytes(bytes32 slot) public view returns (bytes memory) {
|
||||
return slot.getBytesSlot().value;
|
||||
}
|
||||
|
||||
function getBytesStorage(uint256 key) public view returns (bytes memory) {
|
||||
return bytesMap[key].getBytesSlot().value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user