Skip to content

Instantly share code, notes, and snippets.

@d11e9
Created November 20, 2015 17:00
Show Gist options
  • Save d11e9/29b3d154f7e2ff31966f to your computer and use it in GitHub Desktop.
Save d11e9/29b3d154f7e2ff31966f to your computer and use it in GitHub Desktop.
import "owned";
contract Archive is owned {
struct Content {
bool exists;
address OP;
bytes32[] archives;
}
uint public price;
mapping(bytes32 => Content) public contents;
event Post(bytes32 rootHash, bytes32 contentHash);
modifier costs { if (msg.value >= price) _ }
function archive( bytes32 rootContentHash, bytes32 archive, address OP, bool tip ) costs {
address archiver = msg.sender;
if (contents[rootContentHash].exists && archive != bytes32(0)) {
// append to archive
contents[rootContentHash].archives.length++;
contents[rootContentHash].archives[contents[rootContentHash].archives.length] = archive;
Post( rootContentHash, archive);
handleTip( tip, OP );
} else if (!contents[rootContentHash].exists) {
// first archival
bytes32[] memory tmp;
contents[rootContentHash] = Content( true, OP, tmp);
Post( rootContentHash, bytes32(0));
handleTip( tip, OP );
}
}
function handleTip (bool tip, address OP) internal {
if (tip && OP != address(0)) {
OP.send( price );
} else {
owner.send( price );
}
}
function changePrice(uint _price) onlyowner {
price = _price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment