fix coin seller stock deduction delta
This commit is contained in:
parent
ac767d1c7e
commit
3cf62395e0
@ -57,7 +57,7 @@ func (r *Repository) AdminCreditCoinSellerStock(ctx context.Context, command led
|
|||||||
if availableDelta < 0 && account.AvailableAmount < command.CoinAmount {
|
if availableDelta < 0 && account.AvailableAmount < command.CoinAmount {
|
||||||
return ledger.CoinSellerStockCreditReceipt{}, xerr.New(xerr.InsufficientBalance, "insufficient balance")
|
return ledger.CoinSellerStockCreditReceipt{}, xerr.New(xerr.InsufficientBalance, "insufficient balance")
|
||||||
}
|
}
|
||||||
balanceAfter, err := checkedAdd(account.AvailableAmount, availableDelta)
|
balanceAfter, err := checkedAddDelta(account.AvailableAmount, availableDelta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ledger.CoinSellerStockCreditReceipt{}, err
|
return ledger.CoinSellerStockCreditReceipt{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,13 @@ func checkedAdd(left int64, right int64) (int64, error) {
|
|||||||
return left + right, nil
|
return left + right, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkedAddDelta(left int64, right int64) (int64, error) {
|
||||||
|
if (right > 0 && left > math.MaxInt64-right) || (right < 0 && left < math.MinInt64-right) {
|
||||||
|
return 0, xerr.New(xerr.CoinSellerStockAmountInvalid, "coin amount overflow")
|
||||||
|
}
|
||||||
|
return left + right, nil
|
||||||
|
}
|
||||||
|
|
||||||
func stableHash(value string) string {
|
func stableHash(value string) string {
|
||||||
sum := sha256.Sum256([]byte(value))
|
sum := sha256.Sum256([]byte(value))
|
||||||
return hex.EncodeToString(sum[:])
|
return hex.EncodeToString(sum[:])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user