demo.gno

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