Search Apps Documentation Source Content File Folder Download Copy Actions Download

config.gno

1.30 Kb ยท 66 lines
 1package chunk
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6
 7	"gno.land/p/nt/ufmt"
 8)
 9
10const (
11	SetListLimitEvent  = "SetListLimit"
12	SetBatchLimitEvent = "SetBatchLimit"
13)
14
15var (
16	listLimit  int = 100  // Max items per list query
17	batchLimit int = 1000 // Max keys per batch query
18)
19
20// SetListLimit sets the max items per list query (admin only)
21func SetListLimit(cur realm, limit int) {
22	caller := runtime.PreviousRealm().Address()
23	assertIsAdmin(caller)
24	if limit < 1 {
25		panic("limit must be at least 1")
26	}
27
28	oldLimit := listLimit
29	listLimit = limit
30
31	chain.Emit(
32		SetListLimitEvent,
33		"admin", caller.String(),
34		"oldLimit", ufmt.Sprintf("%d", oldLimit),
35		"newLimit", ufmt.Sprintf("%d", limit),
36	)
37}
38
39// GetListLimit returns the max items per list query
40func GetListLimit() int {
41	return listLimit
42}
43
44// SetBatchLimit sets the max keys per batch query (admin only)
45func SetBatchLimit(cur realm, limit int) {
46	caller := runtime.PreviousRealm().Address()
47	assertIsAdmin(caller)
48	if limit < 1 {
49		panic("limit must be at least 1")
50	}
51
52	oldLimit := batchLimit
53	batchLimit = limit
54
55	chain.Emit(
56		SetBatchLimitEvent,
57		"admin", caller.String(),
58		"oldLimit", ufmt.Sprintf("%d", oldLimit),
59		"newLimit", ufmt.Sprintf("%d", limit),
60	)
61}
62
63// GetBatchLimit returns the max keys per batch query
64func GetBatchLimit() int {
65	return batchLimit
66}