Skip to content

Commit

Permalink
refactor: simplify comparator in rpc/governance
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Dec 17, 2023
1 parent aab329b commit 15a1fb9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,13 @@ static UniValue gobject_list_prepared(const JSONRPCRequest& request)
std::vector<const Governance::Object*> vecObjects = wallet->GetGovernanceObjects();
// Sort the vector by the object creation time/hex data
std::sort(vecObjects.begin(), vecObjects.end(), [](const Governance::Object* a, const Governance::Object* b) {
bool fGreater = a->time > b->time;
bool fEqual = a->time == b->time;
bool fHexGreater = a->GetDataAsHexString() > b->GetDataAsHexString();
return fGreater || (fEqual && fHexGreater);
if (a->time != b->time) return a->time < b->time;
return a->GetDataAsHexString() < b->GetDataAsHexString();
});

UniValue jsonArray(UniValue::VARR);
auto it = vecObjects.rbegin() + std::max<int>(0, vecObjects.size() - nCount);
while (it != vecObjects.rend()) {
jsonArray.push_back((*it++)->ToJson());
for (auto it = vecObjects.begin() + std::max<int>(0, vecObjects.size() - nCount); it != vecObjects.end(); ++it) {
jsonArray.push_back((*it)->ToJson());
}

return jsonArray;
Expand Down

0 comments on commit 15a1fb9

Please sign in to comment.