mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-25 04:20:33 +00:00
42 lines
1.7 KiB
Solidity
42 lines
1.7 KiB
Solidity
|
// SPDX-License-Identifier: MIT
|
||
|
pragma solidity ^0.7.0;
|
||
|
|
||
|
contract TestNestedMapping {
|
||
|
// Mapping type variable occupies one single slot but the actual elements are stored at a different storage slot that is computed using a Keccak-256 hash.
|
||
|
// https://docs.soliditylang.org/en/v0.8.4/internals/layout_in_storage.html#mappings-and-dynamic-arrays
|
||
|
mapping (address => mapping (address => uint)) private nestedAddressUintMap;
|
||
|
|
||
|
mapping (int => mapping (address => bool)) private intAddressBoolMap;
|
||
|
|
||
|
mapping (uint => mapping (string => int)) private uintStringIntMap;
|
||
|
|
||
|
mapping (bytes => mapping (int => address)) private bytesIntAddressMap;
|
||
|
|
||
|
mapping (string => mapping (address => int)) private stringAddressIntMap;
|
||
|
|
||
|
// Set variable nestedAddressUintMap.
|
||
|
function setNestedAddressUintMap(address nestedKey, uint value) external {
|
||
|
nestedAddressUintMap[msg.sender][nestedKey] = value;
|
||
|
}
|
||
|
|
||
|
// Set variable intAddressBoolMap.
|
||
|
function setIntAddressBoolMap(int key, address nestedKey, bool value) external {
|
||
|
intAddressBoolMap[key][nestedKey] = value;
|
||
|
}
|
||
|
|
||
|
// Set variable uintStringIntMap.
|
||
|
function setUintStringIntMap(uint key, string calldata nestedKey, int value) external {
|
||
|
uintStringIntMap[key][nestedKey] = value;
|
||
|
}
|
||
|
|
||
|
// Set variable bytesIntAddressMap.
|
||
|
function setBytesIntAddressMap(bytes calldata key, int nestedKey, address value) external {
|
||
|
bytesIntAddressMap[key][nestedKey] = value;
|
||
|
}
|
||
|
|
||
|
// Set variable stringAddressIntMap.
|
||
|
function setStringAddressIntMap(string calldata key, address nestedKey, int value) external {
|
||
|
stringAddressIntMap[key][nestedKey] = value;
|
||
|
}
|
||
|
}
|