mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 20:47:10 +11:00
User constructor now enforces logging rule
This commit is contained in:
parent
ab11101611
commit
69121557a9
2 changed files with 11 additions and 13 deletions
|
|
@ -13,7 +13,7 @@ struct Log
|
||||||
{
|
{
|
||||||
for (auto i = data.size() - 1; i > 0; i--) // Make room at the back
|
for (auto i = data.size() - 1; i > 0; i--) // Make room at the back
|
||||||
{
|
{
|
||||||
data[i - 1] == std::move(data[i])
|
data[i - 1] == std::move(data[i]) // Shifts everything left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data.size() == data.capacity()) // If we haven't hit the max but hit capacity
|
else if (data.size() == data.capacity()) // If we haven't hit the max but hit capacity
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
|
||||||
struct User
|
struct User
|
||||||
|
|
@ -35,19 +36,16 @@ struct User
|
||||||
{
|
{
|
||||||
if (log_j.size())
|
if (log_j.size())
|
||||||
{
|
{
|
||||||
if (max_log_size > (log_j.size() + pre_log_size)) //if current imported log's size + prefetch amount is less then max
|
auto 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(std::min(size, max_log_size)); // Ensures that the log size is under `max_log_size`
|
||||||
|
for (uint32_t i = 0; i < log.size(); i++) // Matches the logs
|
||||||
{
|
{
|
||||||
//std::cout << "allocating " << log_j.size() + pre_log_size << '\n';
|
log.data[i] = std::move(Transaction(
|
||||||
log.data.reserve(log_j.size() + pre_log_size); //allocate that amount
|
log_j[i]["from"].asCString(),
|
||||||
}
|
log_j[i]["to"].asCString(),
|
||||||
else
|
log_j[i]["amount"].asUInt(),
|
||||||
{
|
log_j[i]["time"].asUInt64()
|
||||||
//std::cout << "allocating " << max_log_size << '\n';
|
));
|
||||||
log.data.reserve(max_log_size); //allocate max amount
|
|
||||||
}
|
|
||||||
for (uint32_t i = 0; 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())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue