Last active
December 8, 2017 10:55
-
-
Save axic/e34c8781cee4fcd7603e3a4dc96d028e 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.19; | |
pragma experimental ABIEncoderV2; | |
contract ShenzhenKitties { | |
event Registered(string name, address owner); | |
event Transferred(string name, address from, address to); | |
mapping (bytes32 => address) kitties; | |
string[] public kittieNames; | |
function ShenzhenKitties() public { | |
registerInternal("test", 0x1234); | |
} | |
function registerInternal(string name, address owner) internal { | |
bytes32 key = keccak256(name); | |
require(kitties[key] == 0); | |
kitties[key] = owner; | |
kittieNames.push(name); | |
Registered(name, owner); | |
} | |
function registerKittie(string name) external { | |
registerInternal(name, msg.sender); | |
} | |
function transferKittie(address to, string name) external { | |
bytes32 key = keccak256(name); | |
require(msg.sender == kitties[key]); | |
kitties[key] = to; | |
Transferred(name, msg.sender, to); | |
} | |
function kittieOwner(string name) external view returns (address) { | |
bytes32 key = keccak256(name); | |
return kitties[key]; | |
} | |
function getKittieNames() external view returns (string[]) { | |
return kittieNames; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment