diff --git a/include/bank.hpp b/include/bank.hpp index 0c83e53..0809258 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -235,7 +235,7 @@ public: { if constexpr (max_log_size) { - users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()), std::move(temp[u]["log"])); + users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()), temp[u]["log"]); } else { diff --git a/include/log.hpp b/include/log.hpp index 4da5379..7861e61 100644 --- a/include/log.hpp +++ b/include/log.hpp @@ -12,7 +12,14 @@ struct Log { if (data.size() <= end+1 && end+1 < max_log_size) //if memory reserved is full { - data.resize(data.size() + pre_log_size); //prefetching memory + if(data.size() + pre_log_size > max_log_size) + { + data.resize(max_log_size); + } + else + { + data.resize(data.size() + pre_log_size); //prefetching memory + } } for (uint32_t i = end; i > 0; --i) { diff --git a/include/user.hpp b/include/user.hpp index 17ccb26..04526f6 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -31,11 +31,11 @@ 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, const Json::Value &log_j) : balance(init_bal), password(init_pass) { if (log_j.size()) { - if (max_log_size > log_j.size() + pre_log_size) + if (max_log_size > (log_j.size() + pre_log_size)) { log.data.resize(log_j.size() + pre_log_size); log.end = log_j.size(); @@ -45,9 +45,9 @@ struct User 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) + for (uint32_t i = 0; i < log.end; ++i) { - log.data[i] = std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["balance"].asUInt())); + log.data[i] = std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["amount"].asUInt())); } } }