Skip to content

Commit

Permalink
send tokens using to module instead of address
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Jul 8, 2024
1 parent d1f0598 commit fd0cdea
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions x/accumulator/keeper/token_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,35 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/accumulator/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

func (k BaseKeeper) DistributeValidatorsPool(ctx sdk.Context, amount sdk.Coins) error {
return k.distributeTokens(ctx, types.ValidatorPoolName, authtypes.NewModuleAddress(minttypes.ModuleName), amount)
return k.distributeTokens(ctx, types.ValidatorPoolName, minttypes.ModuleName, amount)
}

func (k BaseKeeper) distributeTokens(ctx sdk.Context, fromPool string, receiver sdk.AccAddress, amount sdk.Coins) error {
func (k BaseKeeper) distributeTokens(ctx sdk.Context, fromPool string, receiverModule string, amount sdk.Coins) error {
poolAddress := GetPoolAddress(fromPool)
if poolAddress == nil {
return types.ErrInvalidPool
}

return k.sendFromAddressToAddress(ctx, poolAddress, receiver, amount)
return k.sendFromAddressToModule(ctx, poolAddress, receiverModule, amount)
}

func (k BaseKeeper) sendFromAddressToAddress(ctx sdk.Context, poolAddress, receiverAddress sdk.AccAddress, amount sdk.Coins) error {
func (k BaseKeeper) sendFromAddressToModule(ctx sdk.Context, poolAddress sdk.AccAddress, receiverAddress string, amount sdk.Coins) error {
err := k.bankKeeper.SendCoinsFromAccountToModule(
ctx,
poolAddress,
types.ModuleName,
receiverAddress,
amount,
)

if err != nil {
err = errors.Wrap(err, "sending native coins to address")
k.Logger(ctx).Error(err.Error())
return err
}

err = k.bankKeeper.SendCoinsFromModuleToAccount(
ctx,
types.ModuleName,
receiverAddress,
amount,
)

if err != nil {
return errors.Wrap(err, "sending native coins to address")
}

return nil
}

0 comments on commit fd0cdea

Please sign in to comment.