Skip to content

Commit f4bbe34

Browse files
seporate token distribution logic
1 parent 08aa3d4 commit f4bbe34

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

types/tokens.go

-5
This file was deleted.

x/accumulator/keeper/keeper.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type (
2121
GetParams(c sdk.Context) types.Params
2222
SetParams(c sdk.Context, params types.Params)
2323
Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
24-
DistributeTokens(ctx sdk.Context, fromPool string, isSentToModule bool, amount sdk.Coins, receiverModule string, receiverAddress *sdk.AccAddress) error
24+
DistributeToModule(ctx sdk.Context, pool string, amount sdk.Coins, receiverModule string) error
25+
DistributeToAccount(ctx sdk.Context, pool string, amount sdk.Coins, receiver sdk.AccAddress) error
2526
}
2627

2728
BaseKeeper struct {

x/accumulator/keeper/token_distribution.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@ import (
66
"github.com/cosmos/cosmos-sdk/x/accumulator/types"
77
)
88

9-
func (k BaseKeeper) DistributeTokens(ctx sdk.Context, fromPool string, isSentToModule bool, amount sdk.Coins, receiverModule string, receiverAddress *sdk.AccAddress) error {
10-
poolAddress := GetPoolAddress(fromPool)
9+
func (k BaseKeeper) DistributeToModule(ctx sdk.Context, pool string, amount sdk.Coins, receiverModule string) error {
10+
poolAddress := GetPoolAddress(pool)
1111
if poolAddress == nil {
1212
return types.ErrInvalidPool
1313
}
1414

15-
if isSentToModule {
16-
return k.sendFromAddressToModule(ctx, poolAddress, receiverModule, amount)
15+
return k.sendFromAddressToModule(ctx, poolAddress, receiverModule, amount)
16+
17+
}
18+
19+
func (k BaseKeeper) DistributeToAccount(ctx sdk.Context, pool string, amount sdk.Coins, receiver sdk.AccAddress) error {
20+
21+
poolAddress := GetPoolAddress(pool)
22+
if poolAddress == nil {
23+
return types.ErrInvalidPool
1724
}
1825

19-
if receiverAddress == nil {
26+
if receiver == nil {
2027
return types.ErrInvalidReceiver
2128
}
22-
return k.sendFromAddressToAddress(ctx, poolAddress, *receiverAddress, amount)
29+
30+
return k.sendFromAddressToAddress(ctx, poolAddress, receiver, amount)
2331

2432
}
2533

@@ -32,7 +40,7 @@ func (k BaseKeeper) sendFromAddressToModule(ctx sdk.Context, poolAddress sdk.Acc
3240
)
3341

3442
if err != nil {
35-
err = errors.Wrap(err, "sending native coins to address")
43+
err = errors.Wrap(err, "sending native coins to account")
3644
k.Logger(ctx).Error(err.Error())
3745
return err
3846
}
@@ -62,7 +70,7 @@ func (k BaseKeeper) sendFromAddressToAddress(ctx sdk.Context, poolAddress sdk.Ac
6270
)
6371

6472
if err != nil {
65-
err = errors.Wrap(err, "sending native coins to module")
73+
err = errors.Wrap(err, "sending native coins to account")
6674
k.Logger(ctx).Error(err.Error())
6775
return err
6876
}

x/mint/keeper/keeper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec {
8080
}
8181

8282
func (k Keeper) SendFromAccumulator(ctx sdk.Context, amount sdk.Coins) error {
83-
err := k.accumulatorKeeper.DistributeTokens(ctx, accumulatortypes.ValidatorPoolName, true, amount, types.ModuleName, nil)
83+
err := k.accumulatorKeeper.DistributeToModule(ctx, accumulatortypes.ValidatorPoolName, amount, types.ModuleName)
8484
if err != nil {
8585
err = errors.Wrap(err, "failed to call accumulator module")
8686
k.Logger(sdk.UnwrapSDKContext(ctx)).Error(err.Error())

x/mint/types/expected_keepers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ type BankKeeper interface {
3030
}
3131

3232
type AccumulatorKeeper interface {
33-
DistributeTokens(ctx sdk.Context, fromPool string, isSentToModule bool, amount sdk.Coins, receiverModule string, receiverAddress *sdk.AccAddress) error
33+
DistributeToModule(ctx sdk.Context, pool string, amount sdk.Coins, receiverModule string) error
3434
}

0 commit comments

Comments
 (0)