🐛 saving of logs bug fixed

This commit is contained in:
EntireTwix 2021-05-20 22:00:52 -07:00
parent 59417ccebf
commit 0d7b7b5df2
4 changed files with 29 additions and 24 deletions

View file

@ -4,13 +4,6 @@
"address": "0.0.0.0", "address": "0.0.0.0",
"port": 80, "port": 80,
"https": false "https": false
},
{
"address": "0.0.0.0",
"port": 443,
"https": true,
"cert": "",
"key": ""
} }
] ]
} }

View file

@ -175,15 +175,15 @@ public:
if constexpr (max_log_size) if constexpr (max_log_size)
{ {
if (!users.if_contains(name, [&res, &attempt](const User &u) { if (!users.if_contains(name, [&res, &attempt](const User &u) {
if (u.password != XXH3_64bits(attempt.data(), attempt.size())) if (u.password != XXH3_64bits(attempt.data(), attempt.size()))
{ {
res = 0; res = 0;
} }
else else
{ {
res = u.log.Serialize(); res = u.log.Serialize();
} }
})) }))
{ {
return -1; return -1;
} }
@ -233,7 +233,7 @@ public:
user_save.close(); user_save.close();
for (const auto &u : temp.getMemberNames()) 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"])); users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()), std::move(temp[u]["log"]));
} }

View file

@ -12,7 +12,7 @@ struct Log
{ {
if (data.size() == end) 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) for (uint32_t i = end; i > 0; --i)
{ {
@ -27,7 +27,7 @@ struct Log
Json::Value Serialize() const Json::Value Serialize() const
{ {
Json::Value res; 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]["to"] = data[i].to;
res[i]["from"] = data[i].from; res[i]["from"] = data[i].from;

View file

@ -31,14 +31,26 @@ struct User
* @param init_pass * @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) : 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); if (max_log_size > 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)
{ {
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())); log.data[i] = std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["balance"].asUInt()));
} }
} }