-exchange mode

This commit is contained in:
jl777
2017-02-04 15:16:51 +02:00
parent db409a6ea0
commit 6ad13d7c20
4 changed files with 49 additions and 38 deletions

View File

@@ -38,7 +38,7 @@ Dependencies
``` ```
#The following packages are needed: #The following packages are needed:
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate sudo apt-get install build-essential pkg-config libcurl-gnutls libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate
``` ```
Komodo Komodo

View File

@@ -38,7 +38,7 @@ struct komodo_state KOMODO_STATES[34];
int COINBASE_MATURITY = 100; int COINBASE_MATURITY = 100;
int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX; int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
uint8_t NOTARY_PUBKEY33[33]; uint8_t NOTARY_PUBKEY33[33];

View File

@@ -1454,6 +1454,7 @@ void komodo_args()
extern int64_t MAX_MONEY; extern int64_t MAX_MONEY;
std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,baseid,len; std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,baseid,len;
IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
KOMODO_EXCHANGEWALLET = GetBoolArg("-exchange", false);
NOTARY_PUBKEY = GetArg("-pubkey", ""); NOTARY_PUBKEY = GetArg("-pubkey", "");
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
{ {

View File

@@ -37,6 +37,7 @@ unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
bool bSpendZeroConfChange = true; bool bSpendZeroConfChange = true;
bool fSendFreeTransactions = false; bool fSendFreeTransactions = false;
bool fPayAtLeastCustomFee = true; bool fPayAtLeastCustomFee = true;
extern int32_t KOMODO_EXCHANGEWALLET;
/** /**
* Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
@@ -2242,7 +2243,8 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
!IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) &&
(!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i)))
{ {
#ifdef KOMODO_ENABLE_INTEREST if ( KOMODO_EXCHANGEWALLET == 0 )
{
extern char ASSETCHAINS_SYMBOL[16]; extern char ASSETCHAINS_SYMBOL[16];
uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; uint32_t locktime; int32_t txheight; CBlockIndex *tipindex;
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 )
@@ -2282,7 +2284,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
ptr = (uint64_t *)&pcoin->vout[i].interest; ptr = (uint64_t *)&pcoin->vout[i].interest;
(*ptr) = 0; (*ptr) = 0;
} }
#endif }
vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO)); vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO));
} }
} }
@@ -2337,7 +2339,7 @@ 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, uint64_t *interestp) const
{ {
uint64_t interests[512],lowest_interest = 0; int32_t count = 0; uint64_t interests[1024],lowest_interest = 0; int32_t count = 0;
setCoinsRet.clear(); setCoinsRet.clear();
memset(interests,0,sizeof(interests)); memset(interests,0,sizeof(interests));
nValueRet = 0; nValueRet = 0;
@@ -2370,6 +2372,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
{ {
setCoinsRet.insert(coin.second); setCoinsRet.insert(coin.second);
nValueRet += coin.first; nValueRet += coin.first;
if ( KOMODO_EXCHANGEWALLET == 0 )
*interestp += pcoin->vout[i].interest; *interestp += pcoin->vout[i].interest;
return true; return true;
} }
@@ -2377,7 +2380,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
{ {
vValue.push_back(coin); vValue.push_back(coin);
nTotalLower += n; nTotalLower += n;
if ( 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); //fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN);
interests[count++] = pcoin->vout[i].interest; interests[count++] = pcoin->vout[i].interest;
@@ -2386,6 +2389,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
else if (n < coinLowestLarger.first) else if (n < coinLowestLarger.first)
{ {
coinLowestLarger = coin; coinLowestLarger = coin;
if ( KOMODO_EXCHANGEWALLET == 0 )
lowest_interest = pcoin->vout[i].interest; lowest_interest = pcoin->vout[i].interest;
} }
} }
@@ -2396,7 +2400,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
{ {
setCoinsRet.insert(vValue[i].second); setCoinsRet.insert(vValue[i].second);
nValueRet += vValue[i].first; nValueRet += vValue[i].first;
if ( i < count ) if ( KOMODO_EXCHANGEWALLET == 0 && i < count )
*interestp += interests[i]; *interestp += interests[i];
} }
return true; return true;
@@ -2408,6 +2412,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
return false; return false;
setCoinsRet.insert(coinLowestLarger.second); setCoinsRet.insert(coinLowestLarger.second);
nValueRet += coinLowestLarger.first; nValueRet += coinLowestLarger.first;
if ( KOMODO_EXCHANGEWALLET == 0 )
*interestp += lowest_interest; *interestp += lowest_interest;
return true; return true;
} }
@@ -2428,6 +2433,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
{ {
setCoinsRet.insert(coinLowestLarger.second); setCoinsRet.insert(coinLowestLarger.second);
nValueRet += coinLowestLarger.first; nValueRet += coinLowestLarger.first;
if ( KOMODO_EXCHANGEWALLET == 0 )
*interestp += lowest_interest; *interestp += lowest_interest;
} }
else { else {
@@ -2436,7 +2442,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
{ {
setCoinsRet.insert(vValue[i].second); setCoinsRet.insert(vValue[i].second);
nValueRet += vValue[i].first; nValueRet += vValue[i].first;
if ( i < count ) if ( KOMODO_EXCHANGEWALLET == 0 && i < count )
*interestp += interests[i]; *interestp += interests[i];
} }
@@ -2495,6 +2501,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*
if(!out.fSpendable) if(!out.fSpendable)
continue; continue;
nValueRet += out.tx->vout[out.i].nValue; nValueRet += out.tx->vout[out.i].nValue;
if ( KOMODO_EXCHANGEWALLET == 0 )
*interestp += out.tx->vout[out.i].interest; *interestp += out.tx->vout[out.i].interest;
setCoinsRet.insert(make_pair(out.tx, out.i)); setCoinsRet.insert(make_pair(out.tx, out.i));
} }
@@ -2634,13 +2641,16 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
//a chance at a free transaction. //a chance at a free transaction.
//But mempool inputs might still be in the mempool, so their age stays 0 //But mempool inputs might still be in the mempool, so their age stays 0
//fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN);
if ( KOMODO_EXCHANGEWALLET == 0 )
interest2 += pcoin.first->vout[pcoin.second].interest; interest2 += pcoin.first->vout[pcoin.second].interest;
int age = pcoin.first->GetDepthInMainChain(); int age = pcoin.first->GetDepthInMainChain();
if (age != 0) if (age != 0)
age += 1; age += 1;
dPriority += (double)nCredit * age; dPriority += (double)nCredit * age;
} }
//fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); if ( KOMODO_EXCHANGEWALLET != 0 )
interest = 0;
//fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN);
CAmount nChange = (nValueIn - nValue + interest); CAmount nChange = (nValueIn - nValue + interest);
//fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); //fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN);
if (nSubtractFeeFromAmount == 0) if (nSubtractFeeFromAmount == 0)