mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
add new enum for coin selection
This commit is contained in:
parent
29e02ed8a0
commit
7b2d19c077
@ -42,7 +42,7 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
|
||||
{
|
||||
int64 nBalance = 0;
|
||||
std::vector<COutput> vCoins;
|
||||
wallet->AvailableCoins(vCoins, true, coinControl);
|
||||
wallet->AvailableCoins(vCoins, true, coinControl, ALL_COINS);
|
||||
BOOST_FOREACH(const COutput& out, vCoins)
|
||||
nBalance += out.tx->vout[out.i].nValue;
|
||||
|
||||
@ -199,8 +199,10 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
|
||||
int64 nFeeRequired = 0;
|
||||
std::string strFailReason;
|
||||
bool fCreated = false;
|
||||
AvailableCoinsType act = ONLY_NONDENOMINATED;
|
||||
if(isDarkSend) act = ONLY_DENOMINATED;
|
||||
|
||||
fCreated = wallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason, coinControl, isDarkSend);
|
||||
fCreated = wallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason, coinControl, act);
|
||||
|
||||
if(!fCreated)
|
||||
{
|
||||
@ -423,8 +425,9 @@ void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vect
|
||||
// AvailableCoins + LockedCoins grouped by wallet address (put change in one group with wallet address)
|
||||
void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const
|
||||
{
|
||||
CCoinControl *coinControl=NULL;
|
||||
std::vector<COutput> vCoins;
|
||||
wallet->AvailableCoins(vCoins);
|
||||
wallet->AvailableCoins(vCoins, true, coinControl, ALL_COINS);
|
||||
|
||||
std::vector<COutPoint> vLockedCoins;
|
||||
wallet->ListLockedCoins(vLockedCoins);
|
||||
|
@ -965,7 +965,7 @@ int64 CWallet::GetImmatureBalance() const
|
||||
}
|
||||
|
||||
// populate vCoins with vector of spendable COutputs
|
||||
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool onlyDarksendInputs) const
|
||||
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, AvailableCoinsType coin_type) const
|
||||
{
|
||||
vCoins.clear();
|
||||
|
||||
@ -986,19 +986,21 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
|
||||
|
||||
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
|
||||
bool found = false;
|
||||
if(onlyDarksendInputs) {
|
||||
if(coin_type == ONLY_DENOMINATED) {
|
||||
//should make this a vector
|
||||
|
||||
COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain());
|
||||
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
|
||||
int rounds = darkSendPool.GetInputDarksendRounds(vin);
|
||||
if(rounds >= nDarksendRounds) found = true;
|
||||
} else {
|
||||
} else if(coin_type == ONLY_NONDENOMINATED) {
|
||||
found = true;
|
||||
BOOST_FOREACH(int64 d, darkSendDenominations)
|
||||
if(pcoin->vout[i].nValue == d)
|
||||
found = false;
|
||||
|
||||
} else {
|
||||
found = true;
|
||||
}
|
||||
if(!found) continue;
|
||||
|
||||
@ -1208,10 +1210,10 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::SelectCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl, bool onlyDarksendInputs) const
|
||||
bool CWallet::SelectCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type) const
|
||||
{
|
||||
vector<COutput> vCoins;
|
||||
AvailableCoins(vCoins, true, coinControl, onlyDarksendInputs);
|
||||
AvailableCoins(vCoins, true, coinControl, coin_type);
|
||||
|
||||
// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
|
||||
if (coinControl && coinControl->HasSelected())
|
||||
@ -1269,7 +1271,7 @@ bool CWallet::SelectCoinsWithoutDenomination(int64 nTargetValue, set<pair<const
|
||||
CCoinControl *coinControl=NULL;
|
||||
|
||||
vector<COutput> vCoins;
|
||||
AvailableCoins(vCoins, true, coinControl, true);
|
||||
AvailableCoins(vCoins, true, coinControl, ONLY_NONDENOMINATED);
|
||||
|
||||
BOOST_FOREACH(const COutput& out, vCoins)
|
||||
{
|
||||
@ -1298,7 +1300,7 @@ bool CWallet::SelectCoinsMoreThanOutput(int64 nTargetValue, CTxIn& vin, int64& n
|
||||
}
|
||||
|
||||
bool CWallet::CreateTransaction(std::vector<pair<CScript, int64> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, bool onlyDarkSendInputs)
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl, AvailableCoinsType coin_type)
|
||||
{
|
||||
int64 nValue = 0;
|
||||
BOOST_FOREACH (PAIRTYPE(CScript, int64)& s, vecSend)
|
||||
@ -1349,9 +1351,9 @@ bool CWallet::CreateTransaction(std::vector<pair<CScript, int64> >& vecSend,
|
||||
// Choose coins to use
|
||||
set<pair<const CWalletTx*,unsigned int> > setCoins;
|
||||
int64 nValueIn = 0;
|
||||
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, onlyDarkSendInputs))
|
||||
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type))
|
||||
{
|
||||
if(!onlyDarkSendInputs)
|
||||
if(coin_type == ALL_COINS || coin_type == ONLY_NONDENOMINATED)
|
||||
strFailReason = _("Insufficient funds");
|
||||
else
|
||||
strFailReason = _("Unable to locate enough Darksend denominated funds for this transaction");
|
||||
|
13
src/wallet.h
13
src/wallet.h
@ -35,6 +35,13 @@ enum WalletFeature
|
||||
FEATURE_LATEST = 60000
|
||||
};
|
||||
|
||||
enum AvailableCoinsType
|
||||
{
|
||||
ALL_COINS = 1,
|
||||
ONLY_DENOMINATED = 2,
|
||||
ONLY_NONDENOMINATED = 3
|
||||
};
|
||||
|
||||
|
||||
/** A key pool entry */
|
||||
class CKeyPool
|
||||
@ -79,7 +86,7 @@ private:
|
||||
int nWalletMaxVersion;
|
||||
|
||||
public:
|
||||
bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false) const;
|
||||
bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS) const;
|
||||
bool SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector<CTxIn>& setCoinsRet, int64& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const;
|
||||
bool SelectCoinsDarkDenominated(int64 nTargetValue, std::vector<CTxIn>& setCoinsRet, int64& nValueRet) const;
|
||||
bool SelectCoinsExactOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed) const;
|
||||
@ -132,7 +139,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(CWalletTx& wtxDenominate);
|
||||
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false) const;
|
||||
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS) 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;
|
||||
bool IsLockedCoin(uint256 hash, unsigned int n) const;
|
||||
@ -188,7 +195,7 @@ public:
|
||||
int64 GetUnconfirmedBalance() const;
|
||||
int64 GetImmatureBalance() const;
|
||||
bool CreateTransaction(std::vector<std::pair<CScript, int64> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL, bool onlyDarksendInputs=false);
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS);
|
||||
bool CreateTransaction(CScript scriptPubKey, int64 nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl=NULL);
|
||||
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
|
||||
|
Loading…
Reference in New Issue
Block a user