Skip to content

Instantly share code, notes, and snippets.

@d11e9
Last active September 17, 2015 13:42
Show Gist options
  • Save d11e9/ceb0137cf0ad9acb9c64 to your computer and use it in GitHub Desktop.
Save d11e9/ceb0137cf0ad9acb9c64 to your computer and use it in GitHub Desktop.
DAppList
contract owned {
address owner;
function owned() { owner = msg.sender; }
function transfer(address to) onlyowner returns (bool success){
owner = to;
return true;
}
function isOwner (address addr) returns(bool) {
return addr == owner;
}
modifier onlyowner { if (msg.sender == owner) _ }
}
contract mortal is owned {
function kill() onlyowner { suicide(owner); }
}
contract keyvalue is owned {
mapping (bytes32 => string) public keys;
function set(bytes32 key, string value) onlyowner {
keys[key] = value;
}
}
contract DAppListing is mortal, keyvalue {
string public jsonPropertiesHash;
function setJsonHash( string hash ) {
jsonPropertiesHash = hash;
}
}
// DApp listing recommended/standard keys
// name: dapp name
// contracts: [[address, abiHash], ...]
// url: legacy-web-url or ipfsHash of dapp index.html
// Extra keys (Optional)
// description: ipfsHash
// tags: [keyword, ...]
// icon: ipfsHash
// status: "project status"
// maintainers: [address, ...]
// donations: address
// licence: "MIT" etc
contract LinkedListAddressAddress is owned, mortal {
struct Item {
address prev;
address next;
address value;
}
address public head;
address public tail;
uint public length;
mapping( address => Item) public items;
modifier exist (address id, bool flag) { if ((items[id].value != address(0) ) == flag) _ }
function LinkedListAddressAddress(){
head = address(0);
tail = address(0);
length = 0;
}
function add (address addr, address value) exist(addr, false) onlyowner {
address prev = head;
items[prev].next = addr;
items[addr] = Item( prev, address(0), value );
head = addr;
length++;
if (tail == address(0)) { tail = addr; }
}
function remove(address addr) exist(addr, true) onlyowner {
if (head == addr) {
head = items[addr].prev;
}
if (tail == addr) {
tail = items[addr].next;
}
if (items[addr].prev != address(0)) {
items[items[addr].prev].next = items[addr].next;
}
if (items[addr].next != address(0)) {
items[items[addr].next].prev = items[addr].prev;
}
length--;
delete items[addr];
}
}
contract DAppList is LinkedListAddressAddress {
function createListing() returns (address contractAddress) {
DAppListing dapp = new DAppListing();
dapp.transfer( msg.sender );
add( address(dapp), msg.sender);
return address(dapp);
}
function registerExistingListing (address addr) {
add(addr, msg.sender);
}
function removeListing(address addr) returns (bool success) {
if (items[addr].value == msg.sender) {
remove(addr);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment