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

init.gno

1.25 Kb · 58 lines
 1package impl
 2
 3import (
 4	plimit "gno.land/p/gnoswap/order/limit/v0"
 5
 6	lo "gno.land/r/gnoswap/order/limit"
 7)
 8
 9func init(cur realm) {
10	lo.RegisterInitializer(cross(cur), func(_ int, rlm realm, orderStore plimit.ILimitOrderStore) plimit.ILimitOrder {
11		if err := initStoreData(0, rlm, orderStore); err != nil {
12			panic(err.Error())
13		}
14
15		return NewLimitOrderImpl(orderStore)
16	})
17}
18
19func initStoreData(_ int, rlm realm, s plimit.ILimitOrderStore) error {
20	if !s.HasOrders() {
21		if err := s.SetOrders(0, rlm, lo.NewBPTreeN(plimit.DefaultBPTreeFanout)); err != nil {
22			return err
23		}
24	}
25
26	if !s.HasOrdersByOwner() {
27		if err := s.SetOrdersByOwner(0, rlm, lo.NewBPTreeN(plimit.DefaultBPTreeFanout)); err != nil {
28			return err
29		}
30	}
31
32	if !s.HasPendingExecutionFees() {
33		if err := s.SetPendingExecutionFees(0, rlm, lo.NewBPTreeN(plimit.DefaultBPTreeFanout)); err != nil {
34			return err
35		}
36	}
37
38	if !s.HasNextOrderID() {
39		if err := s.SetNextOrderID(0, rlm, 1); err != nil {
40			return err
41		}
42	}
43
44	if !s.HasConfig() {
45		config := plimit.NewConfig(
46			defaultExecutionFeeRate,
47			defaultMinMakingAmount,
48			defaultMinOrderDuration,
49			defaultMaxOrderDuration,
50			defaultMaxCleanupBatchSize,
51		)
52		if err := s.SetConfig(0, rlm, config); err != nil {
53			return err
54		}
55	}
56
57	return nil
58}