-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.go
48 lines (40 loc) · 1.3 KB
/
whitelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cosmwasmpool
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/percosis-labs/percosis/osmoutils"
)
// Whitelists the code id.
func (k Keeper) WhitelistCodeId(ctx sdk.Context, codeId uint64) {
params := k.GetParams(ctx)
if !osmoutils.Contains(params.CodeIdWhitelist, codeId) {
params.CodeIdWhitelist = append(params.CodeIdWhitelist, codeId)
k.SetParams(ctx, params)
}
}
// deWhitelistCodeId removes the code id from the whitelist.
// Returns true if the code id was in the whitelist and was removed.
// Returns false if the code id was not in the whitelist.
// nolint: unused
func (k Keeper) deWhiteListCodeId(ctx sdk.Context, codeId uint64) bool {
params := k.GetParams(ctx)
whitelist := params.CodeIdWhitelist
indexToRemove := len(whitelist)
for i, id := range whitelist {
if id == codeId {
indexToRemove = i
break
}
}
foundCodeId := indexToRemove < len(whitelist)
if foundCodeId {
whitelist = append(whitelist[:indexToRemove], whitelist[indexToRemove+1:]...)
params.CodeIdWhitelist = whitelist
k.SetParams(ctx, params)
}
return foundCodeId
}
// isWhitelisted returns true if the code id is in the whitelist.
func (k Keeper) isWhitelisted(ctx sdk.Context, codeId uint64) bool {
whitelist := k.GetParams(ctx).CodeIdWhitelist
return osmoutils.Contains(whitelist, codeId)
}