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

Revert ForEachAccount changes #1787

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/masternodes/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include <masternodes/accounts.h>

void CAccountsView::ForEachAccount(std::function<bool(const CScript &)> callback, const CScript &start) {
ForEach<ByHeightKey, CScript, uint32_t>(
[&callback](const CScript &owner, CLazySerialize<uint32_t>) { return callback(owner); }, start);
}

void CAccountsView::ForEachBalance(std::function<bool(const CScript &, const CTokenAmount &)> callback,
const BalanceKey &start) {
ForEach<ByBalanceKey, BalanceKey, CAmount>(
Expand Down
1 change: 1 addition & 0 deletions src/masternodes/accounts.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct CFuturesUserValue {

class CAccountsView : public virtual CStorageView {
public:
void ForEachAccount(std::function<bool(const CScript &)> callback, const CScript &start = {});
void ForEachBalance(std::function<bool(const CScript &, const CTokenAmount &)> callback,
const BalanceKey &start = {});
CTokenAmount GetBalance(const CScript &owner, DCT_ID tokenID) const;
Expand Down
14 changes: 6 additions & 8 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,13 @@ UniValue gettokenbalances(const JSONRPCRequest& request) {
// CalculateOwnerRewards or if it needs to be called.
CScript lastCalculatedOwner;

mnview.ForEachBalance([&](const CScript &owner, CTokenAmount balance) {
if (IsMineCached(*pwallet, owner) == ISMINE_SPENDABLE) {
if (lastCalculatedOwner != owner) {
mnview.CalculateOwnerRewards(owner, targetHeight);
lastCalculatedOwner = owner;
}
totalBalances.Add(balance);
mnview.ForEachAccount([&](CScript const & account) {
if (IsMineCached(*pwallet, account) == ISMINE_SPENDABLE) {
mnview.CalculateOwnerRewards(account, targetHeight);
mnview.ForEachBalance([&](CScript const & owner, CTokenAmount balance) {
return account == owner && totalBalances.Add(balance);
}, {account, DCT_ID{}});
}

return true;
});

Expand Down