diff --git a/config.json b/config.json index fa95be9..331a931 100644 --- a/config.json +++ b/config.json @@ -4,13 +4,6 @@ "address": "0.0.0.0", "port": 80, "https": false - }, - { - "address": "0.0.0.0", - "port": 443, - "https": true, - "cert": "", - "key": "" } ] } diff --git a/include/bank.hpp b/include/bank.hpp index f20cdda..0c83e53 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -175,15 +175,15 @@ public: if constexpr (max_log_size) { if (!users.if_contains(name, [&res, &attempt](const User &u) { - if (u.password != XXH3_64bits(attempt.data(), attempt.size())) - { - res = 0; - } - else - { - res = u.log.Serialize(); - } - })) + if (u.password != XXH3_64bits(attempt.data(), attempt.size())) + { + res = 0; + } + else + { + res = u.log.Serialize(); + } + })) { return -1; } @@ -233,7 +233,7 @@ public: user_save.close(); for (const auto &u : temp.getMemberNames()) { - if constexpr(max_log_size) + if constexpr (max_log_size) { users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()), std::move(temp[u]["log"])); } diff --git a/include/log.hpp b/include/log.hpp index 60cd1ac..a405cc1 100644 --- a/include/log.hpp +++ b/include/log.hpp @@ -12,7 +12,7 @@ struct Log { if (data.size() == end) { - data.resize(data.size()+pre_log_size); //prefetching memory + data.resize(data.size() + pre_log_size); //prefetching memory } for (uint32_t i = end; i > 0; --i) { @@ -27,7 +27,7 @@ struct Log Json::Value Serialize() const { Json::Value res; - for (uint32_t i = 0; i < data.size() && data[i].amount; ++i) + for (uint32_t i = 0; i < end; ++i) { res[i]["to"] = data[i].to; res[i]["from"] = data[i].from; diff --git a/include/user.hpp b/include/user.hpp index a1f98f9..546c4d0 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -31,14 +31,26 @@ struct User * @param init_pass */ User(uint32_t init_bal, uint64_t init_pass) : balance(init_bal), password(init_pass) {} - User(uint32_t init_bal, uint64_t init_pass, Json::Value&& log_j) : balance(init_bal), password(init_pass) + User(uint32_t init_bal, uint64_t init_pass, Json::Value &&log_j) : balance(init_bal), password(init_pass) { - if(log_j.size()) + std::cout << log_j << '\n'; + if (log_j.size()) { - log.data.resize(log_j.size()+pre_log_size); - log.end = log_j.size(); - for(uint32_t i = 0; i < log_j.size() && i < max_log_size; ++i) + if (max_log_size > log_j.size() + pre_log_size) { + std::cout << "setting size to " << log_j.size() + pre_log_size << '\n'; + log.data.resize(log_j.size() + pre_log_size); + log.end = log_j.size(); + } + else + { + std::cout << "setting size to " << max_log_size << '\n'; + log.data.resize(max_log_size); + log.end = max_log_size; + } + for (uint32_t i = 0; i < log_j.size() && i < max_log_size; ++i) + { + std::cout << i << '\n'; log.data[i] = std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["balance"].asUInt())); } }