demo.gno
0.69 Kb ยท 35 lines
1package statelock
2
3type State string
4
5const (
6 StateActive State = "Active"
7 StateLocked State = "Locked"
8 StateDisabled State = "Disabled"
9)
10
11var state State = StateActive
12
13func assertInState(expected State) {
14 if state != expected {
15 panic("invalid state: expected " + expected + ", got " + state)
16 }
17}
18
19func Lock(cur realm) {
20 assertInState(StateActive)
21 state = StateLocked
22}
23
24func Unlock(cur realm) {
25 assertInState(StateLocked)
26 state = StateActive
27}
28
29func RenderDemo() string {
30 content := "## Live Demo\n"
31 content += "Contract State : **" + string(state) + "**\n\n"
32 content += "[Lock](statelock$help&func=Lock)\n\n"
33 content += "[Unlock](statelock$help&func=Unlock)\n\n"
34 return content
35}