Skip to content

Instantly share code, notes, and snippets.

@wemeetagain
Last active May 6, 2019 16:02
Show Gist options
  • Save wemeetagain/9457099 to your computer and use it in GitHub Desktop.
Save wemeetagain/9457099 to your computer and use it in GitHub Desktop.
topic-grouped lists of addresses with linked id contracts
// convenience nameserver
// name -> address
// address -> name
// [name, newOwnerAddress (optional)]
// only one name allowed per address
// newOwnerAddress will only be applicable if the name is already claimed
// if the name is invalid, stop
if tx.data[0] < 100:
stop
// if the name has already been claimed
if contract.storage[tx.data[0]]:
// if the sender isn't the current owner, stop
if contract.storage[tx.data[0]] != tx.sender:
stop
// if the newOwnerAddress is invalid, stop
if tx.data[1] < 100:
stop
// set new owner
contract.storage[tx.sender] = 0
contract.storage[tx.data[0]] = tx.data[1]
// the name has not been claimed
else:
//if the sending address already has a name, stop
if contract.storage[tx.sender]:
stop
// set name owner as sending address
contract.storage[tx.sender] = tx.data[0]
contract.storage[tx.data[0]] = tx.sender
// Topic list -> [addresses], address -> contract
// two commands: update contract address, update topic
// enforces:
// - one topic per address
// - one contract per address
// [0,contractAddress] - updates sender's contract address (0 for delete)
// [1, topic] - updates sender's topic
// update contract
if tx.data[0] == 0:
if tx.data[1] < 1000: // if the contractAddress isn't valid, stop
stop
contract.storage[tx.sender] = tx.data[1]
// update topic
if tx.data[0] == 1:
if tx.data[1] < 1000: // if the topic isn't valid, stop
stop
// if this address had an old topic, decrement that list
if contract.storage[tx.sender + 1]:
TOPICROOT = sha3(32,contract.storage[tx.sender+1])
LEN = contract.storage[TOPICROOT]
INDEX = contract.storage[tx.sender + 2]
// set swapped address to new index position and set address index
contract.storage[TOPICROOT+INDEX] = contract.storage[TOPICROOT+LEN]
contract.storage[contract.storage[TOPICROOT+INDEX] + 2] = INDEX
contract.storage[LEN] = 0
// decrement old topic length
contract.storage[sha3(32,contract.storage[tx.sender + 1])] = LEN - 1
TOPICROOT = sha3(32,tx.data[1])
LEN = contract.storage[TOPICROOT]
// add address to topic list and increment length
contract.storage[TOPICROOT+LEN+1] = tx.sender
contract.storage[TOPICROOT] = LEN + 1
// store topic and index in list for later lookup
contract.storage[tx.sender+1] = tx.data[1]
contract.storage[tx.sender+2] = LEN + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment