forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_write.cpp
More file actions
625 lines (581 loc) · 27.4 KB
/
Copy pathcore_write.cpp
File metadata and controls
625 lines (581 loc) · 27.4 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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
// Copyright (c) 2018-2025 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 <evo/assetlocktx.h>
#include <evo/cbtx.h>
#include <evo/deterministicmns.h>
#include <evo/dmnstate.h>
#include <evo/mnhftx.h>
#include <evo/netinfo.h>
#include <evo/providertx.h>
#include <evo/simplifiedmns.h>
#include <evo/smldiff.h>
#include <llmq/commitment.h>
#include <rpc/evo_util.h>
#include <util/std23.h>
#include <core_io.h>
#include <rpc/util.h>
#include <util/check.h>
#include <univalue.h>
#include <map>
#include <string>
namespace {
#define RESULT_MAP_ENTRY(name, type, desc) {name, {type, name, desc}}
const std::map<std::string, RPCResult> RPCRESULT_MAP{{
{"addresses",
{RPCResult::Type::OBJ, "addresses", "Network addresses of the masternode",
{
{RPCResult::Type::ARR, "core_p2p", /*optional=*/true, "Addresses used for protocol P2P",
{{RPCResult::Type::STR, "address", ""}}},
{RPCResult::Type::ARR, "platform_p2p", /*optional=*/true, "Addresses used for Platform P2P",
{{RPCResult::Type::STR, "address", ""}}},
{RPCResult::Type::ARR, "platform_https", /*optional=*/true, "Addresses used for Platform HTTPS API",
{{RPCResult::Type::STR, "address", ""}}},
}}},
RESULT_MAP_ENTRY("collateralAddress", RPCResult::Type::STR, "Dash address used for collateral"),
RESULT_MAP_ENTRY("collateralHash", RPCResult::Type::STR_HEX, "Collateral transaction hash"),
RESULT_MAP_ENTRY("collateralIndex", RPCResult::Type::NUM, "Collateral transaction output index"),
RESULT_MAP_ENTRY("consecutivePayments", RPCResult::Type::NUM, "Consecutive payments masternode has received in payment cycle"),
RESULT_MAP_ENTRY("height", RPCResult::Type::NUM, "Block height"),
RESULT_MAP_ENTRY("inputsHash", RPCResult::Type::STR_HEX, "Hash of all the outpoints of the transaction inputs"),
RESULT_MAP_ENTRY("lastPaidHeight", RPCResult::Type::NUM, "Height masternode was last paid"),
RESULT_MAP_ENTRY("llmqType", RPCResult::Type::NUM, "Quorum type"),
RESULT_MAP_ENTRY("memberIndex", RPCResult::Type::NUM, "Quorum member index"),
RESULT_MAP_ENTRY("merkleRootMNList", RPCResult::Type::STR_HEX, "Merkle root of the masternode list"),
RESULT_MAP_ENTRY("merkleRootQuorums", RPCResult::Type::STR_HEX, "Merkle root of the quorum list"),
RESULT_MAP_ENTRY("operatorPayoutAddress", RPCResult::Type::STR, "Dash address used for operator reward payments"),
RESULT_MAP_ENTRY("operatorReward", RPCResult::Type::NUM, "Fraction in %% of reward shared with the operator between 0 and 10000"),
RESULT_MAP_ENTRY("outpoint", RPCResult::Type::STR_HEX,"The outpoint of the masternode"),
RESULT_MAP_ENTRY("ownerAddress", RPCResult::Type::STR, "Dash address used for payee updates and proposal voting"),
RESULT_MAP_ENTRY("payoutAddress", RPCResult::Type::STR, "Dash address used for masternode reward payments"),
{"payouts",
{RPCResult::Type::ARR, "payouts", "Owner masternode reward payout shares",
{
{RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR, "address", "Dash address used for this owner payout"},
{RPCResult::Type::STR_HEX, "script", "Owner payout scriptPubKey"},
{RPCResult::Type::NUM, "reward", "Owner payout share in basis points"},
}},
}}},
RESULT_MAP_ENTRY("platformHTTPPort", RPCResult::Type::NUM, "TCP port of Platform HTTP API (DEPRECATED, returned only if config option -deprecatedrpc=service is passed)"),
RESULT_MAP_ENTRY("platformNodeID", RPCResult::Type::STR_HEX, "Node ID derived from P2P public key for Platform P2P"),
RESULT_MAP_ENTRY("platformP2PPort", RPCResult::Type::NUM, "TCP port of Platform P2P (DEPRECATED, returned only if config option -deprecatedrpc=service is passed)"),
RESULT_MAP_ENTRY("PoSeBanHeight", RPCResult::Type::NUM, "Height masternode was banned for Proof of Service violations"),
RESULT_MAP_ENTRY("PoSePenalty", RPCResult::Type::NUM, "Proof of Service penalty score"),
RESULT_MAP_ENTRY("PoSeRevivedHeight", RPCResult::Type::NUM, "Height masternode recovered from Proof of Service violations"),
RESULT_MAP_ENTRY("proTxHash", RPCResult::Type::STR_HEX, "Hash of the masternode's initial ProRegTx"),
RESULT_MAP_ENTRY("pubKeyOperator", RPCResult::Type::STR, "BLS public key used for operator signing"),
RESULT_MAP_ENTRY("quorumIndex", RPCResult::Type::NUM, "Quorum index. Relevant for rotation quorums only, 0 for non-rotating quorums"),
RESULT_MAP_ENTRY("quorumHash", RPCResult::Type::STR_HEX, "Hash of the quorum"),
RESULT_MAP_ENTRY("quorumSig", RPCResult::Type::STR_HEX, "BLS recovered threshold signature of quorum"),
RESULT_MAP_ENTRY("registeredHeight", RPCResult::Type::NUM, "Height masternode was registered"),
RESULT_MAP_ENTRY("revocationReason", RPCResult::Type::NUM, "Reason for ProUpRegTx revocation"),
RESULT_MAP_ENTRY("service", RPCResult::Type::STR, "IP address and port of the masternode (DEPRECATED, returned only if config option -deprecatedrpc=service is passed)"),
RESULT_MAP_ENTRY("type", RPCResult::Type::NUM, "Masternode type"),
RESULT_MAP_ENTRY("type_str", RPCResult::Type::STR, "Masternode type (human-readable string)"),
RESULT_MAP_ENTRY("version", RPCResult::Type::NUM, "Special transaction version"),
RESULT_MAP_ENTRY("votingAddress", RPCResult::Type::STR, "Dash address used for voting"),
}};
#undef RESULT_MAP_ENTRY
} // anonymous namespace
RPCResult GetRpcResult(const std::string& key, bool optional, const std::string& override_name)
{
if (const auto it = RPCRESULT_MAP.find(key); it != RPCRESULT_MAP.end()) {
const auto& ret{it->second};
return RPCResult{ret.m_type, override_name.empty() ? ret.m_key_name : override_name, optional, ret.m_description, ret.m_inner};
}
throw NonFatalCheckError(strprintf("Requested invalid RPCResult for nonexistent key \"%s\"", key).c_str(),
__FILE__, __LINE__, __func__);
}
RPCResult CAssetLockPayload::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The asset lock special transaction",
{
GetRpcResult("version"),
{RPCResult::Type::ARR, "creditOutputs", "", {
{RPCResult::Type::OBJ, "", "", {
{RPCResult::Type::NUM, "value", "The value in Dash"},
{RPCResult::Type::NUM, "valueSat", "The value in duffs"},
{RPCResult::Type::OBJ, "scriptPubKey", "", {
{RPCResult::Type::STR, "asm", "The asm"},
{RPCResult::Type::STR_HEX, "hex", "The hex"},
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
}}}}}}
}};
}
UniValue CAssetLockPayload::ToJson() const
{
UniValue outputs(UniValue::VARR);
for (const CTxOut& credit_output : creditOutputs) {
UniValue out(UniValue::VOBJ);
out.pushKV("value", ValueFromAmount(credit_output.nValue));
out.pushKV("valueSat", credit_output.nValue);
UniValue spk(UniValue::VOBJ);
ScriptToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false);
out.pushKV("scriptPubKey", spk);
outputs.push_back(out);
}
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("creditOutputs", outputs);
return ret;
}
RPCResult CAssetUnlockPayload::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The asset unlock special transaction",
{
GetRpcResult("version"),
{RPCResult::Type::NUM, "index", "Index of the transaction"},
{RPCResult::Type::NUM, "fee", "Transaction fee in duffs awarded to the miner"},
{RPCResult::Type::NUM, "requestedHeight", "Payment chain block height known by Platform when signing the withdrawal"},
GetRpcResult("quorumHash"),
GetRpcResult("quorumSig"),
}};
}
UniValue CAssetUnlockPayload::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("index", index);
ret.pushKV("fee", fee);
ret.pushKV("requestedHeight", requestedHeight);
ret.pushKV("quorumHash", quorumHash.ToString());
ret.pushKV("quorumSig", quorumSig.ToString());
return ret;
}
RPCResult CCbTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The coinbase special transaction",
{
GetRpcResult("version"),
GetRpcResult("height"),
GetRpcResult("merkleRootMNList"),
GetRpcResult("merkleRootQuorums", /*optional=*/true),
{RPCResult::Type::NUM, "bestCLHeightDiff", /*optional=*/true, "Blocks between the current block and the last known block with a ChainLock"},
{RPCResult::Type::STR_HEX, "bestCLSignature", /*optional=*/true, "Best ChainLock signature known by the miner"},
{RPCResult::Type::NUM, "creditPoolBalance", /*optional=*/true, "Balance in the Platform credit pool"},
}};
}
UniValue CCbTx::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", std23::to_underlying(nVersion));
ret.pushKV("height", nHeight);
ret.pushKV("merkleRootMNList", merkleRootMNList.ToString());
if (nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) {
ret.pushKV("merkleRootQuorums", merkleRootQuorums.ToString());
if (nVersion >= CCbTx::Version::CLSIG_AND_BALANCE) {
ret.pushKV("bestCLHeightDiff", bestCLHeightDiff);
ret.pushKV("bestCLSignature", bestCLSignature.ToString());
ret.pushKV("creditPoolBalance", ValueFromAmount(creditPoolBalance));
}
}
return ret;
}
// CDeterministicMN::ToJson() defined in evo/deterministicmns.cpp
RPCResult CDeterministicMN::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode's details",
{
GetRpcResult("type_str", /*optional=*/false, /*override_name=*/"type"),
GetRpcResult("proTxHash"),
GetRpcResult("collateralHash"),
GetRpcResult("collateralIndex"),
GetRpcResult("collateralAddress", /*optional=*/true),
GetRpcResult("operatorReward"),
CDeterministicMNState::GetJsonHelp(/*key=*/"state", /*optional=*/false),
}};
}
RPCResult CDeterministicMNState::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode state",
{
{RPCResult::Type::NUM, "version", "Version of the masternode state"},
GetRpcResult("service", /*optional=*/true),
GetRpcResult("addresses"),
GetRpcResult("registeredHeight"),
GetRpcResult("lastPaidHeight"),
GetRpcResult("consecutivePayments"),
GetRpcResult("PoSePenalty"),
GetRpcResult("PoSeRevivedHeight"),
GetRpcResult("PoSeBanHeight"),
GetRpcResult("revocationReason"),
GetRpcResult("ownerAddress"),
GetRpcResult("votingAddress"),
GetRpcResult("platformNodeID", /*optional=*/true),
GetRpcResult("platformP2PPort", /*optional=*/true),
GetRpcResult("platformHTTPPort", /*optional=*/true),
GetRpcResult("payoutAddress", /*optional=*/true),
GetRpcResult("payouts", /*optional=*/true),
GetRpcResult("pubKeyOperator"),
GetRpcResult("operatorPayoutAddress", /*optional=*/true),
}};
}
UniValue CDeterministicMNState::ToJson(MnType nType) const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("version", nVersion);
if (IsServiceDeprecatedRPCEnabled()) {
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
}
obj.pushKV("addresses", GetNetInfoWithLegacyFields(*this, nType));
obj.pushKV("registeredHeight", nRegisteredHeight);
obj.pushKV("lastPaidHeight", nLastPaidHeight);
obj.pushKV("consecutivePayments", nConsecutivePayments);
obj.pushKV("PoSePenalty", nPoSePenalty);
obj.pushKV("PoSeRevivedHeight", nPoSeRevivedHeight);
obj.pushKV("PoSeBanHeight", nPoSeBanHeight);
obj.pushKV("revocationReason", nRevocationReason);
obj.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner)));
obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
if (nType == MnType::Evo) {
obj.pushKV("platformNodeID", platformNodeID.ToString());
if (IsServiceDeprecatedRPCEnabled()) {
obj.pushKV("platformP2PPort", GetPlatformPort</*is_p2p=*/true>(*this));
obj.pushKV("platformHTTPPort", GetPlatformPort</*is_p2p=*/false>(*this));
}
}
CTxDestination dest;
if (nVersion >= ProTxVersion::MultiPayout) {
obj.pushKV("payouts", PayoutListToJson(payouts));
} else if (ExtractDestination(scriptPayout, dest)) {
obj.pushKV("payoutAddress", EncodeDestination(dest));
}
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
if (ExtractDestination(scriptOperatorPayout, dest)) {
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
}
return obj;
}
// CDeterministicMNStateDiff::ToJson() defined in evo/dmnstate.cpp
RPCResult CDeterministicMNStateDiff::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode state diff",
{
{RPCResult::Type::NUM, "version", "Version of the masternode state diff"},
GetRpcResult("service", /*optional=*/true),
GetRpcResult("registeredHeight", /*optional=*/true),
GetRpcResult("lastPaidHeight", /*optional=*/true),
GetRpcResult("consecutivePayments", /*optional=*/true),
GetRpcResult("PoSePenalty", /*optional=*/true),
GetRpcResult("PoSeRevivedHeight", /*optional=*/true),
GetRpcResult("PoSeBanHeight", /*optional=*/true),
GetRpcResult("revocationReason", /*optional=*/true),
GetRpcResult("ownerAddress", /*optional=*/true),
GetRpcResult("votingAddress", /*optional=*/true),
GetRpcResult("payoutAddress", /*optional=*/true),
GetRpcResult("payouts", /*optional=*/true),
GetRpcResult("operatorPayoutAddress", /*optional=*/true),
GetRpcResult("pubKeyOperator", /*optional=*/true),
GetRpcResult("platformNodeID", /*optional=*/true),
GetRpcResult("platformP2PPort", /*optional=*/true),
GetRpcResult("platformHTTPPort", /*optional=*/true),
GetRpcResult("addresses", /*optional=*/true),
}};
}
RPCResult CProRegTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode registration special transaction",
{
GetRpcResult("version"),
GetRpcResult("type"),
GetRpcResult("collateralHash"),
GetRpcResult("collateralIndex"),
GetRpcResult("service", /*optional=*/true),
GetRpcResult("addresses"),
GetRpcResult("ownerAddress"),
GetRpcResult("votingAddress"),
GetRpcResult("payoutAddress", /*optional=*/true),
GetRpcResult("payouts", /*optional=*/true),
GetRpcResult("pubKeyOperator"),
GetRpcResult("operatorReward"),
GetRpcResult("platformNodeID", /*optional=*/true),
GetRpcResult("platformP2PPort", /*optional=*/true),
GetRpcResult("platformHTTPPort", /*optional=*/true),
GetRpcResult("inputsHash"),
}};
}
UniValue CProRegTx::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("type", std23::to_underlying(nType));
ret.pushKV("collateralHash", collateralOutpoint.hash.ToString());
ret.pushKV("collateralIndex", collateralOutpoint.n);
if (IsServiceDeprecatedRPCEnabled()) {
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
}
ret.pushKV("addresses", GetNetInfoWithLegacyFields(*this, nType));
ret.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner)));
ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
if (nVersion >= ProTxVersion::MultiPayout) {
ret.pushKV("payouts", PayoutListToJson(payouts));
} else if (CTxDestination dest; ExtractDestination(scriptPayout, dest)) {
ret.pushKV("payoutAddress", EncodeDestination(dest));
}
ret.pushKV("pubKeyOperator", pubKeyOperator.ToString());
ret.pushKV("operatorReward", (double)nOperatorReward / 100);
if (nType == MnType::Evo) {
ret.pushKV("platformNodeID", platformNodeID.ToString());
if (IsServiceDeprecatedRPCEnabled()) {
ret.pushKV("platformP2PPort", GetPlatformPort</*is_p2p=*/true>(*this));
ret.pushKV("platformHTTPPort", GetPlatformPort</*is_p2p=*/false>(*this));
}
}
ret.pushKV("inputsHash", inputsHash.ToString());
return ret;
}
RPCResult CProUpRegTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode update registrar special transaction",
{
GetRpcResult("version"),
GetRpcResult("proTxHash"),
GetRpcResult("votingAddress"),
GetRpcResult("payoutAddress", /*optional=*/true),
GetRpcResult("payouts", /*optional=*/true),
GetRpcResult("pubKeyOperator"),
GetRpcResult("inputsHash"),
}};
}
UniValue CProUpRegTx::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("proTxHash", proTxHash.ToString());
ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
if (nVersion >= ProTxVersion::MultiPayout) {
ret.pushKV("payouts", PayoutListToJson(payouts));
} else if (CTxDestination dest; ExtractDestination(scriptPayout, dest)) {
ret.pushKV("payoutAddress", EncodeDestination(dest));
}
ret.pushKV("pubKeyOperator", pubKeyOperator.ToString());
ret.pushKV("inputsHash", inputsHash.ToString());
return ret;
}
RPCResult CProUpRevTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode operator revocation special transaction",
{
GetRpcResult("version"),
GetRpcResult("proTxHash"),
{RPCResult::Type::NUM, "reason", "Reason for masternode service revocation"},
GetRpcResult("inputsHash", /*optional=*/true),
}};
}
UniValue CProUpRevTx::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("proTxHash", proTxHash.ToString());
ret.pushKV("reason", nReason);
ret.pushKV("inputsHash", inputsHash.ToString());
return ret;
}
RPCResult CProUpServTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode update service special transaction",
{
GetRpcResult("version"),
GetRpcResult("type"),
GetRpcResult("proTxHash"),
GetRpcResult("service", /*optional=*/true),
GetRpcResult("addresses"),
GetRpcResult("operatorPayoutAddress", /*optional=*/true),
GetRpcResult("platformNodeID", /*optional=*/true),
GetRpcResult("platformP2PPort", /*optional=*/true),
GetRpcResult("platformHTTPPort", /*optional=*/true),
GetRpcResult("inputsHash"),
}};
}
UniValue CProUpServTx::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("type", std23::to_underlying(nType));
ret.pushKV("proTxHash", proTxHash.ToString());
if (IsServiceDeprecatedRPCEnabled()) {
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
}
ret.pushKV("addresses", GetNetInfoWithLegacyFields(*this, nType));
if (CTxDestination dest; ExtractDestination(scriptOperatorPayout, dest)) {
ret.pushKV("operatorPayoutAddress", EncodeDestination(dest));
}
if (nType == MnType::Evo) {
ret.pushKV("platformNodeID", platformNodeID.ToString());
if (IsServiceDeprecatedRPCEnabled()) {
ret.pushKV("platformP2PPort", GetPlatformPort</*is_p2p=*/true>(*this));
ret.pushKV("platformHTTPPort", GetPlatformPort</*is_p2p=*/false>(*this));
}
}
ret.pushKV("inputsHash", inputsHash.ToString());
return ret;
}
RPCResult CSimplifiedMNListDiff::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The simplified masternode list diff",
{
{RPCResult::Type::NUM, "nVersion", "Version of the diff"},
{RPCResult::Type::STR_HEX, "baseBlockHash", "Hash of the base block"},
{RPCResult::Type::STR_HEX, "blockHash", "Hash of the ending block"},
{RPCResult::Type::STR_HEX, "cbTxMerkleTree", "Coinbase transaction merkle tree"},
{RPCResult::Type::STR_HEX, "cbTx", "Coinbase raw transaction"},
{RPCResult::Type::ARR, "deletedMNs", "ProRegTx hashes of deleted masternodes",
{{RPCResult::Type::STR_HEX, "hash", ""}}},
{RPCResult::Type::ARR, "mnList", "Masternode list details",
{CSimplifiedMNListEntry::GetJsonHelp(/*key=*/"", /*optional=*/false)}},
{RPCResult::Type::ARR, "deletedQuorums", "Deleted quorums",
{{RPCResult::Type::OBJ, "", "", {
GetRpcResult("llmqType"),
GetRpcResult("quorumHash"),
}}}},
{RPCResult::Type::ARR, "newQuorums", "New quorums",
{llmq::CFinalCommitment::GetJsonHelp(/*key=*/"", /*optional=*/false)}},
GetRpcResult("merkleRootMNList", /*optional=*/true),
GetRpcResult("merkleRootQuorums", /*optional=*/true),
{RPCResult::Type::ARR, "quorumsCLSigs", "ChainLock signature details", {
{RPCResult::Type::OBJ, "", "", {
{RPCResult::Type::ARR, "<sig_hex>", "Array of quorum indices, keyed by BLS signature", {
{RPCResult::Type::NUM, "", "Quorum index"}
}}}}}},
}};
}
UniValue CSimplifiedMNListDiff::ToJson(bool extended) const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("nVersion", nVersion);
obj.pushKV("baseBlockHash", baseBlockHash.ToString());
obj.pushKV("blockHash", blockHash.ToString());
CDataStream ssCbTxMerkleTree(SER_NETWORK, PROTOCOL_VERSION);
ssCbTxMerkleTree << cbTxMerkleTree;
obj.pushKV("cbTxMerkleTree", HexStr(ssCbTxMerkleTree));
obj.pushKV("cbTx", EncodeHexTx(CTransaction(cbTx)));
UniValue deletedMNsArr(UniValue::VARR);
for (const auto& h : deletedMNs) {
deletedMNsArr.push_back(h.ToString());
}
obj.pushKV("deletedMNs", deletedMNsArr);
UniValue mnListArr(UniValue::VARR);
for (const auto& e : mnList) {
mnListArr.push_back(e.ToJson(extended));
}
obj.pushKV("mnList", mnListArr);
UniValue deletedQuorumsArr(UniValue::VARR);
for (const auto& e : deletedQuorums) {
UniValue eObj(UniValue::VOBJ);
eObj.pushKV("llmqType", e.first);
eObj.pushKV("quorumHash", e.second.ToString());
deletedQuorumsArr.push_back(eObj);
}
obj.pushKV("deletedQuorums", deletedQuorumsArr);
UniValue newQuorumsArr(UniValue::VARR);
for (const auto& e : newQuorums) {
newQuorumsArr.push_back(e.ToJson());
}
obj.pushKV("newQuorums", newQuorumsArr);
// Do not assert special tx type here since this can be called prior to DIP0003 activation
if (const auto opt_cbTxPayload = GetTxPayload<CCbTx>(cbTx, /*assert_type=*/false)) {
obj.pushKV("merkleRootMNList", opt_cbTxPayload->merkleRootMNList.ToString());
if (opt_cbTxPayload->nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) {
obj.pushKV("merkleRootQuorums", opt_cbTxPayload->merkleRootQuorums.ToString());
}
}
UniValue quorumsCLSigsArr(UniValue::VARR);
for (const auto& [signature, quorumsIndexes] : quorumsCLSigs) {
UniValue j(UniValue::VOBJ);
UniValue idxArr(UniValue::VARR);
for (const auto& idx : quorumsIndexes) {
idxArr.push_back(idx);
}
j.pushKV(signature.ToString(), idxArr);
quorumsCLSigsArr.push_back(j);
}
obj.pushKV("quorumsCLSigs", quorumsCLSigsArr);
return obj;
}
RPCResult CSimplifiedMNListEntry::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The simplified masternode list entry",
{
{RPCResult::Type::NUM, "nVersion", "Version of the entry"},
GetRpcResult("type", /*optional=*/false, /*override_name=*/"nType"),
{RPCResult::Type::STR_HEX, "proRegTxHash", "Hash of the ProRegTx identifying the masternode"},
{RPCResult::Type::STR_HEX, "confirmedHash", "Hash of the block where the masternode was confirmed"},
GetRpcResult("service", /*optional=*/true),
GetRpcResult("addresses"),
GetRpcResult("pubKeyOperator"),
GetRpcResult("votingAddress"),
{RPCResult::Type::BOOL, "isValid", "Returns true if the masternode is not Proof-of-Service banned"},
GetRpcResult("platformHTTPPort", /*optional=*/true),
GetRpcResult("platformNodeID", /*optional=*/true),
GetRpcResult("payoutAddress", /*optional=*/true),
GetRpcResult("payouts", /*optional=*/true),
GetRpcResult("operatorPayoutAddress", /*optional=*/true),
}};
}
UniValue CSimplifiedMNListEntry::ToJson(bool extended) const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("nVersion", nVersion);
obj.pushKV("nType", std23::to_underlying(nType));
obj.pushKV("proRegTxHash", proRegTxHash.ToString());
obj.pushKV("confirmedHash", confirmedHash.ToString());
if (IsServiceDeprecatedRPCEnabled()) {
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
}
obj.pushKV("addresses", GetNetInfoWithLegacyFields(*this, nType));
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
obj.pushKV("isValid", isValid);
if (nType == MnType::Evo) {
if (IsServiceDeprecatedRPCEnabled()) {
obj.pushKV("platformHTTPPort", GetPlatformPort</*is_p2p=*/false>(*this));
}
obj.pushKV("platformNodeID", platformNodeID.ToString());
}
if (extended) {
CTxDestination dest;
if (nVersion >= ProTxVersion::MultiPayout) {
obj.pushKV("payouts", PayoutListToJson(payouts));
} else if (ExtractDestination(scriptPayout, dest)) {
obj.pushKV("payoutAddress", EncodeDestination(dest));
}
if (ExtractDestination(scriptOperatorPayout, dest)) {
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
}
}
return obj;
}
RPCResult MNHFTx::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode hard fork payload",
{
{RPCResult::Type::NUM, "versionBit", "Version bit associated with the hard fork"},
GetRpcResult("quorumHash"),
{RPCResult::Type::STR_HEX, "sig", "BLS signature by a quorum public key"},
}};
}
UniValue MNHFTx::ToJson() const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("versionBit", versionBit);
obj.pushKV("quorumHash", quorumHash.ToString());
obj.pushKV("sig", sig.ToString());
return obj;
}
RPCResult MNHFTxPayload::GetJsonHelp(const std::string& key, bool optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The masternode hard fork signal special transaction",
{
GetRpcResult("version"),
MNHFTx::GetJsonHelp(/*key=*/"signal", /*optional=*/false),
}};
}
UniValue MNHFTxPayload::ToJson() const
{
UniValue ret(UniValue::VOBJ);
ret.pushKV("version", nVersion);
ret.pushKV("signal", signal.ToJson());
return ret;
}