Last active
May 2, 2018 13:24
-
-
Save jaryl/359ffdd693b49b4a1cdf9ddc45285774 to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity ^0.4.23; | |
contract NameAddressTranslator { | |
mapping(bytes32 => address) nameRegistry; | |
mapping(address => string) addressRegistry; | |
function toName(address _address) public view returns (string) { | |
return addressRegistry[_address]; | |
} | |
function toAddress(string _name) public view returns (address) { | |
return nameRegistry[keccak256(_name)]; | |
} | |
function register(string _name) public { | |
bytes32 index = keccak256(_name); | |
require (nameRegistry[index] == address(0)); | |
require (bytes(_name).length != 0); | |
nameRegistry[index] = msg.sender; | |
if (bytes(addressRegistry[msg.sender]).length == 0) | |
addressRegistry[msg.sender] = _name; | |
} | |
function remap(string _name, address _address) public { | |
bytes32 index = keccak256(_name); | |
require (nameRegistry[index] == msg.sender); | |
nameRegistry[index] = _address; | |
addressRegistry[_address] = _name; | |
addressRegistry[msg.sender] = ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment