mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 20:47:10 +11:00
✨ Logging Saved
This commit is contained in:
parent
0a919a07c8
commit
eb9b724be5
4 changed files with 36 additions and 20 deletions
|
|
@ -4,13 +4,6 @@
|
|||
"address": "0.0.0.0",
|
||||
"port": 80,
|
||||
"https": false
|
||||
},
|
||||
{
|
||||
"address": "0.0.0.0",
|
||||
"port": 443,
|
||||
"https": true,
|
||||
"cert": "",
|
||||
"key": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public:
|
|||
return users.try_emplace_l(
|
||||
name, [](User &) {}, std::move(init_pass));
|
||||
}
|
||||
bool AdminAddUser(const std::string &attempt, std::string &&name, uint_fast32_t init_bal, std::string &&init_pass)
|
||||
bool AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass)
|
||||
{
|
||||
if (name.size() > 50)
|
||||
{
|
||||
|
|
@ -69,7 +69,7 @@ public:
|
|||
return users.erase_if(name, [this, &attempt](const User &) { return (admin_pass == attempt); });
|
||||
}
|
||||
|
||||
bool SendFunds(const std::string &a_name, const std::string &b_name, uint_fast32_t amount, const std::string &attempt)
|
||||
bool SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount, const std::string &attempt)
|
||||
{
|
||||
//cant send money to self, from self or amount is 0
|
||||
if (a_name == b_name || !amount)
|
||||
|
|
@ -173,15 +173,10 @@ public:
|
|||
if (u.password != XXH3_64bits(attempt.data(), attempt.size()))
|
||||
{
|
||||
res = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < u.log.data.size() && u.log.data[i].amount; ++i)
|
||||
else
|
||||
{
|
||||
res[i]["to"] = u.log.data[i].to;
|
||||
res[i]["from"] = u.log.data[i].from;
|
||||
res[i]["amount"] = u.log.data[i].amount;
|
||||
res[i]["time"] = (Json::UInt64)u.log.data[i].time;
|
||||
res = u.log.Serialize();
|
||||
}
|
||||
}))
|
||||
{
|
||||
|
|
@ -232,7 +227,7 @@ public:
|
|||
user_save.close();
|
||||
for (const auto &u : temp.getMemberNames())
|
||||
{
|
||||
users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()));
|
||||
users.try_emplace(u, temp[u]["balance"].asUInt(), std::move(temp[u]["password"].asUInt64()), std::move(temp[u]["log"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,18 @@ struct Log
|
|||
++end;
|
||||
}
|
||||
}
|
||||
Json::Value Serialize() const
|
||||
{
|
||||
Json::Value res;
|
||||
for (uint32_t i = 0; i < data.size() && data[i].amount; ++i)
|
||||
{
|
||||
res[i]["to"] = data[i].to;
|
||||
res[i]["from"] = data[i].from;
|
||||
res[i]["amount"] = data[i].amount;
|
||||
res[i]["time"] = (Json::UInt64)data[i].time;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
//[*][*][]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
struct User
|
||||
{
|
||||
uint_fast32_t balance = 0;
|
||||
uint32_t balance = 0;
|
||||
uint64_t password;
|
||||
Log log;
|
||||
|
||||
|
|
@ -22,14 +22,30 @@ struct User
|
|||
* @param init_bal initial balance
|
||||
* @param init_pass initial password
|
||||
*/
|
||||
User(uint_fast32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
|
||||
User(uint_fast32_t init_bal, uint64_t init_pass) : balance(init_bal), password(init_pass) {}
|
||||
User(uint32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
|
||||
|
||||
/**
|
||||
* @brief User Constructor for loading
|
||||
*
|
||||
* @param init_bal
|
||||
* @param init_pass
|
||||
*/
|
||||
User(uint32_t init_bal, uint64_t init_pass, Json::Value&& log_j) : balance(init_bal), password(init_pass)
|
||||
{
|
||||
log.data.resize(log_j.size());
|
||||
log.end = log_j.size();
|
||||
for(uint32_t i = 0; i < log_j.size(); ++i)
|
||||
{
|
||||
log.data[i] = std::move(Transaction(log_j[i]["from"].asCString(), log_j[i]["to"].asCString(), log_j[i]["balance"].asUInt()));
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value Serialize() const
|
||||
{
|
||||
Json::Value res;
|
||||
res["balance"] = (Json::UInt)balance;
|
||||
res["password"] = (Json::UInt64)password;
|
||||
res["log"] = log.Serialize();
|
||||
return res;
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue