added denominate button

This commit is contained in:
Evan 2014-03-10 11:15:13 -07:00
parent 810b5612c2
commit 0da3498ed0
9 changed files with 114 additions and 55 deletions

View File

@ -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 ) {

View File

@ -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
(

View File

@ -5,6 +5,7 @@
<file alias="quit">res/icons/quit.png</file>
<file alias="send">res/icons/send.png</file>
<file alias="toolbar">res/icons/toolbar.png</file>
<file alias="denominate">res/icons/denominate.png</file>
<file alias="connect_0">res/icons/connect0_16.png</file>
<file alias="connect_1">res/icons/connect1_16.png</file>
<file alias="connect_2">res/icons/connect2_16.png</file>

View File

@ -702,6 +702,32 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="denominateButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Create inputs compatible with DarkSend</string>
</property>
<property name="text">
<string>Denominate</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/denominate</normaloff>:/icons/denominate</iconset>
</property>
<property name="autoRepeatDelay">
<number>300</number>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">

View File

@ -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();

View File

@ -36,6 +36,7 @@ public:
public slots:
void clear();
void denominate();
void reject();
void accept();
SendCoinsEntry *addEntry();

View File

@ -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.";
}
int64 nFeeRequired;
string strError;
// create another transaction as collateral for using DarkSend
while(!done && count > 0)
if (pwalletMain->IsLocked())
{
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<CScript, int64> > 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)));
return _("Error: Wallet locked, unable to denominate! Use walletpassphrase to unlock. ");
}
//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)

View File

@ -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<CScript, int64> > 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)

View File

@ -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<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool noDenominatedInputs=false) const;
void AvailableCoins2(std::vector<COutput>& vCoins, bool fOnlyConfirmed) const;
bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;