-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversioned_blob.sol
103 lines (84 loc) · 2.13 KB
/
versioned_blob.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
contract VersionedBlob {
struct Commit {
uint64 time;
address account;
string message;
bytes blob;
}
struct Tag {
uint32 commitId;
string tag;
}
address public owner;
address[] members;
Commit[] public commits;
Tag[] tags;
event CommitEvent(uint commitId, string message);
event TagEvent(uint indexed commitId, string indexed tag);
event UntagEvent(string indexed tag);
modifier isOwner {
if (msg.sender == owner) _
}
modifier isMember {
for (uint i = 0; i < members.length; i++) {
if (msg.sender == members[i]) _
}
}
function VersionedBlob() {
owner = msg.sender;
}
function setOwner(address newOwner) isOwner {
owner = newOwner;
}
function addMember(address member) isOwner {
members[members.length++] = member;
}
function removeMember(address member) isOwner {
for (uint i = 0; i < members.length; i++) {
if (member == members[i]) {
delete members[i];
}
}
}
function getMembers() isOwner constant returns (address[]) {
return members;
}
function commit(bytes blob, string message) isMember returns (uint commitId) {
commitId = commits.length++;
commits[commitId] = Commit(uint64(now), msg.sender, message, blob);
CommitEvent(commitId, message);
}
function checkOut(int i) constant returns (bytes) {
if (i == -1) {
i = int(commits.length) - 1;
}
return commits[uint(i)].blob;
}
function tag(uint commitId, string tag) {
tags[tags.length++] = Tag(uint32(commitId), tag);
TagEvent(commitId, tag);
}
function findTag(string tag) returns (int) {
bytes32 hash = sha3(tag);
for (uint i = 0; i < tags.length; i++) {
// Not possible to compare strings directly yet.
if (sha3(tags[i].tag) == hash) {
return int(i);
}
}
return -1;
}
function untag(string tag) {
int i = findTag(tag);
if (i != -1) {
delete tags[uint(i)];
UntagEvent(tag);
}
}
function checkOutTag(string tag) constant returns (bytes) {
int i = findTag(tag);
if (i != -1) {
return commits[tags[uint(i)].commitId].blob;
}
}
}