From ae14019e6d6854243b89a8ec7c118c64caeac4c3 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 11 Sep 2015 21:19:14 +0300 Subject: [PATCH] IX fixes: - refactor initialization/fix initial values - use global `fEnableInstantX` - rpc output: `confirmations` (i.e. total) and `bcconfirmations` (blockchain only), fixes #593 also - throw error in UI before submiting IX if it violates max amount --- src/init.cpp | 18 +++++++++--------- src/qt/walletmodel.cpp | 6 ++++++ src/rpcwallet.cpp | 22 ++++++++++++++++++++-- src/util.cpp | 3 ++- src/util.h | 1 + src/wallet.cpp | 4 ++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 901f7397940e..db615b4088ef 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -425,7 +425,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += "\n" + _("InstantX options:") + "\n"; strUsage += " -enableinstantx= " + strprintf(_("Enable instantx, show confirmations for locked transactions (bool, default: %s)"), "true") + "\n"; - strUsage += " -instantxdepth= " + strprintf(_("Show N confirmations for a successfully locked transaction (0-9999, default: %u)"), 1) + "\n"; + strUsage += " -instantxdepth= " + strprintf(_("Show N confirmations for a successfully locked transaction (0-9999, default: %u)"), nInstantXDepth) + "\n"; strUsage += "\n" + _("Node relay options:") + "\n"; strUsage += " -datacarrier " + strprintf(_("Relay and mine data carrier transactions (default: %u)"), 1) + "\n"; @@ -698,6 +698,11 @@ bool AppInit2(boost::thread_group& threadGroup) LogPrintf("AppInit2 : parameter interaction: -zapwallettxes= -> setting -rescan=1\n"); } + if(!GetBoolArg("-enableinstantx", fEnableInstantX)){ + if (SoftSetArg("-instantxdepth", 0)) + LogPrintf("AppInit2 : parameter interaction: -enableinstantx=false -> setting -nInstantXDepth=0\n"); + } + // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); nMaxConnections = GetArg("-maxconnections", 125); @@ -1532,14 +1537,9 @@ bool AppInit2(boost::thread_group& threadGroup) if(nAnonymizeDarkcoinAmount > 999999) nAnonymizeDarkcoinAmount = 999999; if(nAnonymizeDarkcoinAmount < 2) nAnonymizeDarkcoinAmount = 2; - bool fEnableInstantX = GetBoolArg("-enableinstantx", true); - if(fEnableInstantX){ - nInstantXDepth = GetArg("-instantxdepth", 5); - if(nInstantXDepth > 60) nInstantXDepth = 60; - if(nInstantXDepth < 0) nAnonymizeDarkcoinAmount = 0; - } else { - nInstantXDepth = 0; - } + fEnableInstantX = GetBoolArg("-enableinstantx", fEnableInstantX); + nInstantXDepth = GetArg("-instantxdepth", nInstantXDepth); + nInstantXDepth = std::min(std::max(nInstantXDepth, 0), 60); //lite mode disables all Masternode and Darksend related functionality fLiteMode = GetBoolArg("-litemode", false); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 82d272eb8423..71179e791f15 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -297,6 +297,12 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, recipients[0].inputType, recipients[0].useInstantX); transaction.setTransactionFee(nFeeRequired); + if(recipients[0].useInstantX && newTx->GetValueOut() > GetSporkValue(SPORK_5_MAX_VALUE)*COIN){ + emit message(tr("Send Coins"), tr("InstantX doesn't support sending values that high yet. Transactions are currently limited to %1 DASH.").arg(GetSporkValue(SPORK_5_MAX_VALUE)), + CClientUIInterface::MSG_ERROR); + return TransactionCreationFailed; + } + if(!fCreated) { if((total + nFeeRequired) > nBalance) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 844936e80490..f660860fc600 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -48,7 +48,9 @@ void EnsureWalletIsUnlocked() void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { int confirms = wtx.GetDepthInMainChain(false); - entry.push_back(Pair("confirmations", confirms)); + int confirmsTotal = wtx.GetDepthInMainChain(); + entry.push_back(Pair("confirmations", confirmsTotal)); + entry.push_back(Pair("bcconfirmations", confirms)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) @@ -1006,12 +1008,14 @@ struct tallyitem { CAmount nAmount; int nConf; + int nBCConf; vector txids; bool fIsWatchonly; tallyitem() { nAmount = 0; nConf = std::numeric_limits::max(); + nBCConf = std::numeric_limits::max(); fIsWatchonly = false; } }; @@ -1043,6 +1047,7 @@ Value ListReceived(const Array& params, bool fByAccounts) continue; int nDepth = wtx.GetDepthInMainChain(); + int nBCDepth = wtx.GetDepthInMainChain(false); if (nDepth < nMinDepth) continue; @@ -1059,6 +1064,7 @@ Value ListReceived(const Array& params, bool fByAccounts) tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; item.nConf = min(item.nConf, nDepth); + item.nBCConf = min(item.nBCConf, nBCDepth); item.txids.push_back(wtx.GetHash()); if (mine & ISMINE_WATCH_ONLY) item.fIsWatchonly = true; @@ -1078,11 +1084,13 @@ Value ListReceived(const Array& params, bool fByAccounts) CAmount nAmount = 0; int nConf = std::numeric_limits::max(); + int nBCConf = std::numeric_limits::max(); bool fIsWatchonly = false; if (it != mapTally.end()) { nAmount = (*it).second.nAmount; nConf = (*it).second.nConf; + nBCConf = (*it).second.nBCConf; fIsWatchonly = (*it).second.fIsWatchonly; } @@ -1091,6 +1099,7 @@ Value ListReceived(const Array& params, bool fByAccounts) tallyitem& item = mapAccountTally[strAccount]; item.nAmount += nAmount; item.nConf = min(item.nConf, nConf); + item.nBCConf = min(item.nBCConf, nBCConf); item.fIsWatchonly = fIsWatchonly; } else @@ -1102,6 +1111,7 @@ Value ListReceived(const Array& params, bool fByAccounts) obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits::max() ? 0 : nBCConf))); Array transactions; if (it != mapTally.end()) { @@ -1121,12 +1131,14 @@ Value ListReceived(const Array& params, bool fByAccounts) { CAmount nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; + int nBCConf = (*it).second.nBCConf; Object obj; if((*it).second.fIsWatchonly) obj.push_back(Pair("involvesWatchonly", true)); obj.push_back(Pair("account", (*it).first)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits::max() ? 0 : nBCConf))); ret.push_back(obj); } } @@ -1153,6 +1165,7 @@ Value listreceivedbyaddress(const Array& params, bool fHelp) " \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n" " \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n" " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" + " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n" " }\n" " ,...\n" "]\n" @@ -1184,6 +1197,7 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) " \"account\" : \"accountname\", (string) The account name of the receiving account\n" " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n" " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" + " \"bcconfirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n" " }\n" " ,...\n" "]\n" @@ -1323,6 +1337,8 @@ Value listtransactions(const Array& params, bool fHelp) " 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" " 'receive' category of transactions.\n" + " \"bcconfirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send'\n" + " and 'receive' category of transactions.\n" " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" " category of transactions.\n" " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n" @@ -1500,6 +1516,7 @@ Value listsinceblock(const Array& params, bool fHelp) " \"vout\" : n, (numeric) the vout value\n" " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" @@ -1551,7 +1568,7 @@ Value listsinceblock(const Array& params, bool fHelp) { CWalletTx tx = (*it).second; - if (depth == -1 || tx.GetDepthInMainChain() < depth) + if (depth == -1 || tx.GetDepthInMainChain(false) < depth) ListTransactions(tx, "*", 0, true, transactions, filter); } @@ -1578,6 +1595,7 @@ Value gettransaction(const Array& params, bool fHelp) "{\n" " \"amount\" : x.xxx, (numeric) The transaction amount in btc\n" " \"confirmations\" : n, (numeric) The number of confirmations\n" + " \"bcconfirmations\" : n, (numeric) The number of blockchain confirmations\n" " \"blockhash\" : \"hash\", (string) The block hash\n" " \"blockindex\" : xx, (numeric) The block index\n" " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n" diff --git a/src/util.cpp b/src/util.cpp index 62c305a114fd..42c1571f9d85 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -108,7 +108,8 @@ bool fMasterNode = false; string strMasterNodePrivKey = ""; string strMasterNodeAddr = ""; bool fLiteMode = false; -int nInstantXDepth = 1; +bool fEnableInstantX = true; +int nInstantXDepth = 5; int nDarksendRounds = 2; int nAnonymizeDarkcoinAmount = 1000; int nLiquidityProvider = 0; diff --git a/src/util.h b/src/util.h index 93f6db447021..6127b69da5c1 100644 --- a/src/util.h +++ b/src/util.h @@ -32,6 +32,7 @@ extern bool fMasterNode; extern bool fLiteMode; +extern bool fEnableInstantX; extern int nInstantXDepth; extern int nDarksendRounds; extern int nAnonymizeDarkcoinAmount; diff --git a/src/wallet.cpp b/src/wallet.cpp index b6293891f3d9..d57ddbdb885f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -3254,7 +3254,7 @@ int CMerkleTx::GetTransactionLockSignatures() const { if(fLargeWorkForkFound || fLargeWorkInvalidChainFound) return -2; if(!IsSporkActive(SPORK_2_INSTANTX)) return -3; - if(nInstantXDepth == 0) return -1; + if(!fEnableInstantX) return -1; //compile consessus vote std::map::iterator i = mapTxLocks.find(GetHash()); @@ -3267,7 +3267,7 @@ int CMerkleTx::GetTransactionLockSignatures() const bool CMerkleTx::IsTransactionLockTimedOut() const { - if(nInstantXDepth == 0) return 0; + if(!fEnableInstantX) return 0; //compile consessus vote std::map::iterator i = mapTxLocks.find(GetHash());