blob: 1501beff76ea6f99a2fb4d08be6f3310651769c9 (
plain) (
blame)
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
|
# Initialization
# Admin can issue and delete at will
init:
contract.storage[0] = msg.sender
code:
# If a message with one item is sent, that's a balance query
if msg.datasize == 1:
addr = msg.data[0]
return(contract.storage[addr])
# If a message with two items [to, value] are sent, that's a transfer request
elif msg.datasize == 2:
from = msg.sender
fromvalue = contract.storage[from]
to = msg.data[0]
value = msg.data[1]
if fromvalue >= value and value > 0 and to > 4:
contract.storage[from] = fromvalue - value
contract.storage[to] += value
contract.storage[2] = from
contract.storage[3] = to
contract.storage[4] = value
contract.storage[5] += 1
return(1)
return(0)
elif msg.datasize == 3 and msg.sender == contract.storage[0]:
# Admin can issue at will by sending a [to, value, 0] message
if msg.data[2] == 0:
contract.storage[msg.data[0]] += msg.data[1]
# Change admin [ newadmin, 0, 1 ]
# Set admin to 0 to disable administration
elif msg.data[2] == 1:
contract.storage[0] = msg.data[0]
# Fetch last transaction
else:
return([contract.storage[2], contract.storage[3], contract.storage[4], contract.storage[5]], 4)
|