demo.gno
0.64 Kb ยท 33 lines
1package ownable
2
3import (
4 "chain/runtime"
5)
6
7var owner address = ""
8
9func InitOwner(cur realm) {
10 if len(owner) != 0 {
11 panic("owner already defined")
12 }
13 owner = runtime.PreviousRealm().Address()
14}
15
16func assertOnlyOwner() {
17 if runtime.PreviousRealm().Address() != owner {
18 panic("caller isn't the owner")
19 }
20}
21
22func ChangeOwner(cur realm, newOwner address) {
23 assertOnlyOwner()
24 owner = newOwner
25}
26
27func RenderDemo() string {
28 content := "## Live Demo\n"
29 content += "Owner address: **" + owner.String() + "**\n\n"
30 content += "[InitOwner](ownable$help&func=InitOwner)\n\n"
31 content += "[ChangeOwner](ownable$help&func=ChangeOwner)\n\n"
32 return content
33}