mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
changed order of conditionals out of preference
This commit is contained in:
parent
fa9d6e4aa4
commit
a9b629ee72
1 changed files with 19 additions and 19 deletions
38
src/bank.cpp
38
src/bank.cpp
|
|
@ -118,24 +118,12 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!state)
|
if (state)
|
||||||
{
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
//if B doesnt exist
|
//if B doesnt exist
|
||||||
if (!users.modify_if(b_name, [amount](User &b) {
|
if (users.modify_if(b_name, [amount](User &b) {
|
||||||
b.balance += amount;
|
b.balance += amount;
|
||||||
}))
|
}))
|
||||||
{
|
|
||||||
//attempt to refund if A exist
|
|
||||||
users.modify_if(a_name, [amount](User &a) {
|
|
||||||
a.balance += amount;
|
|
||||||
});
|
|
||||||
return ErrorResponse::UserNotFound; //because had to refund transaction
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if constexpr (max_log_size)
|
if constexpr (max_log_size)
|
||||||
{
|
{
|
||||||
|
|
@ -150,6 +138,18 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//attempt to refund if A exist
|
||||||
|
users.modify_if(a_name, [amount](User &a) {
|
||||||
|
a.balance += amount;
|
||||||
|
});
|
||||||
|
return ErrorResponse::UserNotFound; //because had to refund transaction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +256,11 @@ void Bank::Save()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!temp.isNull())
|
if (temp.isNull())
|
||||||
|
{
|
||||||
|
throw std::invalid_argument("Saving Failed\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::ofstream user_save("../users.json");
|
std::ofstream user_save("../users.json");
|
||||||
Json::StreamWriterBuilder builder;
|
Json::StreamWriterBuilder builder;
|
||||||
|
|
@ -264,10 +268,6 @@ void Bank::Save()
|
||||||
writer->write(temp, &user_save);
|
writer->write(temp, &user_save);
|
||||||
user_save.close();
|
user_save.close();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::invalid_argument("Saving Failed\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOT THREAD SAFE, BY NO MEANS SHOULD THIS BE CALLED WHILE RECEIEVING REQUESTS
|
//NOT THREAD SAFE, BY NO MEANS SHOULD THIS BE CALLED WHILE RECEIEVING REQUESTS
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue