Search Apps Documentation Source Content File Folder Download Copy Actions Download

init.gno

0.72 Kb ยท 39 lines
 1package v1
 2
 3import (
 4	"gno.land/p/nt/avl"
 5	"gno.land/r/gnoswap/position"
 6)
 7
 8func init() {
 9	registerPositionV1()
10}
11
12func registerPositionV1() {
13	position.RegisterInitializer(cross, func(positionStore position.IPositionStore) position.IPosition {
14		err := initStoreData(positionStore)
15		if err != nil {
16			panic(err)
17		}
18
19		return NewPositionV1(positionStore, newGNFTAccessor())
20	})
21}
22
23func initStoreData(positionStore position.IPositionStore) error {
24	if !positionStore.HasPositionNextIDStoreKey() {
25		err := positionStore.SetPositionNextID(uint64(1))
26		if err != nil {
27			return err
28		}
29	}
30
31	if !positionStore.HasPositionsStoreKey() {
32		err := positionStore.SetPositions(avl.NewTree())
33		if err != nil {
34			return err
35		}
36	}
37
38	return nil
39}