mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 20:47:10 +11:00
🐎 SendFunds lock time decreased
This commit is contained in:
parent
32ea81bac2
commit
491f5f9adf
1 changed files with 21 additions and 19 deletions
|
|
@ -80,27 +80,29 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
//if A exists, A can afford it, and A's password matches
|
//if A exists, A can afford it, and A's password matches
|
||||||
bool state = false;
|
|
||||||
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //because SendFunds requires 3 locking operations
|
|
||||||
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
|
||||||
if (state = (a.balance >= amount) && (a.password == XXH3_64bits(attempt.data(), attempt.size())))
|
|
||||||
{
|
|
||||||
a.balance -= amount;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (state)
|
|
||||||
{
|
{
|
||||||
//if B doesnt exist
|
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //because SendFunds requires 3 locking operations
|
||||||
if (!users.modify_if(b_name, [amount](User &b) {
|
bool state = false;
|
||||||
b.balance += amount;
|
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
||||||
}))
|
if (state = (a.balance >= amount) && (a.password == XXH3_64bits(attempt.data(), attempt.size())))
|
||||||
|
{
|
||||||
|
a.balance -= amount;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (state)
|
||||||
{
|
{
|
||||||
//attempt to refund if A exist
|
//if B doesnt exist
|
||||||
users.modify_if(a_name, [amount](User &a) {
|
if (!users.modify_if(b_name, [amount](User &b) {
|
||||||
a.balance += amount;
|
b.balance += amount;
|
||||||
});
|
}))
|
||||||
state = false; //because had to refund transaction
|
{
|
||||||
|
//attempt to refund if A exist
|
||||||
|
users.modify_if(a_name, [amount](User &a) {
|
||||||
|
a.balance += amount;
|
||||||
|
});
|
||||||
|
state = false; //because had to refund transaction
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue