Code
solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Registry {
struct User {
address wallet;
uint256 balance;
bool active;
string displayName;
}
// mapping: key -> value (no iteration, no length)
mapping(address => User) public users;
mapping(address => mapping(uint256 => bool)) public approvals; // nested
address[] public userIndex; // for iteration
function register(string calldata name) external {
require(!users[msg.sender].active, "already registered");
users[msg.sender] = User({
wallet: msg.sender,
balance: 0,
active: true,
displayName: name
});
userIndex.push(msg.sender);
}
function approve(uint256 id) external {
approvals[msg.sender][id] = true;
}
function count() external view returns (uint256) {
return userIndex.length;
}
}