/
keeper.go
40 lines (32 loc) · 1.03 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
package keeper
import (
"errors"
"github.com/commercionetwork/commercionetwork/x/government/internal/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type Keeper struct {
StoreKey sdk.StoreKey
cdc *codec.Codec
}
func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey) Keeper {
return Keeper{
StoreKey: storeKey,
cdc: cdc,
}
}
// SetGovernmentAddress allows to set the given address as the one that
// the government will use later
func (keeper Keeper) SetGovernmentAddress(ctx sdk.Context, address sdk.AccAddress) error {
store := ctx.KVStore(keeper.StoreKey)
if store.Has([]byte(types.GovernmentStoreKey)) {
return errors.New("government address already set")
}
store.Set([]byte(types.GovernmentStoreKey), address)
return nil
}
// GetGovernmentAddress returns the address that the government has currently
func (keeper Keeper) GetGovernmentAddress(ctx sdk.Context) sdk.AccAddress {
store := ctx.KVStore(keeper.StoreKey)
return store.Get([]byte(types.GovernmentStoreKey))
}