From a898d6bb0289bb93e208086730e597b1e199a68a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Thu, 22 Apr 2021 01:13:35 -0700 Subject: [PATCH] :bug: -1 fix --- include/bank.hpp | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/include/bank.hpp b/include/bank.hpp index 6721db3..2be03d9 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -160,31 +160,33 @@ public: Json::Value GetLogs(const std::string &name, const std::string &attempt) { Json::Value res; - users.if_contains(name, [&res, &attempt](const User &u) { - if (u.password != XXH3_64bits(attempt.data(), attempt.size())) - { - res = 0; - return; - } - - if (u.log.data.size()) - { - uint32_t j; - for (uint32_t i = u.log.data.size() - 1; i > 0; --i) + if (!users.if_contains(name, [&res, &attempt](const User &u) { + if (u.password != XXH3_64bits(attempt.data(), attempt.size())) { - j = u.log.data.size() - 1 - i; - if (!u.log.data[i].amount) - { - return; - } - res[j]["to"] = u.log.data[i].to; - res[j]["from"] = u.log.data[i].from; - res[j]["amount"] = u.log.data[i].amount; - res[j]["time"] = (Json::UInt64)u.log.data[i].time; + res = 0; + return; } - } - res = -1; - }); + + if (u.log.data.size()) + { + uint32_t j; + for (uint32_t i = u.log.data.size() - 1; i > 0; --i) + { + j = u.log.data.size() - 1 - i; + if (!u.log.data[i].amount) + { + return; + } + res[j]["to"] = u.log.data[i].to; + res[j]["from"] = u.log.data[i].from; + res[j]["amount"] = u.log.data[i].amount; + res[j]["time"] = (Json::UInt64)u.log.data[i].time; + } + } + })) + { + return -1; + } return res; }