From 84f835e8b80261c20612e2ffd787bfb89c1e1d35 Mon Sep 17 00:00:00 2001 From: doggo Date: Sat, 5 Jun 2021 21:25:27 -0500 Subject: [PATCH] User log constructor change Now shifts to the end, is in order but takes only the lotest logs that it is able to. --- include/user.hpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/include/user.hpp b/include/user.hpp index 205aeb1..5608c47 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -36,17 +36,14 @@ struct User { if (log_j.size()) { - unsigned size = ((log_j.size() / pre_log_size) + 1) * pre_log_size; // Ensures that we have a log size aligned on a multiple of `pre_log_size` - log.data.reserve(size); // Ensures that the log size is under `max_log_size` - size = std::min(log_j.size(), max_log_size); - log.data.resize(size); - for (uint32_t i = 0; i < size; ++i) - { - log.data[i] = std::move(Transaction( + uint32_t newLogSize = std::min(pre_log_size * ((log_j.size() / pre_log_size) + 1), max_log_size); + log.data.reserve(newLogSize); + for (uint32_t i = std::max(0, log_j.size() - max_log_size); i < log_j.size(); i++) { + log.data.push_back(std::move(Transaction( log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["amount"].asUInt(), - log_j[i]["time"].asUInt64())); + log_j[i]["time"].asUInt64()))); } } }