-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.rsh
83 lines (64 loc) · 2.08 KB
/
index.rsh
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
'reach 0.1';
const [ _, MOTION_WINS, MOTION_LOSE, TIMEOUT ] = makeEnum(3);
export const main = Reach.App(() => {
const Governor= Participant('Governor', {
getProposal: Fun([], Object({
proposalID:UInt,
ticketPrice: UInt,
deadline: UInt,
})),
proposalReady: Fun([],Null),
showOutcome: Fun([UInt, UInt, UInt], Null),
callFunction:Fun([],Null),
showTimeout:Fun([UInt],Null)
})
const Voter= API('Voter', {
// Specify Bob's interact interface here
vote: Fun([Bool], Bool),
showOutcome:Fun([],UInt)
})
init();
const showOutcome = ( proposalID, voteFor, voteAgainst) => {
Governor.interact.showOutcome( proposalID, voteFor, voteAgainst)};
Governor.only(()=>{
const { ticketPrice, deadline, proposalID}= declassify(interact.getProposal())
})
Governor.publish(ticketPrice,deadline, proposalID);
commit();
Governor.publish()
Governor.interact.proposalReady()
const [ timeRemaining, keepGoing ] = makeDeadline(deadline);
const [voteFor, voteAgainst] =
parallelReduce([0, 0])
.invariant(balance() == (voteFor + voteAgainst) * ticketPrice)
.while(keepGoing())
.api_(Voter.vote, (vote) => {
return [ticketPrice, (k) => {
k(true)
const [nF, nA] = vote ? [1, 0] : [0, 1]
return [voteFor + nF, voteAgainst + nA]
}]
})
.timeout(timeRemaining(), () => {
Anybody.publish();
commit()
// showOutcome(TIMEOUT , voteFor, voteAgainst);
Governor.interact.showTimeout(TIMEOUT)
const [ [], k ] = call(Voter.showOutcome);
k( TIMEOUT );
return [voteFor , voteAgainst]
});
showOutcome( proposalID, voteFor, voteAgainst);
commit()
const outcome = voteFor>= voteAgainst ? MOTION_WINS : MOTION_LOSE
const [ [], k ] = call(Voter.showOutcome);
k(outcome);
commit()
Governor.publish()
if(voteFor >voteAgainst){
Governor.interact.callFunction()
}
transfer(balance()).to(Governor);
commit();
exit();
});