mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
✨ FBE
This commit is contained in:
parent
78f7f34f63
commit
727e4ab4b8
2 changed files with 26 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <json/json.h> //to be removed later
|
#include <json/json.h> //to be removed later
|
||||||
#include "xxhash_str.h"
|
#include "xxhash_str.h"
|
||||||
|
#include "bank_dom_final_models.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct User
|
struct User
|
||||||
|
|
@ -15,6 +16,8 @@ struct User
|
||||||
User(uint32_t init_bal, XXH64_hash_t init_pass) noexcept;
|
User(uint32_t init_bal, XXH64_hash_t init_pass) noexcept;
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
User(uint32_t init_bal, XXH64_hash_t init_pass, const Json::Value &log_j) noexcept;
|
User(uint32_t init_bal, XXH64_hash_t init_pass, const Json::Value &log_j) noexcept;
|
||||||
|
User(const bank_dom::User &u) noexcept;
|
||||||
|
bank_dom::User Encode() const noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Json::Value Serialize() const; //to be removed later
|
Json::Value Serialize() const; //to be removed later
|
||||||
|
|
|
||||||
46
src/user.cpp
46
src/user.cpp
|
|
@ -15,38 +15,38 @@ User::User(uint32_t init_bal, const std::string &init_pass) noexcept : balance(i
|
||||||
* @param init_pass
|
* @param init_pass
|
||||||
*/
|
*/
|
||||||
User::User(uint32_t init_bal, XXH64_hash_t init_pass) noexcept : balance(init_bal), password(init_pass) {}
|
User::User(uint32_t init_bal, XXH64_hash_t init_pass) noexcept : balance(init_bal), password(init_pass) {}
|
||||||
|
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
User::User(uint32_t init_bal, XXH64_hash_t init_pass, const Json::Value &log_j) noexcept : balance(init_bal), password(init_pass)
|
User::User(const bank_dom::User &u) noexcept : balance(u.balance), password(u.password)
|
||||||
{
|
{
|
||||||
if (log_j.size())
|
if (u.logs)
|
||||||
{
|
{
|
||||||
for (uint32_t i = (log_j.size() - MAX_LOG_SIZE) * (log_j.size() > MAX_LOG_SIZE); i < log_j.size(); i++)
|
for (uint32_t i = (u.logs.value().data.size() - MAX_LOG_SIZE); i < u.logs.value().data.size(); ++i)
|
||||||
{
|
{
|
||||||
#if MAX_LOG_SIZE == 1
|
const bank_dom::Transaction &temp = u.logs.value().data[i];
|
||||||
log.data = (
|
log.data.emplace_front(temp.from, temp.to, temp.amount, temp.time);
|
||||||
#else
|
|
||||||
log.data.emplace_back(
|
|
||||||
#endif
|
|
||||||
log_j[i]["from"].asCString(),
|
|
||||||
log_j[i]["to"].asCString(),
|
|
||||||
log_j[i]["amount"].asUInt(),
|
|
||||||
#ifdef _USE_32BIT_TIME_T
|
|
||||||
log_j[i]["time"].asUInt()))
|
|
||||||
#else
|
|
||||||
log_j[i]["time"].asUInt64());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
bank_dom::User User::Encode() const noexcept
|
||||||
Json::Value User::Serialize() const
|
|
||||||
{
|
{
|
||||||
Json::Value res;
|
|
||||||
res["balance"] = (Json::UInt)balance;
|
|
||||||
res["password"] = (Json::UInt64)password;
|
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
res["log"] = log.Serialize();
|
if (this->log.data.size())
|
||||||
|
{
|
||||||
|
bank_dom::Logs save_log;
|
||||||
|
save_log.data.reserve(this->log.data.size());
|
||||||
|
for (const Transaction &t : this->log.data)
|
||||||
|
{
|
||||||
|
save_log.data.emplace_back(t.from, t.to, t.amount, t.time);
|
||||||
|
}
|
||||||
|
return bank_dom::User(balance, password, save_log);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return bank_dom::User(balance, password, std::nullopt);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return bank_dom::User(balance, password, std::nullopt);
|
||||||
#endif
|
#endif
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue