Skip to content

Instantly share code, notes, and snippets.

@3esmit
Created February 9, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3esmit/4634e89eb5758e018b152812fa11e054 to your computer and use it in GitHub Desktop.
Save 3esmit/4634e89eb5758e018b152812fa11e054 to your computer and use it in GitHub Desktop.
Contract used to register hashes of files to proof the original authoring of them.
pragma solidity ^0.4.0;
/*
Proof of authoring
Contract used to register hashes of files to proof the original authoring of them.
Owner can transfer the ownership.
Contract accept donation to documents registereds.
Written by Ricardo Guilherme Schmidt <3esmit@gmail.com>
*/
contract ProofOfAuthoring {
event DocumentRegister(address _owner, bytes32 _hash, uint _time);
event Transfer(bytes32 _hash, address _newOwner);
event Donate(bytes32 _hash, address _donator, uint _value);
struct Document{
address owner;
uint time;
}
modifier only_owner (bytes32 _hash){
if(documents[_hash].owner != msg.sender) throw;
_;
}
modifier owned (bytes32 _hash){
if(documents[_hash].owner == 0x0) throw;
_;
}
modifier not_owned (bytes32 _hash){
if(documents[_hash].owner != 0x0) throw;
_;
}
mapping(bytes32 => Document) public documents;
function () {
throw;
}
function registerDocument(bytes32 _hash) not_owned(_hash){
registerDocumentTo(msg.sender, _hash);
}
function registerDocumentTo(address _owner, bytes32 _hash) not_owned(_hash){
documents[_hash] = Document({owner: _owner, time: block.timestamp});
DocumentRegister(_owner, _hash, block.timestamp);
}
function transfer(bytes32 _hash, address _newOwner) only_owner(_hash){
documents[_hash].owner = _newOwner;
Transfer(_hash,_newOwner);
}
function donate(bytes32 _hash) payable owned(_hash){
if(documents[_hash].owner.send(msg.value))
Donate(_hash,msg.sender,msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment