diff --git a/include/bank.h b/include/bank.h index 32d50e2..2eea179 100644 --- a/include/bank.h +++ b/include/bank.h @@ -58,12 +58,10 @@ public: int_fast8_t AdminDelUser(const std::string &name, const std::string &attempt) noexcept; bool Contains(const std::string &name) const noexcept; - int_fast8_t AdminVerifyPass(const std::string &attempt) noexcept; + bool AdminVerifyPass(const std::string &attempt) noexcept; //interall used int_fast8_t SetBal(const std::string &name, const std::string &attempt, uint32_t amount) noexcept; void Save(); void Load(); -}; - -//TODO make branchless \ No newline at end of file +}; \ No newline at end of file diff --git a/src/bank.cpp b/src/bank.cpp index 2a05051..1d4cb34 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -76,8 +76,9 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam if constexpr (max_log_size > 0) { Transaction temp(a_name, b_name, amount); + Transaction temp_copy(temp); std::shared_lock lock{send_funds_l}; - users.modify_if(a_name, [&temp, &state, amount](User &a) { + users.modify_if(a_name, [&temp_copy, &state, amount](User &a) { //if A can afford it if (a.balance < amount) { @@ -86,7 +87,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam else { a.balance -= amount; - a.log.AddTrans(Transaction(temp)); + a.log.AddTrans(std::move(temp_copy)); state = {k200OK, "Transfer successful!"}; } }); @@ -253,9 +254,9 @@ bool Bank::Contains(const std::string &name) const noexcept { return users.contains(name); } -int_fast8_t Bank::AdminVerifyPass(const std::string &attempt) noexcept +bool Bank::AdminVerifyPass(const std::string &attempt) noexcept { - return (admin_pass == attempt) ? true : ErrorResponse::WrongPassword; + return (admin_pass == attempt); } int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, uint32_t amount) noexcept