Skip to content

Commit

Permalink
Merge pull request #537 from UdjinM6/v0.12.0.x_fix_ds
Browse files Browse the repository at this point in the history
V0.12.0.x fix ds
  • Loading branch information
evan82 committed Aug 16, 2015
2 parents cfbcc81 + a723c21 commit 8a24144
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
14 changes: 7 additions & 7 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
if(nBalanceNeedsDenominated > nOnlyDenominatedBalance) return CreateDenominated(nBalanceNeedsDenominated);

//check if we have the collateral sized inputs
if(!pwalletMain->HasCollateralInputs()) return MakeCollateralAmounts();
if(!pwalletMain->HasCollateralInputs()) return !pwalletMain->HasCollateralInputs(false) && MakeCollateralAmounts();

std::vector<CTxOut> vOut;

Expand Down Expand Up @@ -1692,15 +1692,15 @@ bool CDarksendPool::MakeCollateralAmounts()

// try to use non-denominated and not mn-like funds
bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN);
nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOT1000IFMN);
if(!success){
// if we failed (most likeky not enough funds), try to use denominated instead -
// if we failed (most likeky not enough funds), try to use all coins instead -
// MN-like funds should not be touched in any case and we can't mix denominated without collaterals anyway
LogPrintf("MakeCollateralAmounts: ONLY_NONDENOMINATED_NOTMN Error - %s\n", strFail);
LogPrintf("MakeCollateralAmounts: ONLY_NONDENOMINATED_NOT1000IFMN Error - %s\n", strFail);
success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, strFail, coinControl, ONLY_DENOMINATED);
nFeeRet, strFail, coinControl, ONLY_NOT1000IFMN);
if(!success){
LogPrintf("MakeCollateralAmounts: ONLY_DENOMINATED Error - %s\n", strFail);
LogPrintf("MakeCollateralAmounts: ONLY_NOT1000IFMN Error - %s\n", strFail);
reservekeyCollateral.ReturnKey();
return false;
}
Expand Down Expand Up @@ -1778,7 +1778,7 @@ bool CDarksendPool::CreateDenominated(int64_t nTotalValue)

CCoinControl *coinControl=NULL;
bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekeyChange,
nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOTMN);
nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED_NOT1000IFMN);
if(!success){
LogPrintf("CreateDenominated: Error - %s\n", strFail);
// TODO: return reservekeyDenom here
Expand Down
35 changes: 10 additions & 25 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,13 +1514,13 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
bool found = false;
if(coin_type == ONLY_DENOMINATED) {
//should make this a vector

found = IsDenominatedAmount(pcoin->vout[i].nValue);
} else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_NOTMN) {
} else if(coin_type == ONLY_NOT1000IFMN) {
found = !(fMasterNode && pcoin->vout[i].nValue == 1000*COIN);
} else if(coin_type == ONLY_NONDENOMINATED_NOT1000IFMN) {
if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts
found = !IsDenominatedAmount(pcoin->vout[i].nValue);
if(found && fMasterNode && coin_type == ONLY_NONDENOMINATED_NOTMN) found = (pcoin->vout[i].nValue != 1000*COIN); // do not use MN funds
if(found && fMasterNode) found = pcoin->vout[i].nValue != 1000*COIN; // do not use Hot MN funds
} else {
found = true;
}
Expand Down Expand Up @@ -1871,7 +1871,7 @@ bool CWallet::SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<
nValueRet = 0;

vector<COutput> vCoins;
AvailableCoins(vCoins, true, coinControl, nDarksendRoundsMin < 0 ? ONLY_NONDENOMINATED_NOTMN : ONLY_DENOMINATED);
AvailableCoins(vCoins, true, coinControl, nDarksendRoundsMin < 0 ? ONLY_NONDENOMINATED_NOT1000IFMN : ONLY_DENOMINATED);

set<pair<const CWalletTx*,unsigned int> > setCoinsRet2;

Expand Down Expand Up @@ -1963,10 +1963,10 @@ int CWallet::CountInputsWithAmount(int64_t nInputAmount)
return nTotal;
}

bool CWallet::HasCollateralInputs() const
bool CWallet::HasCollateralInputs(bool fOnlyConfirmed) const
{
vector<COutput> vCoins;
AvailableCoins(vCoins);
AvailableCoins(vCoins, fOnlyConfirmed);

int nFound = 0;
BOOST_FOREACH(const COutput& out, vCoins)
Expand All @@ -1980,21 +1980,6 @@ bool CWallet::IsCollateralAmount(int64_t nInputAmount) const
return nInputAmount != 0 && nInputAmount % DARKSEND_COLLATERAL == 0 && nInputAmount < DARKSEND_COLLATERAL * 5 && nInputAmount > DARKSEND_COLLATERAL;
}

bool CWallet::SelectCoinsWithoutDenomination(int64_t nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
CCoinControl *coinControl=NULL;

vector<COutput> vCoins;
AvailableCoins(vCoins, true, coinControl, ONLY_NONDENOMINATED);

BOOST_FOREACH(const COutput& out, vCoins)
{
nValueRet += out.tx->vout[out.i].nValue;
setCoinsRet.insert(make_pair(out.tx, out.i));
}
return (nValueRet >= nTargetValue);
}

bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason)
{
/*
Expand Down Expand Up @@ -2156,9 +2141,9 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
{
if(coin_type == ALL_COINS) {
strFailReason = _("Insufficient funds.");
} else if (coin_type == ONLY_NONDENOMINATED) {
strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction.");
} else if (coin_type == ONLY_NONDENOMINATED_NOTMN) {
} else if (coin_type == ONLY_NOT1000IFMN) {
strFailReason = _("Unable to locate enough funds for this transaction that are not equal 1000 DASH.");
} else if (coin_type == ONLY_NONDENOMINATED_NOT1000IFMN) {
strFailReason = _("Unable to locate enough Darksend non-denominated funds for this transaction that are not equal 1000 DASH.");
} else {
strFailReason = _("Unable to locate enough Darksend denominated funds for this transaction.");
Expand Down
7 changes: 3 additions & 4 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ enum AvailableCoinsType
{
ALL_COINS = 1,
ONLY_DENOMINATED = 2,
ONLY_NONDENOMINATED = 3,
ONLY_NONDENOMINATED_NOTMN = 4 // ONLY_NONDENOMINATED and not 1000 DASH at the same time
ONLY_NOT1000IFMN = 3,
ONLY_NONDENOMINATED_NOT1000IFMN = 4
};


Expand Down Expand Up @@ -151,12 +151,11 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector<CTxIn>& setCoinsRet, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const;
bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector<CTxIn>& vCoinsRet, std::vector<COutput>& vCoinsRet2, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax);
bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector<CTxIn>& setCoinsRet, int64_t& nValueRet) const;
bool HasCollateralInputs() const;
bool HasCollateralInputs(bool fOnlyConfirmed = true) const;
bool IsCollateralAmount(int64_t nInputAmount) const;
int CountInputsWithAmount(int64_t nInputAmount);

bool SelectCoinsCollateral(std::vector<CTxIn>& setCoinsRet, int64_t& nValueRet) const ;
bool SelectCoinsWithoutDenomination(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const;

/*
* Main wallet lock.
Expand Down

0 comments on commit 8a24144

Please sign in to comment.