-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbitvote.se
More file actions
143 lines (120 loc) · 5.33 KB
/
Copy pathbitvote.se
File metadata and controls
143 lines (120 loc) · 5.33 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (C) 13-11-2014 Jasper den Ouden.
//
// This is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// TODO there is no name registry subscribing functionality.
// Actually, maybe votable 'actions'?
shared:
OnePerID = 0x00
OnePerIDSet = 0x20
TopicI = 0x40
Puppeteer = 0x60
// 224 == 32*7, it is a lot, in the future likely 32, and magnet/swarm/contract links.
TopicSz = 224
TopicStartI = 0x80
HALFWAY = 340282366920938463463374607431768211456
LARGE = 1152921504606846976
NAMEREG = 0x50441127ea5b9dfd835a9aba4e1dc9c1257b58ca
init:
contract.storage[OnePerID] = 0 // One per ID. (initially none)
contract.storage[OnePerIDSet] = msg.sender // One per ID setter. (should be contract)
contract.storage[TopicI] = TopicStartI
contract.storage[Puppeteer] = 0 // (should be contract)
args = ["register", "bitvote"] // Initial registering.(puppeteer may do other)
msg(tx.gas-100, NAMEREG, 0, args, 2)
code:
// One per ID speaking. (it controls registering and deregistering)
// NOTE: registering OnePerID(setter), those two addresses will only be able
// to do their special position.
if msg.sender == contract.storage[OnePerID]:
if msg.data[1] < LARGE: //Exceedingly unlikely; 7e-37.
return("low address")
if msg.datasize == 2:
if msg.data[0] == "register":
got = contract.storage[msg.data[1]]
if got:
return("already registered")
// Splits slot in two halves.
contract.storage[msg.data[1]] = block.timestamp + HALFWAY*block.timestamp
return("registered")
if msg.data[0] == "deregister": // One Per ID has a lot of power!
contract.storage[msg.data[1]] = 0
return("deregistered")
return("OnePerID bad 1")
if msg.datasize == 3 && msg.data[0] == "move":
if msg.data[2] < LARGE: //Exceedingly unlikely; 7e-37.
return("low address")
if contract.storage[msg.data[2]]:
return("already exists there")
got = contract.storage[msg.data[1]]
if got:
contract.storage[msg.data[2]] = got
contract.storage[msg.data[1]] = 0
return("moved")
else:
return("does not exist")
return("OnePerID bad 2")
// One per ID changer speaking. //TODO prepend the name of the command.
if msg.sender == contract.storage[OnePerIDSet]:
if msg.datasize != 3:
return("OnePerIDSet bad")
contract.storage[OnePerID] = msg.data[0]
contract.storage[OnePerIDSet] = msg.data[1]
contract.storage[Puppeteer] = msg.data[2]
return("changed!")
// Puppeteer speaking.
if msg.sender == contract.storage[Puppeteer]:
if msg.datasize == 0:
return("Puppeteer cant do nothing")
i = 1
args = array(msg.datasize-1)
while i < msg.datasize:
args[i-1] = msg.data[i]
i = i + 1
// TODO return list.
return(msg(tx.gas-100, msg.data[0], msg.value, args, msg.datasize-1))
// Anyone speaking.
if msg.datasize == 1:
if msg.data[0] == "topic_count":
return((contract.storage[TopicI] - TopicStartI) / TopicSz)
return("anyone bad 4")
if msg.datasize == 2:
if msg.data[0] == "vote_count":
if msg.data[1] >= ((contract.storage[TopicI] - TopicStartI)/TopicSz):
return("topic doesnt exist yet")
return(contract.storage[TopicStartI + msg.data[1]*TopicSz])
if msg.data[0] == "account": //Can also be used to get out OnePerId,
return(contract.storage[msg.data[1]])
return("anyone bad 1")
if msg.datasize == 3: //Defined as being a vote.
if msg.data[0] == "vote":
if msg.data[1] >= (contract.storage[TopicI] - TopicStartI)/TopicSz:
return("topic doesnt exist yet(vote)")
slot = contract.storage[msg.sender]
if slot == 0:
return("cant vote, not registered")
if slot/HALFWAY + msg.data[2] > block.timestamp:
return("cannot spend more than you have")
// Use up the voting time.
contract.storage[msg.sender] = slot%HALFWAY + HALFWAY*(slot/HALFWAY + msg.data[2])
// And give it to the topic.
cur = contract.storage[TopicStartI + msg.data[1]*TopicSz]
contract.storage[TopicStartI + msg.data[1]*TopicSz] = cur + msg.data[2]
return("voted")
return("anyone bad 2")
if msg.datasize > 3: // Creates a topic.
if msg.datasize > TopicSz - 0x20:
return("too long topic string")
i = contract.storage[TopicI]
j = i + 0x20
k = 0
tj = i + msg.datasize*0x20
while j < tj && msg.data[k] != "": // Set it.
contract.storage[j] = msg.data[k]
j = j + 0x20
k = k + 1
contract.storage[TopicI] = i + TopicSz
return("topic set")
return("anyone bad 3")