mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
refactor: simplify comparator in rpc/governance
This commit is contained in:
parent
4083fff0b2
commit
b2ad5302ce
@ -271,16 +271,13 @@ static UniValue gobject_list_prepared(const JSONRPCRequest& request)
|
|||||||
std::vector<const Governance::Object*> vecObjects = wallet->GetGovernanceObjects();
|
std::vector<const Governance::Object*> vecObjects = wallet->GetGovernanceObjects();
|
||||||
// Sort the vector by the object creation time/hex data
|
// Sort the vector by the object creation time/hex data
|
||||||
std::sort(vecObjects.begin(), vecObjects.end(), [](const Governance::Object* a, const Governance::Object* b) {
|
std::sort(vecObjects.begin(), vecObjects.end(), [](const Governance::Object* a, const Governance::Object* b) {
|
||||||
bool fGreater = a->time > b->time;
|
if (a->time != b->time) return a->time < b->time;
|
||||||
bool fEqual = a->time == b->time;
|
return a->GetDataAsHexString() < b->GetDataAsHexString();
|
||||||
bool fHexGreater = a->GetDataAsHexString() > b->GetDataAsHexString();
|
|
||||||
return fGreater || (fEqual && fHexGreater);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
UniValue jsonArray(UniValue::VARR);
|
UniValue jsonArray(UniValue::VARR);
|
||||||
auto it = vecObjects.rbegin() + std::max<int>(0, vecObjects.size() - nCount);
|
for (auto it = vecObjects.begin() + std::max<int>(0, vecObjects.size() - nCount); it != vecObjects.end(); ++it) {
|
||||||
while (it != vecObjects.rend()) {
|
jsonArray.push_back((*it)->ToJson());
|
||||||
jsonArray.push_back((*it++)->ToJson());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
|
Loading…
Reference in New Issue
Block a user