Created
August 13, 2024 18:52
-
-
Save coderwithsense/c2ae22424c82af37cd4ead4af0e18ce8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.26+commit.8a97fa7a.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.20; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract ContactManager is Ownable { | |
constructor(address initialOwner) Ownable(initialOwner) {} | |
struct User { | |
address userAddress; | |
string[] hashes; | |
} | |
User[] public users; | |
mapping(address => uint) public userIndex; | |
function createUser() public { | |
users.push(User({ | |
userAddress: msg.sender, | |
hashes: new string[](0) | |
})); | |
userIndex[msg.sender] = users.length - 1; | |
} | |
function addUserHash(string memory _hash) public { | |
uint index = userIndex[msg.sender]; | |
users[index].hashes.push(_hash); | |
} | |
function removeUserHash(uint _index) public { | |
uint userIndex_ = userIndex[msg.sender]; | |
User storage user = users[userIndex_]; | |
user.hashes[_index] = user.hashes[user.hashes.length - 1]; | |
user.hashes.pop(); | |
} | |
function getUserHashes() public view returns (string[] memory) { | |
uint index = userIndex[msg.sender]; | |
return users[index].hashes; | |
} | |
function removeUser() public { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment