init.gno
0.89 Kb · 44 lines
1package position
2
3import (
4 "gno.land/r/gnoswap/access/v1"
5 "gno.land/r/gnoswap/position"
6)
7
8func init(cur realm) {
9 registerPositionV1(cur)
10}
11
12func registerPositionV1(cur realm) {
13 position.RegisterInitializer(
14 cross(cur),
15 func(_ int, rlm realm, positionStore position.IPositionStore) position.IPosition {
16 access.AssertIsRlmCurrent(0, rlm)
17
18 err := initStoreData(0, rlm, positionStore)
19 if err != nil {
20 panic(err)
21 }
22
23 return NewPositionV1(positionStore, newGNFTAccessor())
24 },
25 )
26}
27
28func initStoreData(_ int, rlm realm, positionStore position.IPositionStore) error {
29 if !positionStore.HasPositionNextIDStoreKey() {
30 err := positionStore.SetPositionNextID(0, rlm, uint64(1))
31 if err != nil {
32 return err
33 }
34 }
35
36 if !positionStore.HasPositionsStoreKey() {
37 err := positionStore.SetPositions(0, rlm, position.NewPositionsTree())
38 if err != nil {
39 return err
40 }
41 }
42
43 return nil
44}