|
|
@ -2202,7 +2202,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const |
|
|
|
/**
|
|
|
|
* populate vCoins with vector of available COutputs. |
|
|
|
*/ |
|
|
|
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); |
|
|
|
uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); |
|
|
|
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); |
|
|
|
|
|
|
|
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const |
|
|
@ -2250,9 +2250,9 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const |
|
|
|
komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue); |
|
|
|
if ( (tipindex= chainActive.Tip()) != 0 ) |
|
|
|
{ |
|
|
|
interest = komodo_interest(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); |
|
|
|
interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); |
|
|
|
} else interest = 0; |
|
|
|
//interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime);
|
|
|
|
//interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime);
|
|
|
|
if ( interest != 0 ) |
|
|
|
{ |
|
|
|
//printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime);
|
|
|
@ -2333,13 +2333,12 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, uint64_t *interestp) const |
|
|
|
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const |
|
|
|
{ |
|
|
|
uint64_t interests[10000],lowest_interest = 0; int32_t count = 0; |
|
|
|
int32_t count = 0; //uint64_t lowest_interest = 0;
|
|
|
|
setCoinsRet.clear(); |
|
|
|
memset(interests,0,sizeof(interests)); |
|
|
|
//memset(interests,0,sizeof(interests));
|
|
|
|
nValueRet = 0; |
|
|
|
//*interestp = 0;
|
|
|
|
// List of values less than target
|
|
|
|
pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger; |
|
|
|
coinLowestLarger.first = std::numeric_limits<CAmount>::max(); |
|
|
@ -2368,20 +2367,20 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
{ |
|
|
|
setCoinsRet.insert(coin.second); |
|
|
|
nValueRet += coin.first; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 ) |
|
|
|
*interestp += pcoin->vout[i].interest; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 )
|
|
|
|
// *interestp += pcoin->vout[i].interest;
|
|
|
|
return true; |
|
|
|
} |
|
|
|
else if (n < nTargetValue + CENT) |
|
|
|
{ |
|
|
|
vValue.push_back(coin); |
|
|
|
nTotalLower += n; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 && count < sizeof(interests)/sizeof(*interests) ) |
|
|
|
{ |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 && count < sizeof(interests)/sizeof(*interests) )
|
|
|
|
//{
|
|
|
|
//fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN);
|
|
|
|
interests[count++] = pcoin->vout[i].interest; |
|
|
|
} |
|
|
|
if ( count >= sizeof(interests)/sizeof(*interests) && nTotalLower > 2*nTargetValue + CENT ) |
|
|
|
//interests[count++] = pcoin->vout[i].interest;
|
|
|
|
//}
|
|
|
|
if ( nTotalLower > 4*nTargetValue + CENT ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"why bother with all the utxo if we have double what is needed?\n");
|
|
|
|
break; |
|
|
@ -2390,8 +2389,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
else if (n < coinLowestLarger.first) |
|
|
|
{ |
|
|
|
coinLowestLarger = coin; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 ) |
|
|
|
lowest_interest = pcoin->vout[i].interest; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 )
|
|
|
|
// lowest_interest = pcoin->vout[i].interest;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -2401,8 +2400,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
{ |
|
|
|
setCoinsRet.insert(vValue[i].second); |
|
|
|
nValueRet += vValue[i].first; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) |
|
|
|
*interestp += interests[i]; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 && i < count )
|
|
|
|
// *interestp += interests[i];
|
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
@ -2413,8 +2412,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
return false; |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
|
nValueRet += coinLowestLarger.first; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 ) |
|
|
|
*interestp += lowest_interest; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 )
|
|
|
|
// *interestp += lowest_interest;
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -2434,8 +2433,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
{ |
|
|
|
setCoinsRet.insert(coinLowestLarger.second); |
|
|
|
nValueRet += coinLowestLarger.first; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 ) |
|
|
|
*interestp += lowest_interest; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 )
|
|
|
|
// *interestp += lowest_interest;
|
|
|
|
} |
|
|
|
else { |
|
|
|
for (unsigned int i = 0; i < vValue.size(); i++) |
|
|
@ -2443,8 +2442,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
{ |
|
|
|
setCoinsRet.insert(vValue[i].second); |
|
|
|
nValueRet += vValue[i].first; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) |
|
|
|
*interestp += interests[i]; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 && i < count )
|
|
|
|
// *interestp += interests[i];
|
|
|
|
} |
|
|
|
|
|
|
|
LogPrint("selectcoins", "SelectCoins() best subset: "); |
|
|
@ -2457,15 +2456,15 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const |
|
|
|
bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const |
|
|
|
{ |
|
|
|
// Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos.
|
|
|
|
uint64_t tmp,interest = 0; int32_t retval; |
|
|
|
if ( interestp == 0 ) |
|
|
|
{ |
|
|
|
interestp = &tmp; |
|
|
|
*interestp = 0; |
|
|
|
} |
|
|
|
uint64_t tmp; int32_t retval; |
|
|
|
//if ( interestp == 0 )
|
|
|
|
//{
|
|
|
|
// interestp = &tmp;
|
|
|
|
// *interestp = 0;
|
|
|
|
//}
|
|
|
|
vector<COutput> vCoinsNoCoinbase, vCoinsWithCoinbase; |
|
|
|
AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); |
|
|
|
AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); |
|
|
@ -2507,8 +2506,8 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx* |
|
|
|
if (!out.fSpendable) |
|
|
|
continue; |
|
|
|
nValueRet += out.tx->vout[out.i].nValue; |
|
|
|
if ( KOMODO_EXCHANGEWALLET == 0 ) |
|
|
|
*interestp += out.tx->vout[out.i].interest; |
|
|
|
//if ( KOMODO_EXCHANGEWALLET == 0 )
|
|
|
|
// *interestp += out.tx->vout[out.i].interest;
|
|
|
|
setCoinsRet.insert(make_pair(out.tx, out.i)); |
|
|
|
} |
|
|
|
return (nValueRet >= nTargetValue); |
|
|
@ -2548,36 +2547,16 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx* |
|
|
|
retval = false; |
|
|
|
if ( nTargetValue <= nValueFromPresetInputs ) |
|
|
|
retval = true; |
|
|
|
else if ( SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) |
|
|
|
{ |
|
|
|
*interestp += interest; |
|
|
|
else if ( SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet) != 0 ) |
|
|
|
retval = true; |
|
|
|
} |
|
|
|
else if ( SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) |
|
|
|
{ |
|
|
|
*interestp += interest; |
|
|
|
else if ( SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet) != 0 ) |
|
|
|
retval = true; |
|
|
|
} |
|
|
|
else if ( bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) |
|
|
|
{ |
|
|
|
*interestp += interest; |
|
|
|
else if ( bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet) != 0 ) |
|
|
|
retval = true; |
|
|
|
} |
|
|
|
|
|
|
|
//return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) ||
|
|
|
|
// SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) ||
|
|
|
|
// (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp)));
|
|
|
|
/*bool res = nTargetValue <= nValueFromPresetInputs ||
|
|
|
|
SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 6, vCoins, setCoinsRet, nValueRet) || |
|
|
|
SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 1, 1, vCoins, setCoinsRet, nValueRet) || |
|
|
|
(bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue - nValueFromPresetInputs, 0, 1, vCoins, setCoinsRet, nValueRet));*/ |
|
|
|
|
|
|
|
// because SelectCoinsMinConf clears the setCoinsRet, we now add the possible inputs to the coinset
|
|
|
|
setCoinsRet.insert(setPresetCoins.begin(), setPresetCoins.end()); |
|
|
|
|
|
|
|
// add preset inputs to the total value selected
|
|
|
|
nValueRet += nValueFromPresetInputs; |
|
|
|
|
|
|
|
return retval; |
|
|
|
} |
|
|
|
|
|
|
@ -2627,7 +2606,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount &nFeeRet, int& nC |
|
|
|
bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, |
|
|
|
int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl, bool sign) |
|
|
|
{ |
|
|
|
uint64_t interest2,interest = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; |
|
|
|
uint64_t interest2 = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; |
|
|
|
BOOST_FOREACH (const CRecipient& recipient, vecSend) |
|
|
|
{ |
|
|
|
if (nValue < 0 || recipient.nAmount < 0) |
|
|
@ -2684,7 +2663,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt |
|
|
|
nFeeRet = 0; |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
interest = 0; |
|
|
|
//interest = 0;
|
|
|
|
txNew.vin.clear(); |
|
|
|
txNew.vout.clear(); |
|
|
|
wtxNew.fFromMe = true; |
|
|
@ -2733,7 +2712,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt |
|
|
|
bool fOnlyCoinbaseCoins = false; |
|
|
|
bool fNeedCoinbaseCoins = false; |
|
|
|
interest2 = 0; |
|
|
|
if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) |
|
|
|
if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl)) |
|
|
|
{ |
|
|
|
if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { |
|
|
|
strFailReason = _("Coinbase funds can only be sent to a zaddr"); |
|
|
@ -2762,13 +2741,13 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt |
|
|
|
age += 1; |
|
|
|
dPriority += (double)nCredit * age; |
|
|
|
} |
|
|
|
if ( KOMODO_EXCHANGEWALLET != 0 ) |
|
|
|
{ |
|
|
|
//if ( KOMODO_EXCHANGEWALLET != 0 )
|
|
|
|
//{
|
|
|
|
//fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN);
|
|
|
|
interest = 0; // interest2 also
|
|
|
|
} |
|
|
|
//interest = 0; // interest2 also
|
|
|
|
//}
|
|
|
|
CAmount nChange = (nValueIn - nValue + interest2); |
|
|
|
fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)interest/COIN,(double)nTotalValue/COIN); |
|
|
|
fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN); |
|
|
|
if (nSubtractFeeFromAmount == 0) |
|
|
|
nChange -= nFeeRet; |
|
|
|
|
|
|
|