深入mapping

- 1 min

image

数据存在了keccake256(key.(v的插槽)), 这个算出来的数字是16进制的, 我们把他转换成十进制, 就是slot的位置(最大2^256).

image

和其他类型一样, 使用public, 自动生成mapping getter

找到具体的slot地址

function findMapLocation(uint256 slot, uint256 key) public pure returns (uint256) {
    return uint256(keccak256(abi.encode(key, slot)));
}

mapping作为函数传参