2021-08-12 09:58:13 +00:00
// SPDX-License-Identifier: AGPL-3.0
2021-06-10 05:52:03 +00:00
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 ;
2021-06-14 10:53:41 +00:00
mapping ( address => mapping ( address => mapping ( uint24 => address ) ) ) public doubleNestedAddressMap ;
2021-06-10 05:52:03 +00:00
// 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 ;
}
2021-06-14 10:53:41 +00:00
// Set variable doubleNestedAddressMap.
function setDoubleNestedAddressMap ( address key , address nestedKey , uint24 doubleNestedKey , address value ) external {
doubleNestedAddressMap [ key ] [ nestedKey ] [ doubleNestedKey ] = value ;
}
2021-06-10 05:52:03 +00:00
}