From 0ddd3662acc966344541a6902eac8bf12aa6f445 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 9 Jul 2023 20:15:32 -0700 Subject: [PATCH] David/new balance logic mk3 (#175) * WIP will work on locks * added concurrent test for referral, numbers rn still add up * will change balance table to be a view instead of a table * merged in devel. will proceed with migrations for rpc_stats_v2 and referral * WIP * WIP * WIP compiling * gotta add the balance_v2 view * about to add balance view * stupid missing closing param * compiles again, now i will just have to implement the raw sql * need to paste the real query and play with it * ok now on to testing * addresses many comments in PR * app works for simple unauthorized access. will look into tests * some tests pass, referral logic tests fail * not sure why the test is failing * invalidate cache for admin, will check for more possible targets * user balance decrease test works * all tests pass * changed to active model --------- Co-authored-by: yenicelik --- web3_proxy/src/stats/mod.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index ef04de3a..bc70ecb2 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -447,21 +447,16 @@ impl BufferedRpcQueryStats { { trace!("Adding sender bonus balance"); // TODO: Should it be Unchanged, or do we have to load all numbers there again .. - new_referee_entity = referee::ActiveModel { - id: sea_orm::Unchanged(Default::default()), - one_time_bonus_applied_for_referee: sea_orm::Set(bonus_for_user), - credits_applied_for_referrer: sea_orm::Unchanged(Default::default()), - referral_start_date: sea_orm::Unchanged(Default::default()), - used_referral_code: sea_orm::Unchanged(Default::default()), - user_id: sea_orm::Unchanged(Default::default()), - }; + let mut new_referral_entity = referral_entity.clone().into_active_model(); + new_referral_entity.one_time_bonus_applied_for_referee = + sea_orm::Set(bonus_for_user); // Update the cache { // Also no need to invalidate the cache here, just by itself user_balance.total_deposits += bonus_for_user; } // The resulting field will not be read again, so I will not try to turn the ActiveModel into a Model one - new_referee_entity = new_referee_entity.save(&txn).await?; + new_referral_entity = new_referral_entity.save(&txn).await?; } // Apply the bonus to the referrer if they are premium right now