Skip to content

Commit

Permalink
Prevent rewards calculation to shown in account history (#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Fieroni <[email protected]>
  • Loading branch information
bvbfan authored May 21, 2021
1 parent b9469be commit 5351e3f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,15 @@ class CCustomTxVisitor : public boost::static_visitor<Res>
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);
Expand All @@ -607,7 +614,7 @@ class CCustomTxVisitor : public boost::static_visitor<Res>
}

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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<int>(height));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 5351e3f

Please sign in to comment.