-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAddressBook.sol
More file actions
48 lines (32 loc) · 1.32 KB
/
AddressBook.sol
File metadata and controls
48 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract AddressBook {
mapping(address => string[]) private addressAliases;
mapping(address => string[]) private addressContacts;
function addContact(string memory addressalias, string memory contact) public {
addressAliases[msg.sender].push(addressalias);
addressContacts[msg.sender].push(contact);
}
function getContacts() public view returns (string[] memory) {
return addressContacts[msg.sender];
}
function getAliases() public view returns (string[] memory) {
return addressAliases[msg.sender];
}
function removeContact(string memory contact) public {
for (uint256 i = 0; i < addressContacts[msg.sender].length; i++) {
if (keccak256(bytes(addressContacts[msg.sender][i])) == keccak256(bytes(contact))) {
delete addressContacts[msg.sender][i];
break;
}
}
}
function removeAlias(string memory addressalias) public {
for (uint256 i = 0; i < addressAliases[msg.sender].length; i++) {
if (keccak256(bytes(addressAliases[msg.sender][i])) == keccak256(bytes(addressalias))) {
delete addressAliases[msg.sender][i];
break;
}
}
}
}