-
Notifications
You must be signed in to change notification settings - Fork 202
/
consumer.go
39 lines (32 loc) · 1.08 KB
/
consumer.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/Stride-Labs/stride/v19/x/stakeibc/types"
)
// Register new stTokens to the consumer reward denom whitelist
func (k Keeper) RegisterStTokenDenomsToWhitelist(ctx sdk.Context, denoms []string) error {
hostZones := k.GetAllHostZone(ctx)
allDenomsMap := make(map[string]bool)
registeredDenomsMap := make(map[string]bool)
// get all stToken denoms
for _, zone := range hostZones {
allDenomsMap[types.StAssetDenomFromHostZoneDenom(zone.HostDenom)] = true
}
// get registered denoms in the consumer reward denom whitelist
consumerParams := k.ConsumerKeeper.GetConsumerParams(ctx)
for _, denom := range consumerParams.RewardDenoms {
registeredDenomsMap[denom] = true
}
// register new denoms to the whitelist
for _, denom := range denoms {
if !allDenomsMap[denom] {
return types.ErrStTokenNotFound
} else if registeredDenomsMap[denom] {
continue
} else {
consumerParams.RewardDenoms = append(consumerParams.RewardDenoms, denom)
}
}
k.ConsumerKeeper.SetParams(ctx, consumerParams)
return nil
}