refactor: deprecate int32 (#7025)
* refactor: deprecate int32 * fix(db): reject legacy user quota schemas at startup * fix(quota): enforce wallet bounds and saturating billing conversions * fix(rate-limit): keep count*duration from wrapping int64 * fix: error message
This commit is contained in:
+8
-4
@@ -182,7 +182,11 @@ func getMinTopup() int64 {
|
||||
if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeTokens {
|
||||
dMinTopup := decimal.NewFromInt(int64(minTopup))
|
||||
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
||||
minTopup = common.QuotaFromDecimal(dMinTopup.Mul(dQuotaPerUnit))
|
||||
quota, err := common.WalletQuotaFromDecimalStrict(dMinTopup.Mul(dQuotaPerUnit))
|
||||
if err != nil {
|
||||
return common.MaxWalletQuota
|
||||
}
|
||||
minTopup = quota
|
||||
}
|
||||
return int64(minTopup)
|
||||
}
|
||||
@@ -195,7 +199,7 @@ func getTopUpQuota(amount int64) (int, error) {
|
||||
} else {
|
||||
quota = quota.Mul(decimal.NewFromFloat(common.QuotaPerUnit))
|
||||
}
|
||||
return common.QuotaFromDecimalStrict(quota)
|
||||
return common.WalletQuotaFromDecimalStrict(quota)
|
||||
}
|
||||
|
||||
func getMaxTopUpAmount() int64 {
|
||||
@@ -203,7 +207,7 @@ func getMaxTopUpAmount() int64 {
|
||||
return 0
|
||||
}
|
||||
quotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
||||
maxStoredAmount := decimal.NewFromInt(common.MaxQuota - 1).
|
||||
maxStoredAmount := decimal.NewFromInt(common.MaxWalletQuota).
|
||||
Div(quotaPerUnit).
|
||||
Floor()
|
||||
if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeTokens {
|
||||
@@ -217,7 +221,7 @@ func getMaxTopUpAmount() int64 {
|
||||
}
|
||||
|
||||
func validateCreditedQuota(quota decimal.Decimal) (int, error) {
|
||||
value, err := common.QuotaFromDecimalStrict(quota)
|
||||
value, err := common.WalletQuotaFromDecimalStrict(quota)
|
||||
if err != nil {
|
||||
return 0, errors.New("充值额度超出系统可表示范围")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user