Skip to content

Commit

Permalink
Merge pull request #76 from dongsam/tidy-expected-keeper-and-module-i…
Browse files Browse the repository at this point in the history
…nterface

fix: tidy expected_keeper, module interface
  • Loading branch information
dongsam authored Oct 27, 2021
2 parents 34deb61 + 724537d commit 1368a47
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
9 changes: 1 addition & 8 deletions x/budget/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package budget
import (
"time"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -13,15 +11,10 @@ import (
)

// BeginBlocker collects budgets for the current block
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
err := k.CollectBudgets(ctx)
if err != nil {
panic(err)
}
}

func EndBlocker(ctx sdk.Context, k keeper.Keeper) []abci.ValidatorUpdate {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return []abci.ValidatorUpdate{}
}
6 changes: 5 additions & 1 deletion x/budget/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/tendermint/budget/x/budget/types"
Expand All @@ -14,7 +16,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {

k.SetParams(ctx, genState.Params)
moduleAcc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
k.accountKeeper.SetModuleAccount(ctx, moduleAcc)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}

for _, record := range genState.BudgetRecords {
k.SetTotalCollectedCoins(ctx, record.Name, record.TotalCollectedCoins)
Expand Down
4 changes: 2 additions & 2 deletions x/budget/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock returns the begin blocker for the budget module.
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
BeginBlocker(ctx, req, am.keeper)
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
BeginBlocker(ctx, am.keeper)
}

// EndBlock returns the end blocker for the budget module. It returns no validator
Expand Down
8 changes: 0 additions & 8 deletions x/budget/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ import (
// BankKeeper defines the expected bank send keeper
type BankKeeper interface {
InputOutputCoins(ctx sdk.Context, inputs []banktypes.Input, outputs []banktypes.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

GetSupply(ctx sdk.Context, denom string) sdk.Coin
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

// AccountKeeper defines the expected account keeper
type AccountKeeper interface {
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI
SetModuleAccount(sdk.Context, authtypes.ModuleAccountI)
Expand Down

0 comments on commit 1368a47

Please sign in to comment.