-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateTrans.solidity
More file actions
29 lines (26 loc) · 942 Bytes
/
StateTrans.solidity
File metadata and controls
29 lines (26 loc) · 942 Bytes
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
pragma solidity ^0.5.9;
contract StateTransV2 {
enum Stage {Init, Reg, Vote, Done}
Stage public stage;
uint startTime;
uint public timeNow;
constructor() public {
stage = Stage.Init;
startTime = now;
}
//Assuming the Stage change has to be enacted APPROX every 1 mintute
//timeNow variable is defined for underatanding the process, you can simply use
// "now" Solidity defined varaible
// Of course, time duration for the Stages may depend on your application
//1 minutes is set to illustrate the working
function advanceState () public {
timeNow = now;
if (timeNow > (startTime + 1 minutes)) {
startTime = timeNow;
if (stage == Stage.Init) {stage = Stage.Reg; return;}
if (stage == Stage.Reg) {stage = Stage.Vote; return;}
if (stage == Stage.Vote) {stage = Stage.Done; return;}
return;
}
}
}