mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-09 01:04:07 +00:00
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:
co-authored by
nikugogoi
parent
84e1927402
commit
fc44617db3
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user