-
Notifications
You must be signed in to change notification settings - Fork 4
/
controller_address.go
40 lines (33 loc) · 1.15 KB
/
controller_address.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
package keeper
import (
"github.com/Carina-labs/nova/x/icacontrol/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// set store
func (k Keeper) GetControllerAddrStore(ctx sdk.Context) prefix.Store {
return prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyControllerAddress)
}
// set controller address
func (k Keeper) SetControllerAddr(ctx sdk.Context, zoneId string, controllerAddrs string) {
store := k.GetControllerAddrStore(ctx)
key := zoneId
controllerInfo := types.ControllerAddressInfo{
ZoneId: zoneId,
ControllerAddress: controllerAddrs,
}
bz := k.cdc.MustMarshal(&controllerInfo)
store.Set([]byte(key), bz)
}
// get controller address
func (k Keeper) GetControllerAddr(ctx sdk.Context, zoneId string) types.ControllerAddressInfo {
store := k.GetControllerAddrStore(ctx)
bz := store.Get([]byte(zoneId))
var controllerInfo types.ControllerAddressInfo
k.cdc.MustUnmarshal(bz, &controllerInfo)
return controllerInfo
}
func (k Keeper) IsValidControllerAddr(ctx sdk.Context, zoneId, address string) bool {
addrs := k.GetControllerAddr(ctx, zoneId)
return address == addrs.ControllerAddress
}