refer to: kimi,
https://ethereum.stackexchange.com/questions/42272/is-it-possible-to-assign-a-map-as-a-mappings-value
三重mapping的例子:
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.13; contract TripleNestedMapping { // 这样声明 mapping(string => mapping(uint256 => mapping (uint256 => bool) )) users_and_passwords; function setLogin(string calldata _name, uint256 _password, uint256 _pin) public {
// 注意不能这样弄。因为 无法在function中创建动态的mapping //mapping(uint256 => mapping(uint256 => bool) ) memory pins ; //mapping(uint256 => bool) memory isCanLogin; //isCanLogin[_pin] = true; //pins[_password] = isCanLogin; //users_and_passwords[_name] = pins;
// 只能这样弄。因为调用的是 contract 的member users_and_passwords[_name][_password][_pin] = true; } function isLoggedIn(string calldata _name, uint256 _password, uint256 _pin) public view returns (bool) { return users_and_passwords[_name][_password][_pin]; } }