0g-chain/x/community/keeper/keeper.go
Ruaridh bc260d8091
feat(community): add switchover param (#1704)
* add community params type

* add get/set params methods

* add community genesis state type

* add community init/export genesis

* add querier methods for params

* add query cli cmd

* update changelog

* update protonet genesis

* Add `RewardsPerSecond` param to `x/community` module (#1707)

* Add RewardsPerSecond param to community

* Update rewards per second param to int

* Add rewards_per_second to protonet genesis

* Use default rewards per second of 744191

* Include value if negative in Validate error

* Rename RewardsPerSecond param to StakingRewardsPerSecond

* Add changelog entry

* Add param migration, update consensus version to 2

* Update proto docs

* Update staking_rewards_per_second param name in protonet genesis (#1730)

* Update godoc

Co-authored-by: Robert Pirtle <Astropirtle@gmail.com>

* add genesis state tests

* document what 0 upgrade time means

* update kvtool to include new params

---------

Co-authored-by: drklee3 <derrick@dlee.dev>
Co-authored-by: Robert Pirtle <Astropirtle@gmail.com>
2023-09-22 09:05:12 -07:00

81 lines
2.3 KiB
Go

package keeper
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/kava-labs/kava/x/community/types"
)
// Keeper of the community store
type Keeper struct {
key storetypes.StoreKey
cdc codec.Codec
bankKeeper types.BankKeeper
cdpKeeper types.CdpKeeper
distrKeeper types.DistributionKeeper
hardKeeper types.HardKeeper
moduleAddress sdk.AccAddress
legacyCommunityPoolAddress sdk.AccAddress
}
// NewKeeper creates a new community Keeper instance
func NewKeeper(
cdc codec.Codec,
key storetypes.StoreKey,
ak types.AccountKeeper,
bk types.BankKeeper,
ck types.CdpKeeper,
dk types.DistributionKeeper,
hk types.HardKeeper,
) Keeper {
// ensure community module account is set
addr := ak.GetModuleAddress(types.ModuleAccountName)
if addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleAccountName))
}
legacyAddr := ak.GetModuleAddress(types.LegacyCommunityPoolModuleName)
if addr == nil {
panic("legacy community pool address not found")
}
return Keeper{
key: key,
cdc: cdc,
bankKeeper: bk,
cdpKeeper: ck,
distrKeeper: dk,
hardKeeper: hk,
moduleAddress: addr,
legacyCommunityPoolAddress: legacyAddr,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// GetModuleAccountBalance returns all the coins held by the community module account
func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coins {
return k.bankKeeper.GetAllBalances(ctx, k.moduleAddress)
}
// FundCommunityPool transfers coins from the sender to the community module account.
func (k Keeper) FundCommunityPool(ctx sdk.Context, sender sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleAccountName, amount)
}
// DistributeFromCommunityPool transfers coins from the community pool to recipient.
func (k Keeper) DistributeFromCommunityPool(ctx sdk.Context, recipient sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, recipient, amount)
}