From ef45429477d028e8a551c5f27da0555e611ff3e5 Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Sun, 16 Dec 2018 22:15:14 +0300 Subject: [PATCH] #99 Add coin transfer hook. Fix naming. Add comments. --- x/bandwidth/abci.go | 5 +++++ x/bank/keeper.go | 22 +++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/x/bandwidth/abci.go b/x/bandwidth/abci.go index 82aa5f6c..dfb88273 100644 --- a/x/bandwidth/abci.go +++ b/x/bandwidth/abci.go @@ -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) { diff --git a/x/bank/keeper.go b/x/bank/keeper.go index 52679f70..0e5b24c4 100644 --- a/x/bank/keeper.go +++ b/x/bank/keeper.go @@ -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, } } @@ -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) } }