Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent rewards calculation to shown in account history #412

Merged
merged 1 commit into from
May 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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