mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-19 01:22:14 +11:00
moved state&comment
This commit is contained in:
parent
565dd02cc4
commit
81930874db
1 changed files with 4 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include <vector>
|
||||||
#include "parallel-hashmap/parallel_hashmap/phmap.h"
|
#include "parallel-hashmap/parallel_hashmap/phmap.h"
|
||||||
#include "user.hpp"
|
#include "user.hpp"
|
||||||
|
|
||||||
|
|
@ -58,8 +59,6 @@ public:
|
||||||
|
|
||||||
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, uint_fast32_t amount, const std::string &attempt)
|
||||||
{
|
{
|
||||||
//if A exists, A can afford it, and A's password matches
|
|
||||||
bool state = false;
|
|
||||||
|
|
||||||
//cant send money to self, from self
|
//cant send money to self, from self
|
||||||
if (a_name == b_name)
|
if (a_name == b_name)
|
||||||
|
|
@ -67,6 +66,8 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if A exists, A can afford it, and A's password matches
|
||||||
|
bool state = false;
|
||||||
std::shared_lock<std::shared_mutex> lock{save_lock}; //because SendFunds requires 3 locking operations
|
std::shared_lock<std::shared_mutex> lock{save_lock}; //because SendFunds requires 3 locking operations
|
||||||
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
||||||
if (state = (a.balance >= amount) && (a.password == attempt), state)
|
if (state = (a.balance >= amount) && (a.password == attempt), state)
|
||||||
|
|
@ -145,6 +146,7 @@ public:
|
||||||
std::ofstream user_save("users.json");
|
std::ofstream user_save("users.json");
|
||||||
Json::Value temp;
|
Json::Value temp;
|
||||||
|
|
||||||
|
//loading info into json temp
|
||||||
{
|
{
|
||||||
std::unique_lock<std::shared_mutex> lock{save_lock}; //grabbing it from any busy add/del opperations
|
std::unique_lock<std::shared_mutex> lock{save_lock}; //grabbing it from any busy add/del opperations
|
||||||
for (const auto &u : users)
|
for (const auto &u : users)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue