Skip to content

Instantly share code, notes, and snippets.

@qualiabyte
Created September 9, 2014 07:57
Show Gist options
  • Save qualiabyte/b1e11789f3b540edc889 to your computer and use it in GitHub Desktop.
Save qualiabyte/b1e11789f3b540edc889 to your computer and use it in GitHub Desktop.
Ethereum Contracts
# NameReg
#
# API
#
# SERPENT
#
# # Register contract with name
# call(NAMEREG, [REGISTER, name], 2)
#
# # Get address by name
# call(NAMEREG, name)
#
# # Get name by address
# call(NAMEREG, address)
#
# # Unregister the calling address
# call(NAMEREG, UNREGISTER)
#
# # Kill the registry (creator only)
# call(NAMEREG, KILL)
#
# ALETH
#
# data: "register" <name> # Register name
# data: <name> # Get address by name
# data: <address> # Get name by address
# data: "unregister" # Unregister the caller
# data: "kill" # Kill registry
#
shared:
REGISTER = "register" * 2^(256 - 8*8)
UNREGISTER = "unregister" * 2^(256 - 10*8)
KILL = "kill" * 2^(256 - 4*8)
init:
CREATOR = msg.sender
contract.storage[0] = CREATOR
NAME = "NameReg!!" * 2^(256 - 9*8)
contract.storage[NAME] = contract.address
contract.storage[contract.address] = NAME
code:
caller = msg.sender
command = msg.data[0]
arg1 = msg.data[1]
if command == REGISTER:
name = arg1
if contract.storage[name]:
stop
else:
prevName = contract.storage[caller]
if prevName:
contract.storage[prevName] = 0
contract.storage[name] = caller
contract.storage[caller] = name
elif command == UNREGISTER:
name = contract.storage[caller]
if name == 0:
stop
else:
contract.storage[caller] = 0
contract.storage[name] = 0
elif command == KILL:
CREATOR = contract.storage[0]
if caller == CREATOR:
suicide(CREATOR)
else:
key = command
value = contract.storage[key]
return(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment