cosmos-sdk/x/distribution/types/fee_pool.go

49 lines
1.4 KiB
Go
Raw Normal View History

2018-09-04 23:41:17 -07:00
package types
import sdk "github.com/cosmos/cosmos-sdk/types"
// total accumulation tracker
type TotalAccum struct {
UpdateHeight int64 `json:"update_height"`
Accum sdk.Dec `json:"accum"`
}
2018-09-17 20:02:15 -07:00
func NewTotalAccum(height int64) TotalAccum {
return TotalAccum{
UpdateHeight: height,
Accum: sdk.ZeroDec(),
}
}
2018-09-04 23:41:17 -07:00
// update total validator accumulation factor
func (ta TotalAccum) Update(height int64, accumCreatedPerBlock sdk.Dec) TotalAccum {
blocks := height - ta.UpdateHeight
2018-09-19 16:33:12 -07:00
ta.Accum = ta.Accum.Add(accumCreatedPerBlock.Mul(sdk.NewDec(blocks)))
2018-09-04 23:41:17 -07:00
ta.UpdateHeight = height
return ta
}
//___________________________________________________________________________________________
// global fee pool for distribution
type FeePool struct {
ValAccum TotalAccum `json:"val_accum"` // total valdator accum held by validators
Pool DecCoins `json:"pool"` // funds for all validators which have yet to be withdrawn
CommunityPool DecCoins `json:"community_pool"` // pool for community funds yet to be spent}
}
// update total validator accumulation factor
2018-09-19 16:00:21 -07:00
func (f FeePool) UpdateTotalValAccum(height int64, totalBondedTokens sdk.Dec) FeePool {
2018-09-04 23:41:17 -07:00
f.ValAccum = f.ValAccum.Update(height, totalBondedTokens)
return f
}
2018-09-17 20:02:15 -07:00
// zero fee pool
func InitialFeePool() FeePool {
return FeePool{
2018-09-19 16:33:12 -07:00
ValAccum: NewTotalAccum(0),
2018-09-17 20:02:15 -07:00
Pool: DecCoins{},
CommunityPool: DecCoins{},
}
}