-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbvStringLedger.sol
More file actions
63 lines (51 loc) · 1.85 KB
/
Copy pathbvStringLedger.sol
File metadata and controls
63 lines (51 loc) · 1.85 KB
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
contract bvStringLedger {
address public voterRegistry; // Contract Address from which we believe vote-counts are true.
address public grandMaster; // Address allowed to change special positions.
int public ledgerHeight = 0; // A publically available height, then can explore from there.
function selfDestruct() { if (msg.sender == grandMaster) suicide(grandMaster); }
struct ledgerEntry {
uint128 id;
uint128 votes;
uint64 created;
uint64 creation_time;
string datastring;
}
struct ledgerIndex {
bytes32 entryString;
}
function bvStringLedger() {
grandMaster = msg.sender;
}
// Special position grandMaster changing it.
function setSiblings(address _voterRegistry,address _grandMaster) {
if( msg.sender == grandMaster ){ // Must be the current grandMaster.
voterRegistry = _voterRegistry;
grandMaster = _grandMaster;
}
}
// voterRegistry tells us it has votes.
function recordVotes(string dstr, uint128 voterSeconds) {
bytes32 bdstr = bytes32(sha3(dstr));
if( msg.sender == voterRegistry && byteStrings[bdstr].created != 0 ){
byteStrings[bdstr].votes += voterSeconds;
}
}
//Anyone can add a datastring.
function addString(string dstr) returns(uint64) {
bytes32 bdstr = bytes32(sha3(dstr));
ledgerEntry t = byteStrings[bdstr];
if( t.created !=0 ){
return 0;
}
t.votes = 0;
t.creation_time = uint64(block.timestamp);
t.datastring = dstr;
t.created = 1;
ledgerIndex i = lIndex[ledgerHeight];
i.entryString = bdstr;
ledgerHeight++;
return 1;
}
mapping (bytes32 => ledgerEntry) public byteStrings;
mapping (int => ledgerIndex) public lIndex;
}