diff --git a/src/main.cpp b/src/main.cpp index 20a7dc9df3..3871a12bfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5323,6 +5323,7 @@ void CDarkSendPool::Check() //do something... ??? sessionTxID[session_id] = "failed"; SetNull(); + pwalletMain->Lock(); UpdateState(POOL_STATUS_ACCEPTING_INPUTS); return; } @@ -5335,6 +5336,7 @@ void CDarkSendPool::Check() txNew.fTimeReceivedIsTxTime = true; txNew.RelayWalletTransaction(); + printf("CDarkSendPool::Check() -- IS MASTER -- TRANSMITTING DARKSEND\n"); } @@ -5404,6 +5406,10 @@ void CDarkSendPool::ChargeFees(){ } } +std::string CDarkSendPool::Denominate(){ + return pwalletMain->Denominate(); +} + void CDarkSendPool::CheckTimeout(){ // catching hanging sessions if((state == POOL_STATUS_ACCEPTING_OUTPUTS || state == POOL_STATUS_SIGNING) && GetTimeMillis()-last_time_stage_changed >= 10000 ) { diff --git a/src/main.h b/src/main.h index df763ff187..7f1e3cdc6f 100644 --- a/src/main.h +++ b/src/main.h @@ -2568,6 +2568,7 @@ public: void CatchUpNode(CNode* pfrom); void SendMoney(const CTransaction& txCollateral, const CTxIn& from, const CTxOut& to, int64& nFeeRet, CKeyStore& newKeys, int64 from_nValue, CScript& pubScript, CReserveKey& reservekey); void AddQueuedSignatures(); + std::string Denominate(); IMPLEMENT_SERIALIZE ( diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index c2f8308527..2c1fb48b32 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -5,6 +5,7 @@ res/icons/quit.png res/icons/send.png res/icons/toolbar.png + res/icons/denominate.png res/icons/connect0_16.png res/icons/connect1_16.png res/icons/connect2_16.png diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index 4750508168..3b75e33a39 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -702,6 +702,32 @@ + + + + + 0 + 0 + + + + Create inputs compatible with DarkSend + + + Denominate + + + + :/icons/denominate:/icons/denominate + + + 300 + + + false + + + diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 4874aded03..84df944f75 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -28,6 +28,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac ui->addButton->setIcon(QIcon()); ui->clearButton->setIcon(QIcon()); + ui->denominateButton->setIcon(QIcon()); ui->sendButton->setIcon(QIcon()); #endif #if QT_VERSION >= 0x040700 @@ -39,6 +40,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(ui->denominateButton, SIGNAL(clicked()), this, SLOT(denominate())); // Coin Control ui->lineEditCoinControlChange->setFont(GUIUtil::bitcoinAddressFont()); @@ -255,6 +257,17 @@ void SendCoinsDialog::clear() ui->sendButton->setDefault(true); } +void SendCoinsDialog::denominate() +{ + std::string message = darkSendPool.Denominate(); + + if(message != ""){ + QMessageBox::warning(this, tr("Denominate"), + tr(message.c_str()), + QMessageBox::Ok, QMessageBox::Ok); + } +} + void SendCoinsDialog::reject() { clear(); diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index d5fba9b7c0..cdc3ba94af 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -36,6 +36,7 @@ public: public slots: void clear(); + void denominate(); void reject(); void accept(); SendCoinsEntry *addEntry(); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 8887f17b7d..4b7895926d 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -338,60 +338,12 @@ Value denominate(const Array& params, bool fHelp) "Creates compatible inputs for DarkSend" + HelpRequiringPassphrase()); - - int count = 10; - int successful = 0; - bool done = false; - - if(pwalletMain->GetBalance() < 11*COIN){ - return "To use denominate you must have at least 11DRK with 1 confirmation."; + if (pwalletMain->IsLocked()) + { + return _("Error: Wallet locked, unable to denominate! Use walletpassphrase to unlock. "); } - int64 nFeeRequired; - string strError; - // create another transaction as collateral for using DarkSend - while(!done && count > 0) - { - - CWalletTx wtxNew; - CWalletTx wtxNew2; - CReserveKey reservekey(pwalletMain); - - //get 2 new keys - CScript scriptNewAddr; - CPubKey vchPubKey; - assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked - scriptNewAddr.SetDestination(vchPubKey.GetID()); - - CScript scriptNewAddr2; - CPubKey vchPubKey2; - assert(reservekey.GetReservedKey(vchPubKey2)); // should never fail, as we just unlocked - scriptNewAddr2.SetDestination(vchPubKey2.GetID()); - - vector< pair > vecSend; - for(int i = 1; i <= count; i++) { - vecSend.push_back(make_pair(scriptNewAddr, 10*COIN)); - vecSend.push_back(make_pair(scriptNewAddr2, POOL_FEE_AMOUNT+(0.01*COIN))); - } - - //try to create the larger size input - if(pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, strError, NULL, true)){ - if (pwalletMain->CommitTransaction(wtxNew, reservekey)) { - //if successfull, create the collateral needed to submit - done = true; - successful = count; - } - } - count--; - } - - ostringstream convert; - if(successful == 0) { - convert << "An error occurred created DarkSend compatible inputs. Error was " << strError; - } else { - convert << "Created inputs for " << successful << " DarkSends"; - } - return convert.str(); + return darkSendPool.Denominate(); } Value getdarksendtxid(const Array& params, bool fHelp) diff --git a/src/wallet.cpp b/src/wallet.cpp index 8e516abeb5..b46099a703 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1577,11 +1577,11 @@ string CWallet::DarkSendMoney(const CTxDestination& address, int64 nValue) if (!SelectCoinsExactOutput(10*COIN, vin, nValueIn, pubScript, true, coinControl)) { - if (!SelectCoinsExactOutput(10*COIN, vin, nValueIn, pubScript, false, coinControl)) + if (SelectCoinsExactOutput(10*COIN, vin, nValueIn, pubScript, false, coinControl)) { return _("Found an unspend output equal to 10DRK, but it is non-confirmed, please wait for a confirmation before using DarkSend."); } - return _("Couldn't find a confirmed unspend output equal to 10DRK."); + return _("Couldn't find a confirmed unspend output equal to 10DRK. Run denominate."); } CTxOut out(nValue, scriptPubKey); @@ -1600,6 +1600,65 @@ string CWallet::DarkSendMoney(const CTxDestination& address, int64 nValue) return ""; } +std::string CWallet::Denominate() +{ + + int count = 10; + int successful = 0; + bool done = false; + + if(GetBalance() < 11*COIN){ + return "To use denominate you must have at least 11DRK with 1 confirmation."; + } + + int64 nFeeRequired; + string strError; + CReserveKey reservekey(this); + + // create another transaction as collateral for using DarkSend + while(!done && count > 0) + { + + CWalletTx wtxNew; + CWalletTx wtxNew2; + + //get 2 new keys + CScript scriptNewAddr; + CPubKey vchPubKey; + assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked + scriptNewAddr.SetDestination(vchPubKey.GetID()); + + CScript scriptNewAddr2; + CPubKey vchPubKey2; + assert(reservekey.GetReservedKey(vchPubKey2)); // should never fail, as we just unlocked + scriptNewAddr2.SetDestination(vchPubKey2.GetID()); + + vector< pair > vecSend; + for(int i = 1; i <= count; i++) { + vecSend.push_back(make_pair(scriptNewAddr, 10*COIN)); + vecSend.push_back(make_pair(scriptNewAddr2, POOL_FEE_AMOUNT+(0.01*COIN))); + } + + //try to create the larger size input + if(CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, strError, NULL, true)){ + if (CommitTransaction(wtxNew, reservekey)) { + //if successfull, create the collateral needed to submit + done = true; + successful = count; + } + } + count--; + } + + ostringstream convert; + if(successful == 0) { + convert << "An error occurred created DarkSend compatible inputs. Error was " << strError; + } else { + convert << "Created inputs for " << successful << " DarkSends"; + } + return convert.str(); +} + DBErrors CWallet::LoadWallet(bool& fFirstRunRet) { if (!fFileBacked) diff --git a/src/wallet.h b/src/wallet.h index c65031dcb7..945ef8755b 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -127,7 +127,7 @@ public: // check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } - + std::string Denominate(); void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool noDenominatedInputs=false) const; void AvailableCoins2(std::vector& vCoins, bool fOnlyConfirmed) const; bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64& nValueRet) const;