Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

state.gno

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