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
This commit is contained in:
UdjinM6 2015-09-11 21:19:14 +03:00
parent 818303dbbd
commit ae14019e6d
6 changed files with 40 additions and 14 deletions

View File

@ -425,7 +425,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += "\n" + _("InstantX options:") + "\n";
strUsage += " -enableinstantx=<n> " + strprintf(_("Enable instantx, show confirmations for locked transactions (bool, default: %s)"), "true") + "\n";
strUsage += " -instantxdepth=<n> " + strprintf(_("Show N confirmations for a successfully locked transaction (0-9999, default: %u)"), 1) + "\n";
strUsage += " -instantxdepth=<n> " + 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=<mode> -> 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);

View File

@ -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)

View File

@ -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<uint256> txids;
bool fIsWatchonly;
tallyitem()
{
nAmount = 0;
nConf = std::numeric_limits<int>::max();
nBCConf = std::numeric_limits<int>::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<int>::max();
int nBCConf = std::numeric_limits<int>::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<int>::max() ? 0 : nConf)));
obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits<int>::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<int>::max() ? 0 : nConf)));
obj.push_back(Pair("bcconfirmations", (nBCConf == std::numeric_limits<int>::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"

View File

@ -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;

View File

@ -32,6 +32,7 @@
extern bool fMasterNode;
extern bool fLiteMode;
extern bool fEnableInstantX;
extern int nInstantXDepth;
extern int nDarksendRounds;
extern int nAnonymizeDarkcoinAmount;

View File

@ -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<uint256, CTransactionLock>::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<uint256, CTransactionLock>::iterator i = mapTxLocks.find(GetHash());