Skip to content

Instantly share code, notes, and snippets.

@ghiliweld
Last active March 22, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghiliweld/847ccac471008d14a6815c6df252a6b4 to your computer and use it in GitHub Desktop.
Save ghiliweld/847ccac471008d14a6815c6df252a6b4 to your computer and use it in GitHub Desktop.
Address Handle Service
pragma solidity ^0.4.19;
/*
@title Address Handle Service aka AHS
@author Ghilia Weldesselasie, founder of D-OZ and genius extraordinaire
@twitter: @ghiliweld, my DMs are open so slide through if you trynna chat ;)
This is a simple alternative to ENS I made cause ENS was too complicated
for me to understand which seemed odd since it should be simple in my opinion.
Please donate if you like it, all the proceeds go towards funding D-OZ, my project.
*/
contract AHS {
address public owner;
mapping (bytes32 => address) public handleToAddresses;
mapping (bytes32 => bool) public handleRegistred;
mapping (address => mapping (bytes32 => bool)) public ownsHandle;
event HandleRegistered(string _handle, address indexed _address);
event HandleTransfered(string _handle, address indexed _to);
function AHS(string _handle) public {
owner = msg.sender;
registerHandle(_handle);
}
function registerHandle(string _handle) public payable {
require(handleRegistred[keccak256(_handle)] == false);
handleToAddresses[keccak256(_handle)] = msg.sender;
handleRegistred[keccak256(_handle)] = true;
ownsHandle[msg.sender][keccak256(_handle)] = true;
HandleRegistered(_handle, msg.sender);
}
function registerFor(string _handle, address _addr) public payable {
require(handleRegistred[keccak256(_handle)] == false);
handleToAddresses[keccak256(_handle)] = _addr;
handleRegistred[keccak256(_handle)] = true;
ownsHandle[msg.sender][keccak256(_handle)] = true;
HandleRegistered(_handle, msg.sender);
}
function transferHandle(string _handle, address _newAddress) public {
require(handleRegistred[keccak256(_handle)]);
require(_newAddress != address(0));
require(ownsHandle[msg.sender][keccak256(_handle)]);
handleToAddresses[keccak256(_handle)] = _newAddress;
HandleTransfered(_handle, msg.sender);
}
// This function is SUPER risky
// Only share ownership of your handle to a contract you trust 100%
function shareOwnership(string _handle, address _contract) public {
require(_contract != address(0));
require(ownsHandle[msg.sender][keccak256(_handle)]);
ownsHandle[_contract][keccak256(_handle)] = true;
}
function relinquishOwnership(string _handle) public {
require(ownsHandle[msg.sender][keccak256(_handle)]);
ownsHandle[msg.sender][keccak256(_handle)] = false;
}
function pay(string _handle) public payable {
require(handleRegistred[keccak256(_handle)]);
require(msg.value >= 0);
address to = handleToAddresses[keccak256(_handle)];
to.transfer(msg.value);
}
function withdraw() public {
require(msg.sender == owner);
owner.transfer(address(this).balance);
}
function findAddress(string _handle) public view returns(address) {
return handleToAddresses[keccak256(_handle)];
}
function isRegistered(string _handle) public view returns(bool) {
return handleRegistred[keccak256(_handle)];
}
function doesOwn(string _handle, address _addr) public view returns(bool) {
return ownsHandle[_addr][keccak256(_handle)];
}
}
@ghiliweld
Copy link
Author

You can register a handle for your own wallet or any other wallet, you can also transfer a handle to a wallet you own. There is no way to transfer a handle to a wallet you don't own and get a payment back trustlessly.

@gskapka
Copy link

gskapka commented Mar 22, 2018

The ENS allows for fair purchasing and selling of domain names via auction, whereas your contract allows people to simply buy a name and be done with it. The ENS also maintains funds in escrow, unlike this contract, which allows you to take all the funds whenever you please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment