Search Apps Documentation Source Content File Folder Download Copy Actions Download

upgrade.gno

1.29 Kb ยท 53 lines
 1package staker
 2
 3import (
 4	"chain/runtime"
 5
 6	"gno.land/r/gnoswap/access"
 7)
 8
 9// RegisterInitializer registers an implementation
10// This function is called by each implementation version during init
11func RegisterInitializer(cur realm, initializer func(govStakerStore IGovStakerStore) IGovStaker) {
12	initializerFunc := func(domainStore any) any {
13		currentGovStakerStore, ok := domainStore.(IGovStakerStore)
14		if !ok {
15			panic("domainStore is not an IGovStakerStore")
16		}
17
18		return initializer(currentGovStakerStore)
19	}
20
21	err := versionManager.RegisterInitializer(initializerFunc)
22	if err != nil {
23		panic(err)
24	}
25
26	err = updateImplementation()
27	if err != nil {
28		panic(err)
29	}
30}
31
32// UpgradeImpl upgrades the implementation to a new version
33// Only admin or governance can call this function
34func UpgradeImpl(cur realm, packagePath string) {
35	// Check admin or governance permission
36	caller := runtime.PreviousRealm().Address()
37	access.AssertIsAdminOrGovernance(caller)
38
39	err := versionManager.ChangeImplementation(packagePath)
40	if err != nil {
41		panic(err)
42	}
43
44	err = updateImplementation()
45	if err != nil {
46		panic(err)
47	}
48}
49
50// GetImplementationPackagePath returns the package path of the currently active implementation.
51func GetImplementationPackagePath() string {
52	return versionManager.GetCurrentPackagePath()
53}