state.gno
1.15 Kb · 59 lines
1package launchpad
2
3import (
4 "errors"
5
6 _ "gno.land/r/gnoswap/rbac" // initialize readable contract role(s)
7
8 "gno.land/p/gnoswap/store"
9 "gno.land/p/gnoswap/version_manager"
10)
11
12var (
13 kvStore store.KVStore
14
15 versionManager version_manager.VersionManager
16 implementation ILaunchpad
17)
18
19func init(cur realm) {
20 // Create a new KV store instance for this domain
21 kvStore = store.NewKVStore(cur.Address())
22
23 // Initialize the initializers map to store implementation registration functions
24 versionManager = version_manager.NewVersionManager(
25 cur.PkgPath(),
26 kvStore,
27 initializeDomainStore,
28 )
29
30 implementation = nil
31}
32
33func initializeDomainStore(_ int, rlm realm, kvStore store.KVStore) any {
34 return NewLaunchpadStore(kvStore)
35}
36
37func getImplementation() ILaunchpad {
38 if implementation == nil {
39 panic("implementation is not initialized")
40 }
41
42 return implementation
43}
44
45func updateImplementation() error {
46 result := versionManager.GetCurrentImplementation()
47 if result == nil {
48 return errors.New("implementation is not initialized")
49 }
50
51 impl, ok := result.(ILaunchpad)
52 if !ok {
53 return errors.New("impl is not an ILaunchpad")
54 }
55
56 implementation = impl
57
58 return nil
59}