staking: Fix potential division-by-zero
`v.DelegatorShares` can be 0 so don't allow division in that case.
This commit is contained in:
parent
46bc89f04d
commit
5b8a5ea690
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue