🐎 SendFunds lock time decreased

This commit is contained in:
EntireTwix 2021-04-21 15:44:27 -07:00
parent 32ea81bac2
commit 491f5f9adf

View file

@ -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
}
} }
} }