mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🐎 improved SendFunds()
This commit is contained in:
parent
5ffd655de5
commit
1c5f2e1ae6
3 changed files with 9 additions and 9 deletions
|
|
@ -10,6 +10,6 @@ struct Transaction
|
||||||
time_t time = 0;
|
time_t time = 0;
|
||||||
|
|
||||||
Transaction();
|
Transaction();
|
||||||
Transaction(std::string &&from_str, std::string &&to_str, uint32_t amount, time_t time);
|
Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount, time_t time);
|
||||||
Transaction(std::string &&from_str, std::string &&to_str, uint32_t amount);
|
Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
10
src/bank.cpp
10
src/bank.cpp
|
|
@ -60,7 +60,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
|
||||||
BankResponse state;
|
BankResponse state;
|
||||||
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //about 10% of this function's cost
|
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //about 10% of this function's cost
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
Transaction temp(std::string(a_name), std::string(b_name), amount);
|
Transaction temp(a_name, b_name, amount);
|
||||||
if (!users.modify_if(a_name, [&temp, &state, amount](User &a) {
|
if (!users.modify_if(a_name, [&temp, &state, amount](User &a) {
|
||||||
#else
|
#else
|
||||||
if (!users.modify_if(a_name, [&state, amount](User &a) {
|
if (!users.modify_if(a_name, [&state, amount](User &a) {
|
||||||
|
|
@ -120,11 +120,11 @@ BankResponse Bank::SetBal(const std::string &name, uint32_t amount) noexcept
|
||||||
#if CONSERVATIVE_DISK_SAVE
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
save_flag.SetChangesOn();
|
save_flag.SetChangesOn();
|
||||||
#endif
|
#endif
|
||||||
return BankResponse(k200OK, "Balance set!");
|
return {k200OK, "Balance set!"};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return BankResponse(k404NotFound, "User not found");
|
return {k404NotFound, "User not found"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Bank::Contains(const std::string &name) const noexcept
|
bool Bank::Contains(const std::string &name) const noexcept
|
||||||
|
|
@ -140,7 +140,7 @@ BankResponse Bank::AddUser(std::string &&name, std::string &&init_pass) noexcept
|
||||||
{
|
{
|
||||||
if (!ValidUsrname(name))
|
if (!ValidUsrname(name))
|
||||||
{
|
{
|
||||||
return BankResponse(k400BadRequest, "Invalid Name, breaks size and/or character restrictions");
|
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
|
|
@ -153,7 +153,7 @@ BankResponse Bank::AdminAddUser(std::string &&name, uint32_t init_bal, std::stri
|
||||||
{
|
{
|
||||||
if (!ValidUsrname(name))
|
if (!ValidUsrname(name))
|
||||||
{
|
{
|
||||||
return BankResponse(k400BadRequest, "Invalid Name, breaks size and/or character restrictions");
|
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_lock<std::shared_mutex> lock{size_l};
|
std::shared_lock<std::shared_mutex> lock{size_l};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
|
|
||||||
Transaction::Transaction() = default;
|
Transaction::Transaction() = default;
|
||||||
Transaction::Transaction(std::string &&from_str, std::string &&to_str, uint32_t amount, time_t time_val) : from(from_str), to(to_str), amount(amount), time(time_val) {}
|
Transaction::Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount, time_t time_val) : from(from_str), to(to_str), amount(amount), time(time_val) {}
|
||||||
Transaction::Transaction(std::string &&from_str, std::string &&to_str, uint32_t amount) : from(from_str), to(to_str), amount(amount) { time = std::time(NULL); }
|
Transaction::Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount) : from(from_str), to(to_str), amount(amount) { time = std::time(NULL); }
|
||||||
Loading…
Reference in a new issue