Skip to content

Commit

Permalink
#99 Add coin transfer hook. Fix naming. Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau authored and arturalbov committed Dec 18, 2018
1 parent 64195f0 commit ef45429
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 5 additions & 0 deletions x/bandwidth/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"math"
)

// Used for 2 points:
// 1. Adjust credit price each `AdjustPricePeriod` blocks
// 2. For accs with updated on current block stake adjust max bandwidth. Why not update on `onCoinsTransfer`?
// Cuz for some bound related operations, coins already added/reduced from acc, but not added to
// validator\delegator pool.
func EndBlocker(
ctx sdk.Context, totalSpentForPeriod uint64, curPrice float64, ms storage.MainStorage,
) (newPrice float64, totalSpent uint64) {
Expand Down
22 changes: 9 additions & 13 deletions x/bank/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/cybercongress/cyberd/app/types/coin"
bdwth "github.com/cybercongress/cyberd/x/bandwidth"
)

type Keeper struct {
bank.Keeper

ak auth.AccountKeeper
sk *stake.Keeper
bwk bdwth.AccountBandwidthKeeper
ak auth.AccountKeeper
sk *stake.Keeper

// stake changed hooks
accStakeChangedHooks []CoinsTransferHook
coinsTransferHooks []CoinsTransferHook
}

func NewBankKeeper(ak auth.AccountKeeper, sk *stake.Keeper, accStakeChangedHooks []CoinsTransferHook) Keeper {
func NewBankKeeper(ak auth.AccountKeeper, sk *stake.Keeper, coinsTransferHooks []CoinsTransferHook) Keeper {
return Keeper{
Keeper: bank.NewBaseKeeper(ak),
ak: ak,
sk: sk,
accStakeChangedHooks: accStakeChangedHooks,
Keeper: bank.NewBaseKeeper(ak),
ak: ak,
sk: sk,
coinsTransferHooks: coinsTransferHooks,
}
}

Expand Down Expand Up @@ -75,14 +72,13 @@ func (k Keeper) InputOutputCoins(
}
for _, j := range outputs {
k.onCoinsTransfer(ctx, nil, j.Address)
//k.bwk.UpdateAccountMaxBandwidth(ctx, j.Address, k.GetAccountTotalStakePercentage(ctx, j.Address))
}
}
return tags, err
}

func (k Keeper) onCoinsTransfer(ctx sdk.Context, from sdk.AccAddress, to sdk.AccAddress) {
for _, hook := range k.accStakeChangedHooks {
for _, hook := range k.coinsTransferHooks {
hook(ctx, from, to)
}
}
Expand Down

0 comments on commit ef45429

Please sign in to comment.