forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
evo.cpp
1820 lines (1603 loc) · 80.5 KB
/
evo.cpp
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2018-2024 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 <base58.h>
#include <bls/bls.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <deploymentstatus.h>
#include <evo/chainhelper.h>
#include <evo/deterministicmns.h>
#include <evo/dmn_types.h>
#include <evo/providertx.h>
#include <evo/simplifiedmns.h>
#include <evo/specialtx.h>
#include <evo/specialtxman.h>
#include <index/txindex.h>
#include <llmq/blockprocessor.h>
#include <llmq/context.h>
#include <masternode/meta.h>
#include <messagesigner.h>
#include <netbase.h>
#include <node/context.h>
#include <rpc/blockchain.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <util/moneystr.h>
#include <util/translation.h>
#include <validation.h>
#ifdef ENABLE_WALLET
#include <wallet/coincontrol.h>
#include <wallet/rpcwallet.h>
#include <wallet/wallet.h>
#endif//ENABLE_WALLET
#ifdef ENABLE_WALLET
extern RPCHelpMan signrawtransaction();
extern RPCHelpMan sendrawtransaction();
#else
class CWallet;
#endif//ENABLE_WALLET
static RPCArg GetRpcArg(const std::string& strParamName)
{
static const std::map<std::string, RPCArg> mapParamHelp = {
{"collateralAddress",
{"collateralAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The Dash address to send the collateral to."}
},
{"collateralHash",
{"collateralHash", RPCArg::Type::STR, RPCArg::Optional::NO,
"The collateral transaction hash."}
},
{"collateralIndex",
{"collateralIndex", RPCArg::Type::NUM, RPCArg::Optional::NO,
"The collateral transaction output index."}
},
{"feeSourceAddress",
{"feeSourceAddress", RPCArg::Type::STR, /* default */ "",
"If specified wallet will only use coins from this address to fund ProTx.\n"
"If not specified, payoutAddress is the one that is going to be used.\n"
"The private key belonging to this address must be known in your wallet."}
},
{"fundAddress",
{"fundAddress", RPCArg::Type::STR, /* default */ "",
"If specified wallet will only use coins from this address to fund ProTx.\n"
"If not specified, payoutAddress is the one that is going to be used.\n"
"The private key belonging to this address must be known in your wallet."}
},
{"ipAndPort",
{"ipAndPort", RPCArg::Type::STR, RPCArg::Optional::NO,
"IP and port in the form \"IP:PORT\". Must be unique on the network.\n"
"Can be set to an empty string, which will require a ProUpServTx afterwards."}
},
{"ipAndPort_update",
{"ipAndPort", RPCArg::Type::STR, RPCArg::Optional::NO,
"IP and port in the form \"IP:PORT\". Must be unique on the network."}
},
{"operatorKey",
{"operatorKey", RPCArg::Type::STR, RPCArg::Optional::NO,
"The operator BLS private key associated with the\n"
"registered operator public key."}
},
{"operatorPayoutAddress",
{"operatorPayoutAddress", RPCArg::Type::STR, /* default */ "",
"The address used for operator reward payments.\n"
"Only allowed when the ProRegTx had a non-zero operatorReward value.\n"
"If set to an empty string, the currently active payout address is reused."}
},
{"operatorPubKey_register",
{"operatorPubKey", RPCArg::Type::STR, RPCArg::Optional::NO,
"The operator BLS public key. The BLS private key does not have to be known.\n"
"It has to match the BLS private key which is later used when operating the masternode."}
},
{"operatorPubKey_register_legacy",
{"operatorPubKey", RPCArg::Type::STR, RPCArg::Optional::NO,
"The operator BLS public key in legacy scheme. The BLS private key does not have to be known.\n"
"It has to match the BLS private key which is later used when operating the masternode.\n"}
},
{"operatorPubKey_update",
{"operatorPubKey", RPCArg::Type::STR, RPCArg::Optional::NO,
"The operator BLS public key. The BLS private key does not have to be known.\n"
"It has to match the BLS private key which is later used when operating the masternode.\n"
"If set to an empty string, the currently active operator BLS public key is reused."}
},
{"operatorPubKey_update_legacy",
{"operatorPubKey", RPCArg::Type::STR, RPCArg::Optional::NO,
"The operator BLS public key in legacy scheme. The BLS private key does not have to be known.\n"
"It has to match the BLS private key which is later used when operating the masternode.\n"
"If set to an empty string, the currently active operator BLS public key is reused."}
},
{"operatorReward",
{"operatorReward", RPCArg::Type::STR, RPCArg::Optional::NO,
"The fraction in %% to share with the operator.\n"
"The value must be between 0 and 10000."}
},
{"ownerAddress",
{"ownerAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The Dash address to use for payee updates and proposal voting.\n"
"The corresponding private key does not have to be known by your wallet.\n"
"The address must be unused and must differ from the collateralAddress."}
},
{"payoutAddress_register",
{"payoutAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The Dash address to use for masternode reward payments."}
},
{"payoutAddress_update",
{"payoutAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The Dash address to use for masternode reward payments.\n"
"If set to an empty string, the currently active payout address is reused."}
},
{"proTxHash",
{"proTxHash", RPCArg::Type::STR, RPCArg::Optional::NO,
"The hash of the initial ProRegTx."}
},
{"reason",
{"reason", RPCArg::Type::NUM, /* default */ "",
"The reason for masternode service revocation."}
},
{"submit",
{"submit", RPCArg::Type::BOOL, /* default */ "true",
"If true, the resulting transaction is sent to the network."}
},
{"votingAddress_register",
{"votingAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The voting key address. The private key does not have to be known by your wallet.\n"
"It has to match the private key which is later used when voting on proposals.\n"
"If set to an empty string, ownerAddress will be used."}
},
{"votingAddress_update",
{"votingAddress", RPCArg::Type::STR, RPCArg::Optional::NO,
"The voting key address. The private key does not have to be known by your wallet.\n"
"It has to match the private key which is later used when voting on proposals.\n"
"If set to an empty string, the currently active voting key address is reused."}
},
{"platformNodeID",
{"platformNodeID", RPCArg::Type::STR, RPCArg::Optional::NO,
"Platform P2P node ID, derived from P2P public key."}
},
{"platformP2PPort",
{"platformP2PPort", RPCArg::Type::NUM, RPCArg::Optional::NO,
"TCP port of Dash Platform peer-to-peer communication between nodes (network byte order)."}
},
{"platformHTTPPort",
{"platformHTTPPort", RPCArg::Type::NUM, RPCArg::Optional::NO,
"TCP port of Platform HTTP/API interface (network byte order)."}
},
};
auto it = mapParamHelp.find(strParamName);
if (it == mapParamHelp.end())
throw std::runtime_error(strprintf("FIXME: WRONG PARAM NAME %s!", strParamName));
return it->second;
}
static CKeyID ParsePubKeyIDFromAddress(const std::string& strAddress, const std::string& paramName)
{
CTxDestination dest = DecodeDestination(strAddress);
const PKHash *pkhash = std::get_if<PKHash>(&dest);
if (!pkhash) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be a valid P2PKH address, not %s", paramName, strAddress));
}
return ToKeyID(*pkhash);
}
static CBLSPublicKey ParseBLSPubKey(const std::string& hexKey, const std::string& paramName, bool specific_legacy_bls_scheme)
{
CBLSPublicKey pubKey;
if (!pubKey.SetHexStr(hexKey, specific_legacy_bls_scheme)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be a valid BLS public key, not %s", paramName, hexKey));
}
return pubKey;
}
static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::string& paramName, bool specific_legacy_bls_scheme)
{
CBLSSecretKey secKey;
if (!secKey.SetHexStr(hexKey, specific_legacy_bls_scheme)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be a valid BLS secret key", paramName));
}
return secKey;
}
static bool ValidatePlatformPort(const int32_t port)
{
return port >= 1 && port <= std::numeric_limits<uint16_t>::max();
}
#ifdef ENABLE_WALLET
template<typename SpecialTxPayload>
static void FundSpecialTx(CWallet* pwallet, CMutableTransaction& tx, const SpecialTxPayload& payload, const CTxDestination& fundDest)
{
CHECK_NONFATAL(pwallet != nullptr);
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
LOCK(pwallet->cs_wallet);
CTxDestination nodest = CNoDestination();
if (fundDest == nodest) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "No source of funds specified");
}
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
ds << payload;
tx.vExtraPayload.assign(UCharCast(ds.data()), UCharCast(ds.data() + ds.size()));
static const CTxOut dummyTxOut(0, CScript() << OP_RETURN);
std::vector<CRecipient> vecSend;
bool dummyTxOutAdded = false;
if (tx.vout.empty()) {
// add dummy txout as CreateTransaction requires at least one recipient
tx.vout.emplace_back(dummyTxOut);
dummyTxOutAdded = true;
}
for (const auto& txOut : tx.vout) {
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, false};
vecSend.push_back(recipient);
}
CCoinControl coinControl;
coinControl.destChange = fundDest;
coinControl.fRequireAllInputs = false;
std::vector<COutput> vecOutputs;
pwallet->AvailableCoins(vecOutputs);
for (const auto& out : vecOutputs) {
CTxDestination txDest;
if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, txDest) && txDest == fundDest) {
coinControl.Select(COutPoint(out.tx->tx->GetHash(), out.i));
}
}
if (!coinControl.HasSelected()) {
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("No funds at specified address %s", EncodeDestination(fundDest)));
}
CTransactionRef newTx;
CAmount nFee;
int nChangePos = -1;
bilingual_str strFailReason;
FeeCalculation fee_calc_out;
if (!pwallet->CreateTransaction(vecSend, newTx, nFee, nChangePos, strFailReason, coinControl, fee_calc_out, false, tx.vExtraPayload.size())) {
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason.original);
}
tx.vin = newTx->vin;
tx.vout = newTx->vout;
if (dummyTxOutAdded && tx.vout.size() > 1) {
// CreateTransaction added a change output, so we don't need the dummy txout anymore.
// Removing it results in slight overpayment of fees, but we ignore this for now (as it's a very low amount).
auto it = std::find(tx.vout.begin(), tx.vout.end(), dummyTxOut);
CHECK_NONFATAL(it != tx.vout.end());
tx.vout.erase(it);
}
}
template<typename SpecialTxPayload>
static void UpdateSpecialTxInputsHash(const CMutableTransaction& tx, SpecialTxPayload& payload)
{
payload.inputsHash = CalcTxInputsHash(CTransaction(tx));
}
template<typename SpecialTxPayload>
static void SignSpecialTxPayloadByHash(const CMutableTransaction& tx, SpecialTxPayload& payload, const CKey& key)
{
UpdateSpecialTxInputsHash(tx, payload);
payload.vchSig.clear();
uint256 hash = ::SerializeHash(payload);
if (!CHashSigner::SignHash(hash, key, payload.vchSig)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to sign special tx");
}
}
template<typename SpecialTxPayload>
static void SignSpecialTxPayloadByString(const CMutableTransaction& tx, SpecialTxPayload& payload, const CKey& key)
{
UpdateSpecialTxInputsHash(tx, payload);
payload.vchSig.clear();
std::string m = payload.MakeSignString();
if (!CMessageSigner::SignMessage(m, payload.vchSig, key)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to sign special tx");
}
}
template<typename SpecialTxPayload>
static void SignSpecialTxPayloadByHash(const CMutableTransaction& tx, SpecialTxPayload& payload, const CBLSSecretKey& key)
{
UpdateSpecialTxInputsHash(tx, payload);
uint256 hash = ::SerializeHash(payload);
payload.sig = key.Sign(hash);
}
static std::string SignAndSendSpecialTx(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman, const CMutableTransaction& tx, bool fSubmit = true)
{
{
LOCK(cs_main);
TxValidationState state;
if (!chain_helper.special_tx->CheckSpecialTx(CTransaction(tx), chainman.ActiveChain().Tip(), chainman.ActiveChainstate().CoinsTip(), true, state)) {
throw std::runtime_error(state.ToString());
}
} // cs_main
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
ds << tx;
JSONRPCRequest signRequest(request);
signRequest.params.setArray();
signRequest.params.push_back(HexStr(ds));
UniValue signResult = signrawtransactionwithwallet().HandleRequest(signRequest);
if (!fSubmit) {
return signResult["hex"].get_str();
}
JSONRPCRequest sendRequest(request);
sendRequest.params.setArray();
sendRequest.params.push_back(signResult["hex"].get_str());
return sendrawtransaction().HandleRequest(sendRequest).get_str();
}
static void protx_register_fund_help(const JSONRPCRequest& request, bool legacy)
{
std::string rpc_name = legacy ? "register_fund_legacy" : "register_fund";
std::string rpc_full_name = std::string("protx ").append(rpc_name);
std::string pubkey_operator = legacy ? "\"0532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"" : "\"8532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"";
std::string rpc_example = rpc_name.append(" \"" + EXAMPLE_ADDRESS[0] + "\" \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" ").append(pubkey_operator).append(" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\"");
RPCHelpMan{rpc_full_name,
"\nCreates, funds and sends a ProTx to the network. The resulting transaction will move 1000 Dash\n"
"to the address specified by collateralAddress and will then function as the collateral of your\n"
"masternode.\n"
"A few of the limitations you see in the arguments are temporary and might be lifted after DIP3\n"
"is fully deployed.\n"
+ HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("collateralAddress"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
legacy ? GetRpcArg("operatorPubKey_register_legacy") : GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("fundAddress"),
GetRpcArg("submit"),
},
{
RPCResult{"if \"submit\" is not set or set to true",
RPCResult::Type::STR_HEX, "txid", "The transaction id"},
RPCResult{"if \"submit\" is set to false",
RPCResult::Type::STR_HEX, "hex", "The serialized signed ProTx in hex format"},
},
RPCExamples{
HelpExampleCli("protx", rpc_example)
},
}.Check(request);
}
static void protx_register_help(const JSONRPCRequest& request, bool legacy)
{
std::string rpc_name = legacy ? "register_legacy" : "register";
std::string rpc_full_name = std::string("protx ").append(rpc_name);
std::string pubkey_operator = legacy ? "\"0532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"" : "\"8532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"";
std::string rpc_example = rpc_name.append(" \"0123456701234567012345670123456701234567012345670123456701234567\" 0 \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" ").append(pubkey_operator).append(" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\"");
RPCHelpMan{rpc_full_name,
"\nSame as \"protx register_fund\", but with an externally referenced collateral.\n"
"The collateral is specified through \"collateralHash\" and \"collateralIndex\" and must be an unspent\n"
"transaction output spendable by this wallet. It must also not be used by any other masternode.\n"
+ HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("collateralHash"),
GetRpcArg("collateralIndex"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
legacy ? GetRpcArg("operatorPubKey_register_legacy") : GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("feeSourceAddress"),
GetRpcArg("submit"),
},
{
RPCResult{"if \"submit\" is not set or set to true",
RPCResult::Type::STR_HEX, "txid", "The transaction id"},
RPCResult{"if \"submit\" is set to false",
RPCResult::Type::STR_HEX, "hex", "The serialized signed ProTx in hex format"},
},
RPCExamples{
HelpExampleCli("protx", rpc_example)
},
}.Check(request);
}
static void protx_register_prepare_help(const JSONRPCRequest& request, bool legacy)
{
std::string rpc_name = legacy ? "register_prepare_legacy" : "register_prepare";
std::string rpc_full_name = std::string("protx ").append(rpc_name);
std::string pubkey_operator = legacy ? "\"0532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"" : "\"8532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"";
std::string rpc_example = rpc_name.append(" \"0123456701234567012345670123456701234567012345670123456701234567\" 0 \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" ").append(pubkey_operator).append(" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\"");
RPCHelpMan{rpc_full_name,
"\nCreates an unsigned ProTx and a message that must be signed externally\n"
"with the private key that corresponds to collateralAddress to prove collateral ownership.\n"
"The prepared transaction will also contain inputs and outputs to cover fees.\n",
{
GetRpcArg("collateralHash"),
GetRpcArg("collateralIndex"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
legacy ? GetRpcArg("operatorPubKey_register_legacy") : GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("feeSourceAddress"),
},
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR_HEX, "tx", "The serialized unsigned ProTx in hex format"},
{RPCResult::Type::STR_HEX, "collateralAddress", "The collateral address"},
{RPCResult::Type::STR_HEX, "signMessage", "The string message that needs to be signed with the collateral key"},
}},
RPCExamples{
HelpExampleCli("protx", rpc_example)
},
}.Check(request);
}
static void protx_register_submit_help(const JSONRPCRequest& request)
{
RPCHelpMan{"protx register_submit",
"\nCombines the unsigned ProTx and a signature of the signMessage, signs all inputs\n"
"which were added to cover fees and submits the resulting transaction to the network.\n"
"Note: See \"help protx register_prepare\" for more info about creating a ProTx and a message to sign.\n"
+ HELP_REQUIRING_PASSPHRASE,
{
{"tx", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The serialized unsigned ProTx in hex format."},
{"sig", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature signed with the collateral key. Must be in base64 format."},
},
RPCResult{
RPCResult::Type::STR_HEX, "txid", "The transaction id"
},
RPCExamples{
HelpExampleCli("protx", "register_submit \"tx\" \"sig\"")
},
}.Check(request);
}
static void protx_register_fund_evo_help(const JSONRPCRequest& request)
{
RPCHelpMan{
"protx register_fund_evo",
"\nCreates, funds and sends a ProTx to the network. The resulting transaction will move 4000 Dash\n"
"to the address specified by collateralAddress and will then function as the collateral of your\n"
"EvoNode.\n"
"A few of the limitations you see in the arguments are temporary and might be lifted after DIP3\n"
"is fully deployed.\n" +
HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("collateralAddress"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("platformNodeID"),
GetRpcArg("platformP2PPort"),
GetRpcArg("platformHTTPPort"),
GetRpcArg("fundAddress"),
GetRpcArg("submit"),
},
{
RPCResult{"if \"submit\" is not set or set to true",
RPCResult::Type::STR_HEX, "txid", "The transaction id"},
RPCResult{"if \"submit\" is set to false",
RPCResult::Type::STR_HEX, "hex", "The serialized signed ProTx in hex format"},
},
RPCExamples{
HelpExampleCli("protx", "register_fund_evo \"" + EXAMPLE_ADDRESS[0] + "\" \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" \"93746e8731c57f87f79b3620a7982924e2931717d49540a85864bd543de11c43fb868fd63e501a1db37e19ed59ae6db4\" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\" \"f2dbd9b0a1f541a7c44d34a58674d0262f5feca5\" 22821 22822")},
}.Check(request);
}
static void protx_register_evo_help(const JSONRPCRequest& request)
{
RPCHelpMan{
"protx register_evo",
"\nSame as \"protx register_fund_evo\", but with an externally referenced collateral.\n"
"The collateral is specified through \"collateralHash\" and \"collateralIndex\" and must be an unspent\n"
"transaction output spendable by this wallet. It must also not be used by any other masternode.\n" +
HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("collateralHash"),
GetRpcArg("collateralIndex"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("platformNodeID"),
GetRpcArg("platformP2PPort"),
GetRpcArg("platformHTTPPort"),
GetRpcArg("feeSourceAddress"),
GetRpcArg("submit"),
},
{
RPCResult{"if \"submit\" is not set or set to true",
RPCResult::Type::STR_HEX, "txid", "The transaction id"},
RPCResult{"if \"submit\" is set to false",
RPCResult::Type::STR_HEX, "hex", "The serialized signed ProTx in hex format"},
},
RPCExamples{
HelpExampleCli("protx", "register_evo \"0123456701234567012345670123456701234567012345670123456701234567\" 0 \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" \"93746e8731c57f87f79b3620a7982924e2931717d49540a85864bd543de11c43fb868fd63e501a1db37e19ed59ae6db4\" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\" \"f2dbd9b0a1f541a7c44d34a58674d0262f5feca5\" 22821 22822")},
}.Check(request);
}
static void protx_register_prepare_evo_help(const JSONRPCRequest& request)
{
RPCHelpMan{
"protx register_prepare_evo",
"\nCreates an unsigned ProTx and a message that must be signed externally\n"
"with the private key that corresponds to collateralAddress to prove collateral ownership.\n"
"The prepared transaction will also contain inputs and outputs to cover fees.\n",
{
GetRpcArg("collateralHash"),
GetRpcArg("collateralIndex"),
GetRpcArg("ipAndPort"),
GetRpcArg("ownerAddress"),
GetRpcArg("operatorPubKey_register"),
GetRpcArg("votingAddress_register"),
GetRpcArg("operatorReward"),
GetRpcArg("payoutAddress_register"),
GetRpcArg("platformNodeID"),
GetRpcArg("platformP2PPort"),
GetRpcArg("platformHTTPPort"),
GetRpcArg("feeSourceAddress"),
},
RPCResult{
RPCResult::Type::OBJ, "", "", {
{RPCResult::Type::STR_HEX, "tx", "The serialized unsigned ProTx in hex format"},
{RPCResult::Type::STR_HEX, "collateralAddress", "The collateral address"},
{RPCResult::Type::STR_HEX, "signMessage", "The string message that needs to be signed with the collateral key"},
}},
RPCExamples{HelpExampleCli("protx", "register_prepare_evo \"0123456701234567012345670123456701234567012345670123456701234567\" 0 \"1.2.3.4:1234\" \"" + EXAMPLE_ADDRESS[1] + "\" \"93746e8731c57f87f79b3620a7982924e2931717d49540a85864bd543de11c43fb868fd63e501a1db37e19ed59ae6db4\" \"" + EXAMPLE_ADDRESS[1] + "\" 0 \"" + EXAMPLE_ADDRESS[0] + "\" \"f2dbd9b0a1f541a7c44d34a58674d0262f5feca5\" 22821 22822")},
}.Check(request);
}
static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
CChainstateHelper& chain_helper,
const ChainstateManager& chainman,
const bool specific_legacy_bls_scheme,
const bool isExternalRegister,
const bool isFundRegister,
const bool isPrepareRegister,
const MnType mnType)
{
const bool isEvoRequested = mnType == MnType::Evo;
if (isEvoRequested) {
if (isFundRegister && (request.fHelp || (request.params.size() < 10 || request.params.size() > 12))) {
protx_register_fund_evo_help(request);
} else if (isExternalRegister && (request.fHelp || (request.params.size() < 11 || request.params.size() > 13))) {
protx_register_evo_help(request);
} else if (isPrepareRegister && (request.fHelp || (request.params.size() != 11 && request.params.size() != 12))) {
protx_register_prepare_evo_help(request);
}
} else {
if (isFundRegister && (request.fHelp || (request.params.size() < 7 || request.params.size() > 9))) {
protx_register_fund_help(request, specific_legacy_bls_scheme);
} else if (isExternalRegister && (request.fHelp || (request.params.size() < 8 || request.params.size() > 10))) {
protx_register_help(request, specific_legacy_bls_scheme);
} else if (isPrepareRegister && (request.fHelp || (request.params.size() != 8 && request.params.size() != 9))) {
protx_register_prepare_help(request, specific_legacy_bls_scheme);
}
}
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
if (isExternalRegister || isFundRegister) {
EnsureWalletIsUnlocked(wallet.get());
}
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
if (isEvoRequested && !isV19active) {
throw JSONRPCError(RPC_INVALID_REQUEST, "EvoNodes aren't allowed yet");
}
size_t paramIdx = 0;
CMutableTransaction tx;
tx.nVersion = 3;
tx.nType = TRANSACTION_PROVIDER_REGISTER;
const bool use_legacy = isV19active ? specific_legacy_bls_scheme : true;
CProRegTx ptx;
ptx.nType = mnType;
if (isFundRegister) {
CTxDestination collateralDest = DecodeDestination(request.params[paramIdx].get_str());
if (!IsValidDestination(collateralDest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid collaterall address: %s", request.params[paramIdx].get_str()));
}
CScript collateralScript = GetScriptForDestination(collateralDest);
CAmount fundCollateral = GetMnType(mnType).collat_amount;
CTxOut collateralTxOut(fundCollateral, collateralScript);
tx.vout.emplace_back(collateralTxOut);
paramIdx++;
} else {
uint256 collateralHash(ParseHashV(request.params[paramIdx], "collateralHash"));
int32_t collateralIndex = ParseInt32V(request.params[paramIdx + 1], "collateralIndex");
if (collateralHash.IsNull() || collateralIndex < 0) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid hash or index: %s-%d", collateralHash.ToString(), collateralIndex));
}
ptx.collateralOutpoint = COutPoint(collateralHash, (uint32_t)collateralIndex);
paramIdx += 2;
}
if (request.params[paramIdx].get_str() != "") {
if (!Lookup(request.params[paramIdx].get_str().c_str(), ptx.addr, Params().GetDefaultPort(), false)) {
throw std::runtime_error(strprintf("invalid network address %s", request.params[paramIdx].get_str()));
}
}
ptx.keyIDOwner = ParsePubKeyIDFromAddress(request.params[paramIdx + 1].get_str(), "owner address");
ptx.pubKeyOperator.Set(ParseBLSPubKey(request.params[paramIdx + 2].get_str(), "operator BLS address", use_legacy), use_legacy);
ptx.nVersion = use_legacy ? CProRegTx::LEGACY_BLS_VERSION : CProRegTx::BASIC_BLS_VERSION;
CHECK_NONFATAL(ptx.pubKeyOperator.IsLegacy() == (ptx.nVersion == CProRegTx::LEGACY_BLS_VERSION));
CKeyID keyIDVoting = ptx.keyIDOwner;
if (request.params[paramIdx + 3].get_str() != "") {
keyIDVoting = ParsePubKeyIDFromAddress(request.params[paramIdx + 3].get_str(), "voting address");
}
int64_t operatorReward;
if (!ParseFixedPoint(request.params[paramIdx + 4].getValStr(), 2, &operatorReward)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "operatorReward must be a number");
}
if (operatorReward < 0 || operatorReward > 10000) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "operatorReward must be between 0 and 10000");
}
ptx.nOperatorReward = operatorReward;
CTxDestination payoutDest = DecodeDestination(request.params[paramIdx + 5].get_str());
if (!IsValidDestination(payoutDest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid payout address: %s", request.params[paramIdx + 5].get_str()));
}
if (isEvoRequested) {
if (!IsHex(request.params[paramIdx + 6].get_str())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformNodeID must be hexadecimal string");
}
ptx.platformNodeID.SetHex(request.params[paramIdx + 6].get_str());
int32_t requestedPlatformP2PPort = ParseInt32V(request.params[paramIdx + 7], "platformP2PPort");
if (!ValidatePlatformPort(requestedPlatformP2PPort)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformP2PPort must be a valid port [1-65535]");
}
ptx.platformP2PPort = static_cast<uint16_t>(requestedPlatformP2PPort);
int32_t requestedPlatformHTTPPort = ParseInt32V(request.params[paramIdx + 8], "platformHTTPPort");
if (!ValidatePlatformPort(requestedPlatformHTTPPort)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformHTTPPort must be a valid port [1-65535]");
}
ptx.platformHTTPPort = static_cast<uint16_t>(requestedPlatformHTTPPort);
paramIdx += 3;
}
ptx.keyIDVoting = keyIDVoting;
ptx.scriptPayout = GetScriptForDestination(payoutDest);
if (!isFundRegister) {
// make sure fee calculation works
ptx.vchSig.resize(65);
}
CTxDestination fundDest = payoutDest;
if (!request.params[paramIdx + 6].isNull()) {
fundDest = DecodeDestination(request.params[paramIdx + 6].get_str());
if (!IsValidDestination(fundDest))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[paramIdx + 6].get_str());
}
bool fSubmit{true};
if ((isExternalRegister || isFundRegister) && !request.params[paramIdx + 7].isNull()) {
fSubmit = ParseBoolV(request.params[paramIdx + 7], "submit");
}
if (isFundRegister) {
FundSpecialTx(wallet.get(), tx, ptx, fundDest);
UpdateSpecialTxInputsHash(tx, ptx);
CAmount fundCollateral = GetMnType(mnType).collat_amount;
uint32_t collateralIndex = (uint32_t) -1;
for (uint32_t i = 0; i < tx.vout.size(); i++) {
if (tx.vout[i].nValue == fundCollateral) {
collateralIndex = i;
break;
}
}
CHECK_NONFATAL(collateralIndex != (uint32_t) -1);
ptx.collateralOutpoint.n = collateralIndex;
SetTxPayload(tx, ptx);
return SignAndSendSpecialTx(request, chain_helper, chainman, tx, fSubmit);
} else {
// referencing external collateral
const bool unlockOnError = [&]() {
if (LOCK(wallet->cs_wallet); !wallet->IsLockedCoin(ptx.collateralOutpoint.hash, ptx.collateralOutpoint.n)) {
wallet->LockCoin(ptx.collateralOutpoint);
return true;
}
return false;
}();
try {
FundSpecialTx(wallet.get(), tx, ptx, fundDest);
UpdateSpecialTxInputsHash(tx, ptx);
Coin coin;
if (!GetUTXOCoin(ptx.collateralOutpoint, coin)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("collateral not found: %s", ptx.collateralOutpoint.ToStringShort()));
}
CTxDestination txDest;
ExtractDestination(coin.out.scriptPubKey, txDest);
const PKHash* pkhash = std::get_if<PKHash>(&txDest);
if (!pkhash) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("collateral type not supported: %s", ptx.collateralOutpoint.ToStringShort()));
}
if (isPrepareRegister) {
// external signing with collateral key
ptx.vchSig.clear();
SetTxPayload(tx, ptx);
UniValue ret(UniValue::VOBJ);
ret.pushKV("tx", EncodeHexTx(CTransaction(tx)));
ret.pushKV("collateralAddress", EncodeDestination(txDest));
ret.pushKV("signMessage", ptx.MakeSignString());
return ret;
} else {
{
LOCK(wallet->cs_wallet);
// lets prove we own the collateral
CScript scriptPubKey = GetScriptForDestination(txDest);
std::unique_ptr<SigningProvider> provider = wallet->GetSolvingProvider(scriptPubKey);
std::string signed_payload;
SigningResult err = wallet->SignMessage(ptx.MakeSignString(), *pkhash, signed_payload);
if (err == SigningResult::SIGNING_FAILED) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, SigningResultString(err));
} else if (err != SigningResult::OK){
throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err));
}
bool invalid = false;
ptx.vchSig = DecodeBase64(signed_payload.c_str(), &invalid);
if (invalid) throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to decode base64 ready signature for protx");
} // cs_wallet
SetTxPayload(tx, ptx);
return SignAndSendSpecialTx(request, chain_helper, chainman, tx, fSubmit);
}
} catch (...) {
if (unlockOnError) {
WITH_LOCK(wallet->cs_wallet, wallet->UnlockCoin(ptx.collateralOutpoint));
}
throw;
}
}
}
static UniValue protx_register_evo(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman)
{
bool isExternalRegister = request.strMethod == "protxregister_evo";
bool isFundRegister = request.strMethod == "protxregister_fund_evo";
bool isPrepareRegister = request.strMethod == "protxregister_prepare_evo";
if (request.strMethod.find("_hpmn") != std::string::npos) {
if (!IsDeprecatedRPCEnabled("hpmn")) {
throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them");
}
isExternalRegister = request.strMethod == "protxregister_hpmn";
isFundRegister = request.strMethod == "protxregister_fund_hpmn";
isPrepareRegister = request.strMethod == "protxregister_prepare_hpmn";
}
return protx_register_common_wrapper(request, chain_helper, chainman, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Evo);
}
static UniValue protx_register(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman)
{
bool isExternalRegister = request.strMethod == "protxregister";
bool isFundRegister = request.strMethod == "protxregister_fund";
bool isPrepareRegister = request.strMethod == "protxregister_prepare";
return protx_register_common_wrapper(request, chain_helper, chainman, false, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular);
}
static UniValue protx_register_legacy(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman)
{
bool isExternalRegister = request.strMethod == "protxregister_legacy";
bool isFundRegister = request.strMethod == "protxregister_fund_legacy";
bool isPrepareRegister = request.strMethod == "protxregister_prepare_legacy";
return protx_register_common_wrapper(request, chain_helper, chainman, true, isExternalRegister, isFundRegister, isPrepareRegister, MnType::Regular);
}
static UniValue protx_register_submit(const JSONRPCRequest& request, CChainstateHelper& chain_helper, const ChainstateManager& chainman)
{
protx_register_submit_help(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
EnsureWalletIsUnlocked(wallet.get());
CMutableTransaction tx;
if (!DecodeHexTx(tx, request.params[0].get_str())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "transaction not deserializable");
}
if (tx.nType != TRANSACTION_PROVIDER_REGISTER) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "transaction not a ProRegTx");
}
auto ptx = [&tx]() {
if (const auto opt_ptx = GetTxPayload<CProRegTx>(tx); opt_ptx.has_value()) {
return *opt_ptx;
}
throw JSONRPCError(RPC_INVALID_PARAMETER, "transaction payload not deserializable");
}();
if (!ptx.vchSig.empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "payload signature not empty");
}
bool decode_fail{false};
ptx.vchSig = DecodeBase64(request.params[1].get_str().c_str(), &decode_fail);
if (decode_fail) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "malformed base64 encoding");
}
SetTxPayload(tx, ptx);
return SignAndSendSpecialTx(request, chain_helper, chainman, tx);
}
static void protx_update_service_help(const JSONRPCRequest& request)
{
RPCHelpMan{"protx update_service",
"\nCreates and sends a ProUpServTx to the network. This will update the IP address\n"
"of a masternode.\n"
"If this is done for a masternode that got PoSe-banned, the ProUpServTx will also revive this masternode.\n"
+ HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("proTxHash"),
GetRpcArg("ipAndPort_update"),
GetRpcArg("operatorKey"),
GetRpcArg("operatorPayoutAddress"),
GetRpcArg("feeSourceAddress"),
},
RPCResult{
RPCResult::Type::STR_HEX, "txid", "The transaction id"
},
RPCExamples{
HelpExampleCli("protx", "update_service \"0123456701234567012345670123456701234567012345670123456701234567\" \"1.2.3.4:1234\" 5a2e15982e62f1e0b7cf9783c64cf7e3af3f90a52d6c40f6f95d624c0b1621cd")
},
}.Check(request);
}
static void protx_update_service_evo_help(const JSONRPCRequest& request)
{
RPCHelpMan{
"protx update_service_evo",
"\nCreates and sends a ProUpServTx to the network. This will update the IP address and the Platform fields\n"
"of an EvoNode.\n"
"If this is done for an EvoNode that got PoSe-banned, the ProUpServTx will also revive this EvoNode.\n" +
HELP_REQUIRING_PASSPHRASE,
{
GetRpcArg("proTxHash"),
GetRpcArg("ipAndPort_update"),
GetRpcArg("operatorKey"),
GetRpcArg("platformNodeID"),
GetRpcArg("platformP2PPort"),
GetRpcArg("platformHTTPPort"),
GetRpcArg("operatorPayoutAddress"),
GetRpcArg("feeSourceAddress"),
},
RPCResult{
RPCResult::Type::STR_HEX, "txid", "The transaction id"},
RPCExamples{
HelpExampleCli("protx", "update_service_evo \"0123456701234567012345670123456701234567012345670123456701234567\" \"1.2.3.4:1234\" \"5a2e15982e62f1e0b7cf9783c64cf7e3af3f90a52d6c40f6f95d624c0b1621cd\" \"f2dbd9b0a1f541a7c44d34a58674d0262f5feca5\" 22821 22822")},
}.Check(request);
}
static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& request, CChainstateHelper& chain_helper, CDeterministicMNManager& dmnman, const ChainstateManager& chainman, const MnType mnType)
{
if (request.strMethod.find("_hpmn") != std::string::npos) {
if (!IsDeprecatedRPCEnabled("hpmn")) {
throw JSONRPCError(RPC_METHOD_DEPRECATED, "*_hpmn methods are deprecated. Use the related *_evo methods or set -deprecatedrpc=hpmn to enable them");
}
}
const bool isEvoRequested = mnType == MnType::Evo;
if (isEvoRequested) {
protx_update_service_evo_help(request);
} else {
protx_update_service_help(request);
}
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
EnsureWalletIsUnlocked(wallet.get());
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
const bool is_bls_legacy = !isV19active;
if (isEvoRequested && !isV19active) {
throw JSONRPCError(RPC_INVALID_REQUEST, "EvoNodes aren't allowed yet");
}
CProUpServTx ptx;
ptx.nType = mnType;
ptx.proTxHash = ParseHashV(request.params[0], "proTxHash");
if (!Lookup(request.params[1].get_str().c_str(), ptx.addr, Params().GetDefaultPort(), false)) {
throw std::runtime_error(strprintf("invalid network address %s", request.params[1].get_str()));
}
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[2].get_str(), "operatorKey", is_bls_legacy);
size_t paramIdx = 3;
if (isEvoRequested) {
if (!IsHex(request.params[paramIdx].get_str())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformNodeID must be hexadecimal string");
}
ptx.platformNodeID.SetHex(request.params[paramIdx].get_str());
int32_t requestedPlatformP2PPort = ParseInt32V(request.params[paramIdx + 1], "platformP2PPort");
if (!ValidatePlatformPort(requestedPlatformP2PPort)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformP2PPort must be a valid port [1-65535]");
}
ptx.platformP2PPort = static_cast<uint16_t>(requestedPlatformP2PPort);
int32_t requestedPlatformHTTPPort = ParseInt32V(request.params[paramIdx + 2], "platformHTTPPort");
if (!ValidatePlatformPort(requestedPlatformHTTPPort)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "platformHTTPPort must be a valid port [1-65535]");
}
ptx.platformHTTPPort = static_cast<uint16_t>(requestedPlatformHTTPPort);
paramIdx += 3;
}
auto dmn = dmnman.GetListAtChainTip().GetMN(ptx.proTxHash);
if (!dmn) {
throw std::runtime_error(strprintf("masternode with proTxHash %s not found", ptx.proTxHash.ToString()));
}
if (dmn->nType != mnType) {
throw std::runtime_error(strprintf("masternode with proTxHash %s is not a %s", ptx.proTxHash.ToString(), GetMnType(mnType).description));
}
ptx.nVersion = dmn->pdmnState->nVersion;
if (keyOperator.GetPublicKey() != dmn->pdmnState->pubKeyOperator.Get()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("the operator key does not belong to the registered public key"));
}
CMutableTransaction tx;
tx.nVersion = 3;
tx.nType = TRANSACTION_PROVIDER_UPDATE_SERVICE;
// param operatorPayoutAddress