Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COIN-852: Tezos: bad behavior (balance gets to zero) when the server … #675

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ namespace ledger {
const std::string &forceUrl,
bool isDecimal) {
const bool parseNumbersAsString = true;
const bool ignoreStatusCode = true;
auto networkId = getNetworkParameters().Identifier;

std::string p, separator = "?";
Expand All @@ -235,9 +236,19 @@ namespace ledger {
return _http->GET(url + p,
std::unordered_map<std::string, std::string>(),
forceUrl)
.json(parseNumbersAsString)
.json(parseNumbersAsString, ignoreStatusCode)
.mapPtr<BigInt>(getContext(),
[field, networkId, fallbackValue, isDecimal](const HttpRequest::JsonResult &result) {
auto& connection = *std::get<0>(result);
if (connection.getStatusCode() == 404) {
// it means that it’s a “logical” error (i.e. some resources not found), which
// in this case we fallback to a given value
return std::make_shared<BigInt>(!fallbackValue.empty() ? fallbackValue : "0");
}
else if (connection.getStatusCode() < 200 || connection.getStatusCode() >= 300) {
throw Exception(api::ErrorCode::HTTP_ERROR, connection.getStatusText());
}

auto &json = *std::get<1>(result);
if ((!json.IsObject() ||
!json.HasMember(field.c_str()) ||
Expand All @@ -253,19 +264,7 @@ namespace ledger {
value = api::BigInt::fromDecimalString(value, 6, ".")->toString(10);
}
return std::make_shared<BigInt>(value);
})
.recover(getContext(), [fallbackValue] (const Exception &exception) {
auto ecode = exception.getErrorCode();
if (ecode == api::ErrorCode::UNABLE_TO_CONNECT_TO_HOST) {
// if it’s an HTTP error, it might be due to the host not being reachable or such,
// so we re-run the error
throw exception;
}

// otherwise, it means that it’s a “logical” error (i.e. some resources not found), which
// in this case we fallback to a given value
return std::make_shared<BigInt>(!fallbackValue.empty() ? fallbackValue : "0");
});
});
}

Future<std::shared_ptr<BigInt>>
Expand Down