Skip to content

Instantly share code, notes, and snippets.

@wemeetagain
Last active May 6, 2019 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wemeetagain/9382663 to your computer and use it in GitHub Desktop.
Save wemeetagain/9382663 to your computer and use it in GitHub Desktop.
// contract 1
// 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 transaction fee isn't enough to run the contract, stop
if tx.value < 100 * block.basefee:
stop
// 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
// contract 2
// address -> contract address
// [contractAddress] -- contractAddress is the address of the contract to link to
// if the transaction fee isn't enough to run the contract, stop
if tx.value < 100 * block.basefee:
stop
contract.storage[tx.sender] = tx.data[0]
//contract 3
// ID contract
// store id info
// two commands: add value at index, suicide contract
// [0,index, value] insert value at storage[1000+index]
// [1] suicide
// note: set contractcreator when creating contract
// if the transaction fee isn't enough to cover the contract, stop
if tx.value < 100 * block.basefee:
stop
// if the sender doesn't own this contract, stop
if tx.sender != CONTRACTCREATOR:
stop
if tx.data[0] == 0:
contract.storage[1000+tx.value[1]] = tx.value[2]
elif tx.data[0] == 1:
suicide(CONTRACTCREATOR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment