mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 18:45:55 +00:00
fix(gateway_balances): handle overflow exception: (#4355)
* Prevent internal error by catching overflow exception in `gateway_balances`. * Treat `gateway_balances` obligations overflow as max (largest valid) `STAmount`. * Note that very large sums of STAmount are approximations regardless. --------- Co-authored-by: Scott Schurr <scott@ripple.com>
This commit is contained in:
@@ -184,7 +184,23 @@ doGatewayBalances(RPC::JsonContext& context)
|
||||
bal = -rs->getBalance();
|
||||
}
|
||||
else
|
||||
bal -= rs->getBalance();
|
||||
{
|
||||
try
|
||||
{
|
||||
bal -= rs->getBalance();
|
||||
}
|
||||
catch (std::runtime_error const&)
|
||||
{
|
||||
// Presumably the exception was caused by overflow.
|
||||
// On overflow return the largest valid STAmount.
|
||||
// Very large sums of STAmount are approximations
|
||||
// anyway.
|
||||
bal = STAmount(
|
||||
bal.issue(),
|
||||
STAmount::cMaxValue,
|
||||
STAmount::cMaxOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user