forked from maran/notareth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.sol
81 lines (67 loc) · 2.26 KB
/
contract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
contract Etherdoc {
address owner;
function Etherdoc(){
owner = msg.sender;
}
// In case you sent funds by accident
function empty(){
uint256 balance = address(this).balance;
address(owner).send(balance);
}
function newDocument(bytes32 hash) returns (bool success){
if (documentExists(hash)) {
success = false;
}else{
createHistory(hash, msg.sender, msg.sender);
usedHashes[hash] = true;
success = true;
}
return success;
}
function createHistory (bytes32 hash, address from, address to) internal{
++latestDocument;
documentHashMap[hash] = to;
usedHashes[hash] = true;
history[latestDocument] = DocumentTransfer(block.number, hash, from, to);
DocumentEvent(block.number, hash, from,to);
}
function transferDocument(bytes32 hash, address recipient) returns (bool success){
success = false;
if (documentExists(hash)){
if (documentHashMap[hash] == msg.sender){
createHistory(hash, msg.sender, recipient);
success = true;
}
}
return success;
}
function documentExists(bytes32 hash) constant returns (bool exists){
if (usedHashes[hash]) {
exists = true;
}else{
exists= false;
}
return exists;
}
function getDocument(uint docId) constant returns (uint blockNumber, bytes32 hash, address from, address to){
DocumentTransfer doc = history[docId];
blockNumber = doc.blockNumber;
hash = doc.hash;
from = doc.from;
to = doc.to;
}
event DocumentEvent(uint blockNumber, bytes32 indexed hash, address indexed from, address indexed to);
struct DocumentTransfer {
uint blockNumber;
bytes32 hash;
address from;
address to;
}
function getLatest() constant returns (uint latest){
return latestDocument;
}
uint latestDocument;
mapping(uint => DocumentTransfer) public history;
mapping(bytes32 => bool) public usedHashes;
mapping(bytes32 => address) public documentHashMap;
}