-
Notifications
You must be signed in to change notification settings - Fork 2
/
town_crier.vif
78 lines (65 loc) · 2.31 KB
/
town_crier.vif
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
# Constants that we don't have values for right now
minValue : IFL(wei_value, top)
maxValue : IFL(wei_value, top)
cancelValue : IFL(wei_value, top)
nextId : IFL(uint256, this)
SGX : IFL(address, this)
requests : {
deposit : IFL(wei_value, this),
requester : IFL(address, this),
params : IFL(bytes32, this),
callback : IFL(address, requester),
flag : IFL(uint256, this)
}[uint256]
@public
def __init__(_SGX : address):
self.minValue = 0
self.maxValue = 3000000
self.cancelValue = 20000
self.SGX = _SGX
self.nextId = 0
@public
@payable
@IFL_autoendorsethis
def request(params : bytes32, callback : address) -> uint256:
assert msg.value >= self.minValue
assert msg.value <= self.maxValue
id : uint256 = self.nextId
self.nextId = self.nextId + 1
self.requests[id] = {deposit : msg.value,
requester : msg.sender,
params : endorse(params, msg.sender, this),
callback : callback,
flag : 0}
return id
@public
@IFL_autoendorsethis
def cancel(id : uint256) -> bool:
assert endorse(id < self.nextId, bot, this)
assert self.requests[id].deposit >= self.cancelValue
assert self.requests[id].requester == msg.sender
if self.requests[id].flag == 0:
self.requests[id].flag = 1
send(msg.sender, self.requests[id].deposit - self.cancelValue)
return True
else:
return False
@public
def updateCallback(id : uint256, callback : address):
assert id < self.nextId
assert msg.sender == self.requests[id].requester
self.requests[id].callback = callback
@public
@IFL_autoendorsethis
def deliver(id : IFL(uint256, self.SGX), params : IFL(bytes32, self.SGX), data : IFL(bytes[15], self.SGX)):
assert id < self.nextId
assert self.requests[id].deposit >= self.minValue
assert self.requests[id].params == params
assert self.requests[id].flag == 0 or self.requests[id].flag == 1
self.requests[id].flag = 2
if self.requests[id].flag == 1:
send(self.SGX, self.cancelValue)
else:
send(self.SGX, self.requests[id].deposit)
gasValue : wei_value = self.requests[id].deposit - self.minValue
output : bytes[1] = raw_call(self.requests[id].callback, data, outsize=1, gas=gasValue)