Repository navigation
Expand file tree
/
Copy pathmasternodemodel.cpp
More file actions
599 lines (552 loc) · 24 KB
/
Copy pathmasternodemodel.cpp
File metadata and controls
599 lines (552 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
// Copyright (c) 2021-2026 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/masternodemodel.h>
#include <addresstype.h>
#include <bls/bls.h>
#include <chainparams.h>
#include <evo/types.h>
#include <interfaces/node.h>
#include <key_io.h>
#include <pubkey.h>
#include <script/script.h>
#include <qt/bitcoinunits.h>
#include <qt/clientmodel.h>
#include <qt/guiutil.h>
#include <QHash>
#include <QObject>
#include <QSettings>
#include <QStringList>
#include <univalue.h>
#include <set>
namespace {
std::optional<QString> JoinArray(const UniValue& arr)
{
if (!arr.isArray()) return std::nullopt;
QStringList list;
for (size_t i = 0; i < arr.size(); ++i) {
if (arr[i].isStr()) {
list << QString::fromStdString(arr[i].get_str());
}
}
return list.join(", ");
}
} // anonymous namespace
MasternodeStandby::StandbyRecord MasternodeStandby::SavedDate(const QString& pro_tx_hash)
{
QSettings settings;
if (const QString date{settings.value(QStringLiteral("sharedmn/standby/") + pro_tx_hash).toString()};
!date.isEmpty()) {
return {/*saved=*/true, date};
}
return {};
}
MasternodeEntry::MasternodeEntry(const interfaces::MnEntryCPtr& dmn, const QString& collateral_address, int next_payment_height) :
m_banned{dmn->isBanned()},
m_shared{dmn->isShared()},
m_early_penalty{dmn->getEarlyPenalty()},
m_early_period_blocks{dmn->getEarlyPeriodBlocks()},
m_shares{dmn->getShares()},
m_last_paid_height{dmn->getLastPaidHeight()},
m_next_payment_height{next_payment_height},
m_pose_penalty{dmn->getPoSePenalty()},
m_registered_height{dmn->getRegisteredHeight()},
m_dmn{dmn},
m_type{dmn->getType()},
m_collateral_address{collateral_address},
m_collateral_outpoint{QString::fromStdString(dmn->getCollateralOutpoint().ToStringShort())},
m_protx_hash{QString::fromStdString(dmn->getProTxHash().ToString())},
m_type_description{dmn->isShared() ? QObject::tr("Shared") : QString::fromStdString(std::string(GetMnType(dmn->getType()).description))},
m_voting_address{QString::fromStdString(EncodeDestination(PKHash(dmn->getKeyIdVoting())))},
m_operator_reward_pct{dmn->getOperatorReward()}
{
const CService primary_service{dmn->getNetInfoPrimary()};
if (primary_service.IsValid()) {
m_service = QString::fromStdString(primary_service.ToStringAddrPort());
const auto addr_key{primary_service.GetKey()};
m_service_key = QByteArray(reinterpret_cast<const char*>(addr_key.data()), addr_key.size());
}
// A shared masternode has a null keyIDOwner and its share owners take that
// role instead, so every reader of m_owner_address is guarded by !isShared()
// and this stays UNKNOWN for them
const CKeyID& key_id_owner{dmn->getKeyIdOwner()};
m_owner_address = key_id_owner.IsNull()
? QObject::tr("UNKNOWN")
: QString::fromStdString(EncodeDestination(PKHash(key_id_owner)));
if (m_shared) {
// A fingerprint of the mutable share state (reward scripts, penalty terms) so
// reconcile() refreshes the row after a share update, plus a flat address list
// the text filter matches against
QStringList fingerprint, addresses;
for (const auto& share : m_shares) {
const QString owner{QString::fromStdString(EncodeDestination(PKHash(share.keyIDOwner)))};
QString refund, reward;
if (CTxDestination dest; ExtractDestination(share.scriptRefund, dest)) {
refund = QString::fromStdString(EncodeDestination(dest));
}
if (CTxDestination dest; ExtractDestination(share.rewardScript(), dest)) {
reward = QString::fromStdString(EncodeDestination(dest));
}
fingerprint << QString::number(share.amount) + ":" + owner + ":" + refund + ":" + reward;
addresses << owner << refund << reward;
}
m_shares_fingerprint = fingerprint.join("|") + "|" + QString::number(m_early_period_blocks) + "|" +
QString::number(m_early_penalty);
addresses.removeDuplicates();
m_share_addresses = addresses.join(" ");
}
QStringList payout_addresses;
for (const auto& script_payout : dmn->getScriptPayouts()) {
if (CTxDestination dest; ExtractDestination(script_payout, dest)) {
payout_addresses << QString::fromStdString(EncodeDestination(dest));
}
}
m_payout_addresses = payout_addresses;
m_payout_address = payout_addresses.isEmpty() ? QObject::tr("UNKNOWN") : payout_addresses.join(", ");
if (CTxDestination operator_destination; ExtractDestination(dmn->getScriptOperatorPayout(), operator_destination)) {
m_operator_payout_address = QString::fromStdString(EncodeDestination(operator_destination));
}
if (m_operator_reward_pct) {
m_operator_reward = QString::number(m_operator_reward_pct / 100.0, 'f', 2) + "%";
if (dmn->getScriptOperatorPayout() != CScript()) {
if (!m_operator_payout_address.isEmpty()) {
m_operator_reward += " " + QObject::tr("to %1").arg(m_operator_payout_address);
} else {
m_operator_reward += " " + QObject::tr("to UNKNOWN");
}
} else {
m_operator_reward += " " + QObject::tr("but not claimed");
}
} else {
m_operator_reward = QObject::tr("NONE");
}
// TODO: get rid of this JSON
const auto json{dmn->toJson()};
m_json = QString::fromStdString(json.write(2));
if (const auto& val = json.find_value("collateralHash"); val.isStr()) {
m_collateral_hash = QString::fromStdString(val.get_str());
}
if (const auto& val = json.find_value("collateralIndex"); val.isNum()) {
m_collateral_index = val.getInt<int32_t>();
}
if (const auto& state = json.find_value("state"); state.isObject()) {
if (const auto& val = state.find_value("version"); val.isNum()) {
m_operator_scheme = ProTxVersion::GetBLSScheme(static_cast<uint16_t>(val.getInt<int>()));
}
if (const auto& val = state.find_value("consecutivePayments"); val.isNum()) {
m_consecutive_payments = val.getInt<int32_t>();
}
if (const auto& val = state.find_value("PoSeBanHeight"); val.isNum()) {
m_pose_ban_height = val.getInt<int32_t>();
}
if (const auto& val = state.find_value("PoSeRevivedHeight"); val.isNum()) {
m_pose_revived_height = val.getInt<int32_t>();
}
if (const auto& val = state.find_value("pubKeyOperator"); val.isStr()) {
m_pub_key_operator = QString::fromStdString(val.get_str());
}
if (const auto& val = state.find_value("addresses"); val.isObject()) {
m_network_addresses = JoinArray(val.find_value("core_p2p"));
m_platform_p2p_addresses = JoinArray(val.find_value("platform_p2p"));
m_platform_https_addresses = JoinArray(val.find_value("platform_https"));
}
if (const auto& val = state.find_value("platformNodeID"); val.isStr()) {
m_platform_node_id = QString::fromStdString(val.get_str());
}
}
}
MasternodeEntry::~MasternodeEntry() = default;
QString MasternodeEntry::operatorPubKey(BLSScheme scheme) const
{
CBLSPublicKey key;
if (!m_pub_key_operator || !key.SetHexStr(m_pub_key_operator->toStdString(), m_operator_scheme)) {
return {};
}
return key.IsValid() ? QString::fromStdString(key.ToString(scheme)) : QString{};
}
std::vector<unsigned char> MasternodeEntry::operatorPubKeyBytes() const
{
CBLSPublicKey key;
if (!m_pub_key_operator || !key.SetHexStr(m_pub_key_operator->toStdString(), m_operator_scheme)) {
return {};
}
return key.ToByteVector();
}
QString MasternodeDetailsText(const MasternodeDetails& details)
{
QStringList blocks;
for (const auto& section : details) {
QStringList lines{section.title};
for (const auto& field : section.fields) {
lines << field.label + ": " + field.value;
}
blocks << lines.join('\n');
}
return blocks.join("\n\n");
}
MasternodeDetails MasternodeEntry::details(int current_height, const QSet<int>& my_share_indexes, BitcoinUnits::Unit unit) const
{
// Amounts are copied as plain numbers an amount field accepts, so the unit
// goes into the label
const auto amount = [unit](CAmount value) {
return BitcoinUnits::format(unit, value, /*plussign=*/false, BitcoinUnits::SeparatorStyle::NEVER);
};
const auto address = [](const CScript& script) {
CTxDestination dest;
return ExtractDestination(script, dest) ? QString::fromStdString(EncodeDestination(dest)) : QObject::tr("UNKNOWN");
};
MasternodeDetails ret;
MasternodeDetailSection masternode{QObject::tr("Masternode"), {}};
masternode.fields.push_back({QObject::tr("Masternode Type"), m_type_description});
masternode.fields.push_back({QObject::tr("ProTx Hash"), m_protx_hash});
masternode.fields.push_back({QObject::tr("Registered Height"), QString::number(m_registered_height)});
masternode.fields.push_back({QObject::tr("Last Paid Height"), QString::number(m_last_paid_height)});
if (m_consecutive_payments) {
masternode.fields.push_back({QObject::tr("Consecutive Payments"), QString::number(*m_consecutive_payments)});
}
masternode.fields.push_back(
{QObject::tr("Operator Reward"), QString::number(m_operator_reward_pct / 100.0, 'f', 2) + "%"});
ret.push_back(std::move(masternode));
MasternodeDetailSection keys{QObject::tr("Keys and Addresses"), {}};
if (m_pub_key_operator) {
keys.fields.push_back({QObject::tr("Public Key Operator"), *m_pub_key_operator});
}
if (!m_shared) {
keys.fields.push_back({QObject::tr("Owner Address"), m_owner_address});
keys.fields.push_back({QObject::tr("Payout Address"), m_payout_address});
}
keys.fields.push_back({QObject::tr("Voting Address"), m_voting_address});
ret.push_back(std::move(keys));
MasternodeDetailSection collateral{QObject::tr("Collateral"), {}};
collateral.fields.push_back({QObject::tr("Collateral Address"), m_collateral_address});
if (m_collateral_hash) {
collateral.fields.push_back({QObject::tr("Collateral Hash"), *m_collateral_hash});
}
if (m_collateral_index) {
collateral.fields.push_back({QObject::tr("Collateral Index"), QString::number(*m_collateral_index)});
}
ret.push_back(std::move(collateral));
if (m_shared) {
CAmount total{0};
for (const auto& share : m_shares) {
total += share.amount;
}
for (size_t i = 0; i < m_shares.size(); ++i) {
const auto& share{m_shares[i]};
// Shares are numbered from 1 everywhere the user can see them; the
// RPC index is one lower
const QString title{(my_share_indexes.contains(static_cast<int>(i)) ? QObject::tr("Share %1 (you)")
: QObject::tr("Share %1"))
.arg(i + 1)};
const double pct{total > 0 ? 100.0 * share.amount / total : 0.0};
MasternodeDetailSection section{title, {}};
section.fields.push_back(
{BitcoinUnits::getAmountColumnTitle(unit), amount(share.amount), QString::number(pct, 'f', 1) + "%"});
section.fields.push_back(
{QObject::tr("Owner Address"), QString::fromStdString(EncodeDestination(PKHash(share.keyIDOwner)))});
section.fields.push_back({QObject::tr("Reward Address"), address(share.rewardScript()),
share.scriptReward.empty() ? QObject::tr("same as refund") : QString{}});
section.fields.push_back({QObject::tr("Refund Address"), address(share.scriptRefund)});
ret.push_back(std::move(section));
}
MasternodeDetailSection terms{QObject::tr("Shared Masternode Terms"), {}};
const int64_t early_until{static_cast<int64_t>(m_registered_height) + m_early_period_blocks};
if (m_early_period_blocks == 0) {
terms.fields.push_back({QObject::tr("Early period"), QObject::tr("none")});
} else {
QString note;
if (current_height >= early_until) {
note = QObject::tr("ended");
} else if (current_height > 0) {
note = QObject::tr("about %1 from now")
.arg(GUIUtil::formatBlockDuration(early_until - current_height,
Params().GetConsensus().nPowTargetSpacing));
}
terms.fields.push_back({QObject::tr("Early Period Ends"), QString::number(early_until), note});
}
terms.fields.push_back(
{QObject::tr("Early-exit penalty") + " (" + BitcoinUnits::name(unit) + ")", amount(m_early_penalty)});
const auto standby_record{MasternodeStandby::SavedDate(m_protx_hash)};
terms.fields.push_back({QObject::tr("Standby dissolution"),
standby_record.saved ? QObject::tr("saved on this computer on %1").arg(standby_record.date)
: QObject::tr("not created on this computer")});
ret.push_back(std::move(terms));
}
MasternodeDetailSection network{QObject::tr("Network"), {}};
for (const auto& [label, value] : {std::pair{QObject::tr("Network Addresses"), m_network_addresses},
std::pair{QObject::tr("Platform HTTPS Addresses"), m_platform_https_addresses},
std::pair{QObject::tr("Platform P2P Addresses"), m_platform_p2p_addresses},
std::pair{QObject::tr("Platform Node ID"), m_platform_node_id}}) {
if (value && !value->isEmpty()) network.fields.push_back({label, *value});
}
if (!network.fields.empty()) ret.push_back(std::move(network));
MasternodeDetailSection pose{QObject::tr("Proof of Service"), {}};
pose.fields.push_back({QObject::tr("PoSe Penalty"), QString::number(m_pose_penalty)});
if (m_pose_ban_height && *m_pose_ban_height != -1) {
pose.fields.push_back({QObject::tr("PoSe Ban Height"), QString::number(*m_pose_ban_height)});
}
if (m_pose_revived_height && *m_pose_revived_height != -1) {
pose.fields.push_back({QObject::tr("PoSe Revived Height"), QString::number(*m_pose_revived_height)});
}
ret.push_back(std::move(pose));
return ret;
}
MasternodeModel::MasternodeModel(QObject* parent) :
QAbstractTableModel(parent)
{
refreshIcons();
}
void MasternodeModel::refreshIcons()
{
m_icon_banned = GUIUtil::getIcon("warning", GUIUtil::ThemedColor::RED);
m_icon_enabled = GUIUtil::getIcon("synced", GUIUtil::ThemedColor::GREEN);
}
MasternodeModel::~MasternodeModel() = default;
int MasternodeModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid()) {
return 0;
}
return static_cast<int>(m_data.size());
}
int MasternodeModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid()) {
return 0;
}
return Column::COUNT;
}
QVariant MasternodeModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || !isValidRow(index.row())) {
return {};
}
if (role != Qt::DecorationRole && role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::UserRole && role != Qt::ToolTipRole) {
return {};
}
const auto* entry = m_data[index.row()].get();
if (!entry) {
return {};
}
if (role == Qt::ToolTipRole) {
if (index.column() == Column::TYPE && entry->isShared()) {
return tr("Shared masternode · you hold %1 of %2 shares")
.arg(m_my_share_counts.value(entry->proTxHash(), 0))
.arg(entry->shares().size());
}
if (index.column() == Column::STATUS && m_current_height > 0) {
const int64_t spacing = Params().GetConsensus().nPowTargetSpacing;
if (entry->isBanned()) {
if (auto ban_height = entry->poseBanHeight(); ban_height && *ban_height > 0) {
return tr("Banned for %1").arg(GUIUtil::formatBlockDuration(m_current_height - *ban_height, spacing));
} else {
return tr("Banned");
}
} else {
int32_t active_height = entry->registeredHeight();
if (auto revived_height = entry->poseRevivedHeight(); revived_height && *revived_height > 0) {
active_height = *revived_height;
}
return tr("Active for %1").arg(GUIUtil::formatBlockDuration(m_current_height - active_height, spacing));
}
}
return {};
} else if (role == Qt::DecorationRole) {
if (index.column() == Column::STATUS) {
return entry->isBanned() ? m_icon_banned : m_icon_enabled;
}
return {};
} else if (role == Qt::UserRole) {
return QString{
entry->service() + " " +
entry->typeDescription() + " " +
QString::number(entry->posePenalty()) + " " +
QString::number(entry->registeredHeight()) + " " +
QString::number(entry->lastPaidHeight()) + " " +
(entry->nextPaymentHeight() > 0 ? QString::number(entry->nextPaymentHeight()) : "") + " " +
entry->payoutAddress() + " " +
entry->operatorReward() + " " +
entry->collateralAddress() + " " +
(entry->isShared() ? QString{} : entry->ownerAddress() + " ") +
entry->votingAddress() + " " +
entry->proTxHash() +
(entry->isShared() ? " " + entry->shareAddresses() : QString{})
};
} else if (role == Qt::DisplayRole) {
switch (index.column()) {
case Column::SERVICE:
return entry->service();
case Column::TYPE:
// "Shared" alone says nothing about this wallet's stake in it, and
// the share count is the one number a co-owner wants at a glance
if (entry->isShared()) {
if (const int mine{m_my_share_counts.value(entry->proTxHash(), 0)}; mine > 0) {
return tr("Shared (you hold %1 of %2)").arg(mine).arg(entry->shares().size());
}
return tr("Shared (%1 shares)").arg(entry->shares().size());
}
return entry->typeDescription();
case Column::STATUS:
return {};
case Column::POSE:
return QString::number(entry->posePenalty());
case Column::REGISTERED:
return QString::number(entry->registeredHeight());
case Column::LAST_PAYMENT:
return QString::number(entry->lastPaidHeight());
case Column::NEXT_PAYMENT:
return entry->nextPaymentHeight() > 0 ? QString::number(entry->nextPaymentHeight()) : tr("UNKNOWN");
case Column::OPERATOR_REWARD:
return entry->operatorReward();
case Column::PROTX_HASH:
return entry->proTxHash();
default:
return {};
}
} else if (role == Qt::EditRole) {
// Edit role is used for sorting, return raw values where possible
switch (index.column()) {
case Column::SERVICE:
return entry->serviceKey();
case Column::TYPE:
return entry->isShared() ? TYPE_SHARED : static_cast<int>(entry->type());
case Column::STATUS:
if (m_current_height > 0) {
if (entry->isBanned()) {
// Banned nodes use positive values
if (auto ban_height = entry->poseBanHeight(); ban_height && *ban_height > 0) {
return m_current_height - *ban_height + 1; // +1: freshly banned → 1, never 0
}
return 1; // Unknown ban time, treat as freshly banned
} else {
// Active nodes use negative values
int32_t active_height = entry->registeredHeight();
if (auto revived_height = entry->poseRevivedHeight(); revived_height && *revived_height > 0) {
active_height = *revived_height;
}
return -(m_current_height - active_height);
}
}
return entry->isBanned() ? 1 : 0;
case Column::POSE:
return entry->posePenalty();
case Column::REGISTERED:
return entry->registeredHeight();
case Column::LAST_PAYMENT:
return entry->lastPaidHeight();
case Column::NEXT_PAYMENT:
return entry->nextPaymentHeight();
case Column::OPERATOR_REWARD:
return entry->operatorRewardPct();
case Column::PROTX_HASH:
return entry->proTxHash();
default:
return {};
}
}
return {};
}
QVariant MasternodeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) {
return {};
}
switch (section) {
case Column::SERVICE:
return tr("Service");
case Column::TYPE:
return tr("Type");
case Column::STATUS:
return {};
case Column::POSE:
return tr("PoSe Score");
case Column::REGISTERED:
return tr("Registered");
case Column::LAST_PAYMENT:
return tr("Last Paid");
case Column::NEXT_PAYMENT:
return tr("Next Payment");
case Column::OPERATOR_REWARD:
return tr("Operator Reward");
case Column::PROTX_HASH:
return tr("ProTx Hash");
default:
return {};
}
}
void MasternodeModel::append(std::shared_ptr<MasternodeEntry>&& entry)
{
beginInsertRows({}, rowCount(), rowCount());
m_data.push_back(std::move(entry));
endInsertRows();
}
void MasternodeModel::remove(int row)
{
if (!isValidRow(row)) {
return;
}
beginRemoveRows({}, row, row);
m_data.erase(m_data.begin() + row);
endRemoveRows();
}
void MasternodeModel::reconcile(MasternodeEntryList&& entries)
{
QHash<QString, int> existing;
for (int i = 0; i < static_cast<int>(m_data.size()); ++i) {
existing[m_data[i]->proTxHash()] = i;
}
std::set<int> present;
std::vector<int> changed;
std::vector<std::shared_ptr<MasternodeEntry>> add;
for (auto& entry : entries) {
if (auto it = existing.find(entry->proTxHash()); it != existing.end()) {
int idx = it.value();
present.insert(idx);
if (m_data[idx]->toTie() != entry->toTie()) {
m_data[idx] = std::move(entry);
changed.push_back(idx);
}
} else {
// New entry
add.push_back(std::move(entry));
}
}
// Remove entries no longer present
std::vector<int> removed;
for (int i = static_cast<int>(m_data.size()) - 1; i >= 0; --i) {
if (present.find(i) == present.end()) {
removed.push_back(i);
beginRemoveRows({}, i, i);
m_data.erase(m_data.begin() + i);
endRemoveRows();
}
}
// Emit dataChanged with adjusted indices
for (int idx : changed) {
int offset{0};
for (int removed_idx : removed) {
if (removed_idx < idx) {
++offset;
}
}
int jdx = idx - offset;
Q_EMIT dataChanged(index(jdx, 0), index(jdx, Column::COUNT - 1));
}
// Append new entries
if (!add.empty()) {
int first = static_cast<int>(m_data.size());
int last = first + static_cast<int>(add.size()) - 1;
beginInsertRows({}, first, last);
for (auto& entry : add) {
m_data.push_back(std::move(entry));
}
endInsertRows();
}
}
const MasternodeEntry* MasternodeModel::getEntryAt(const QModelIndex& index) const
{
if (!index.isValid() || !isValidRow(index.row())) {
return nullptr;
}
return m_data[index.row()].get();
}