From 2682bd0e9f69b28f8c210471f1c8979c88f21800 Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Fri, 21 May 2021 10:54:01 +0300 Subject: [PATCH] Prevent rewards calculation to shown in account history Signed-off-by: Anthony Fieroni --- src/masternodes/mn_checks.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index 7b86235598..a6d018851e 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -597,8 +597,15 @@ class CCustomTxVisitor : public boost::static_visitor return Res::Ok(); } + // we need proxy view to prevent add/sub balance record + void CalculateOwnerRewards(const CScript& owner) const { + CCustomCSView view(mnview); + view.CalculateOwnerRewards(owner, height); + view.Flush(); + } + Res subBalanceDelShares(const CScript& owner, const CBalances& balance) const { - mnview.CalculateOwnerRewards(owner, height); + CalculateOwnerRewards(owner); auto res = mnview.SubBalances(owner, balance); if (!res) { return Res::ErrCode(CustomTxErrCodes::NotEnoughBalance, res.msg); @@ -607,7 +614,7 @@ class CCustomTxVisitor : public boost::static_visitor } Res addBalanceSetShares(const CScript& owner, const CBalances& balance) const { - mnview.CalculateOwnerRewards(owner, height); + CalculateOwnerRewards(owner); auto res = mnview.AddBalances(owner, balance); return !res ? res : setShares(owner, balance.balances); } @@ -801,7 +808,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!minted) { return minted; } - mnview.CalculateOwnerRewards(*mintable.val, height); + CalculateOwnerRewards(*mintable.val); auto res = mnview.AddBalance(*mintable.val, CTokenAmount{kv.first, kv.second}); if (!res) { return res; @@ -908,8 +915,8 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!res) { return res; } - mnview.CalculateOwnerRewards(obj.from, height); - mnview.CalculateOwnerRewards(obj.to, height); + CalculateOwnerRewards(obj.from); + CalculateOwnerRewards(obj.to); res = mnview.SubBalance(obj.from, {obj.idTokenFrom, obj.amountFrom}); return !res ? res : mnview.AddBalance(obj.to, tokenAmount); }, static_cast(height)); @@ -941,7 +948,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor } for (const auto& kv : obj.from) { - mnview.CalculateOwnerRewards(kv.first, height); + CalculateOwnerRewards(kv.first); auto res = mnview.SubBalances(kv.first, kv.second); if (!res) { return res; @@ -997,7 +1004,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor auto res = pool.RemoveLiquidity(amount.nValue, [&] (CAmount amountA, CAmount amountB) { - mnview.CalculateOwnerRewards(from, height); + CalculateOwnerRewards(from); CBalances balances{TAmounts{{pool.idTokenA, amountA}, {pool.idTokenB, amountB}}}; return mnview.AddBalances(from, balances); });