3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
5
#include " qt/pivx/masternodewizarddialog.h"
6
- #include " optional.h"
7
- #include " primitives/transaction.h"
8
6
#include " qt/pivx/forms/ui_masternodewizarddialog.h"
9
7
10
8
#include " key_io.h"
@@ -410,22 +408,6 @@ bool MasterNodeWizardDialog::createMN()
410
408
std::string ipAddress = addressStr.toStdString ();
411
409
std::string port = portStr.toStdString ();
412
410
413
- // Look for a valid collateral utxo
414
- COutPoint collateralOut;
415
-
416
- if (!walletModel->getMNCollateralCandidate (collateralOut)) {
417
- // New receive address
418
- auto r = walletModel->getNewAddress (alias);
419
- if (!r) return errorOut (tr (r.getError ().c_str ()));
420
- if (!mnModel->createMNCollateral (addressLabel,
421
- QString::fromStdString (r.getObjResult ()->ToString ()),
422
- collateralOut,
423
- returnStr)) {
424
- // error str set internally
425
- return false ;
426
- }
427
- }
428
-
429
411
if (isDeterministic) {
430
412
auto opOwnerAddrAndKeyId = getOrCreateOwnerAddress (alias);
431
413
if (!opOwnerAddrAndKeyId.getRes ()) {
@@ -447,7 +429,7 @@ bool MasterNodeWizardDialog::createMN()
447
429
// 3) Get operator data
448
430
QString operatorKey = ui->lineEditOperatorKey ->text ();
449
431
Optional<CKeyID> operatorPayoutKeyId = walletModel->getKeyIDFromAddr (ui->lineEditOperatorPayoutAddress ->text ().toStdString ());
450
- double operatorPercentage = ui->lineEditPercentage ->text ().isEmpty () ? 0 : (double ) ui->lineEditPercentage ->text ().toDouble ();
432
+ double operatorPercentage = ui->lineEditPercentage ->text ().isEmpty () ? 0 : (double )ui->lineEditPercentage ->text ().toDouble ();
451
433
452
434
// 4) Get voter data
453
435
Optional<CKeyID> votingAddr;
@@ -463,32 +445,32 @@ bool MasterNodeWizardDialog::createMN()
463
445
votingAddr = ownerKeyId;
464
446
}
465
447
466
- Optional<COutPoint> collateralOut = COutPoint ();
448
+ Optional<COutPoint> collateralOut = COutPoint ();
467
449
bool foundCandidate = false ;
468
- if (!walletModel->getMNCollateralCandidate (*collateralOut)){
469
- collateralOut= nullopt ;
470
- }else {
471
- // We have to lock the collateral or the system could spend it
450
+ if (!walletModel->getMNCollateralCandidate (*collateralOut)) {
451
+ collateralOut = nullopt ;
452
+ } else {
453
+ // We have to lock the collateral or the system could spend it
472
454
walletModel->lockCoin (*collateralOut);
473
455
foundCandidate = true ;
474
456
}
475
457
std::string error_str;
476
-
458
+
477
459
auto res = mnModel->createDMN (alias,
478
- collateralOut,
479
- addressLabel,
480
- ipAddress,
481
- port,
482
- ownerKeyId,
483
- operatorKey.isEmpty () ? nullopt : Optional<std::string>(operatorKey.toStdString ()),
484
- votingAddr,
485
- payoutKeyId,
486
- error_str,
487
- (uint16_t ) operatorPercentage * 100 , // operator percentage
488
- operatorPayoutKeyId); // operator payout script
460
+ collateralOut,
461
+ addressLabel,
462
+ ipAddress,
463
+ port,
464
+ ownerKeyId,
465
+ operatorKey.isEmpty () ? nullopt : Optional<std::string>(operatorKey.toStdString ()),
466
+ votingAddr,
467
+ payoutKeyId,
468
+ error_str,
469
+ (uint16_t )operatorPercentage * 100 , // operator percentage
470
+ operatorPayoutKeyId); // operator payout script
489
471
if (!res) {
490
- // unlock in case of error
491
- if (foundCandidate){
472
+ // unlock in case of error
473
+ if (foundCandidate) {
492
474
walletModel->unlockCoin (*collateralOut);
493
475
}
494
476
return errorOut (tr (error_str.c_str ()));
@@ -497,18 +479,17 @@ bool MasterNodeWizardDialog::createMN()
497
479
// future: move "operatorSk" to a constant field
498
480
std::string operatorSk = walletModel->getStrFromTxExtraData (*res.getObjResult (), " operatorSk" );
499
481
mnSummary = std::make_unique<MNSummary>(alias,
500
- ipAddress+ " :" + port,
501
- collateralOut? *collateralOut: COutPoint (UINT256_ZERO,0 ), // TODO: the outpoint index is not 0 in general, but it does not matter (just display)
502
- ownerAddrStr,
503
- payoutAddrStr,
504
- operatorSk.empty () ? operatorKey.toStdString () : operatorSk,
505
- ownerAddrStr, // voting key, for now fixed to owner addr
506
- 0 , // operator percentage
507
- nullopt ); // operator payout
482
+ ipAddress + " :" + port,
483
+ collateralOut ? *collateralOut : COutPoint (UINT256_ZERO, 0 ), // TODO: the outpoint index is not 0 in general, but it does not matter (just display)
484
+ ownerAddrStr,
485
+ payoutAddrStr,
486
+ operatorSk.empty () ? operatorKey.toStdString () : operatorSk,
487
+ ownerAddrStr, // voting key, for now fixed to owner addr
488
+ 0 , // operator percentage
489
+ nullopt ); // operator payout
508
490
509
491
returnStr = tr (" Deterministic Masternode created! It will appear on your list on the next mined block!" );
510
492
} else {
511
-
512
493
// Legacy
513
494
// Look for a valid collateral utxo
514
495
COutPoint collateralOut;
@@ -517,10 +498,10 @@ bool MasterNodeWizardDialog::createMN()
517
498
// New receive address
518
499
auto r = walletModel->getNewAddress (alias);
519
500
if (!r) return errorOut (tr (r.getError ().c_str ()));
520
- if (!mnModel->createDMNExternalCollateral (addressLabel,
521
- QString::fromStdString (r.getObjResult ()->ToString ()),
522
- collateralOut,
523
- returnStr)) {
501
+ if (!mnModel->createDMNExternalCollateral (addressLabel,
502
+ QString::fromStdString (r.getObjResult ()->ToString ()),
503
+ collateralOut,
504
+ returnStr)) {
524
505
// error str set internally
525
506
return false ;
526
507
}
0 commit comments