staking: Fix potential division-by-zero

`v.DelegatorShares` can be 0 so don't allow division in that case.
This commit is contained in:
Chirantan Ekbote 2022-08-25 17:51:17 +09:00 committed by Conor Patrick
parent 46bc89f04d
commit 5b8a5ea690
1 changed files with 3 additions and 0 deletions

View File

@ -304,6 +304,9 @@ func (v Validator) InvalidExRate() bool {
// calculate the token worth of provided shares
func (v Validator) TokensFromShares(shares sdk.Dec) sdk.Dec {
if v.DelegatorShares.IsZero() {
return sdk.Dec(sdk.ZeroInt())
}
return (shares.MulInt(v.Tokens)).Quo(v.DelegatorShares)
}