fix: core/coins: skip 2 int64(uint32) casts by comparison checks and silence gosec warnings (#13611)

This commit is contained in:
Emmanuel T Odeke 2022-10-21 07:50:52 -07:00 committed by GitHub
parent 1dae922fe0
commit 6a371842df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -44,17 +44,15 @@ func formatCoin(coin *basev1beta1.Coin, metadata *bankv1beta1.Metadata) (string,
return vr + " " + coin.Denom, err
}
exponentDiff := int64(coinExp) - int64(dispExp)
dispAmount, err := math.LegacyNewDecFromStr(coin.Amount)
if err != nil {
return "", err
}
if exponentDiff > 0 {
dispAmount = dispAmount.Mul(math.LegacyNewDec(10).Power(uint64(exponentDiff)))
if coinExp > dispExp {
dispAmount = dispAmount.Mul(math.LegacyNewDec(10).Power(uint64(coinExp - dispExp)))
} else {
dispAmount = dispAmount.Quo(math.LegacyNewDec(10).Power(uint64(-exponentDiff)))
dispAmount = dispAmount.Quo(math.LegacyNewDec(10).Power(uint64(dispExp - coinExp)))
}
vr, err := math.FormatDec(dispAmount.String())