/
keeper.go
49 lines (42 loc) · 1.26 KB
/
keeper.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
49
package guardian
import (
"github.com/Dipper-Labs/Dipper-Protocol/codec"
sdk "github.com/Dipper-Labs/Dipper-Protocol/types"
)
// Keeper defines the guardian store
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
}
// NewKeeper creates a new guardian Keeper instance
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
}
return keeper
}
func (k Keeper) AddProfiler(ctx sdk.Context, guardian Guardian) error {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryLengthPrefixed(guardian)
store.Set(GetProfilerKey(guardian.Address), bz)
return nil
}
func (k Keeper) DeleteProfiler(ctx sdk.Context, address sdk.AccAddress) error {
store := ctx.KVStore(k.storeKey)
store.Delete(GetProfilerKey(address))
return nil
}
func (k Keeper) GetProfiler(ctx sdk.Context, addr sdk.AccAddress) (guardian Guardian, found bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(GetProfilerKey(addr))
if bz != nil {
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &guardian)
return guardian, true
}
return guardian, false
}
func (k Keeper) ProfilersIterator(ctx sdk.Context) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
return sdk.KVStorePrefixIterator(store, GetProfilersSubspaceKey())
}