Use solidity mapper to get value for mapping and nested mapping (balance and allowance) (#48)

* Implement getting value for basic mapping type.

* Add test for basic mapping type.

* Implement getting value for nested mapping type.

Co-authored-by: nikugogoi <95nikass@gmail.com>
This commit is contained in:
Ashwin Phatak
2021-06-09 10:18:19 +05:30
committed by GitHub
co-authored by nikugogoi
parent 84e1927402
commit fc44617db3
11 changed files with 2901 additions and 94 deletions
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract TestMappingTypes {
// 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 type variable occupies the next single slot.
mapping(address => uint) public addressUintMap;
// Set variable addressUintMap.
function setAddressUintMap(uint value) external {
addressUintMap[msg.sender] = value;
}
// Set variable nestedAddressUintMap.
function setNestedAddressUintMap(address addressValue, uint uintValue) external {
nestedAddressUintMap[msg.sender][addressValue] = uintValue;
}
}