-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartContract.sol
55 lines (41 loc) · 1.41 KB
/
SmartContract.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
pragma solidity ^0.4.23;
// Document Timestamping & Recording Smart Contract by Pavon Dunbar
// Begin Smart Contract
contract DocumentTimestamp{
address owner;
struct Document{
bool stored;
uint blockNumber;
uint blockTimestamp;
address sender;
}
mapping(bytes32 => Document) internal documents;
event DocumentEvent(uint blockNumber, bytes32 hash);
function DocumentTimestamp() public{
owner = msg.sender;
}
// In case you send funds by accident
function empty() public{
owner.transfer(this.balance);
}
function addDocument(bytes32 hash) internal{
documents[hash].stored = true;
documents[hash].blockNumber = block.number;
documents[hash].blockTimestamp = block.timestamp;
documents[hash].sender = msg.sender;
}
function newDocument(bytes32 hash) external returns(bool success){
if(documents[hash].stored){
success = false;
}else{
addDocument(hash);
emit DocumentEvent(documents[hash].blockNumber, hash);
success = true;
}
return success;
}
function getDocument(bytes32 hash) external view returns(uint blockNumber, uint blockTimestamp, address sender){
require(documents[hash].stored);
return(documents[hash].blockNumber, documents[hash].blockTimestamp, documents[hash].sender);
}
}