Auto merge of #4115 - LarryRuane:4114-spent-index-debug, r=Eirik0

#4114 Don't call GetSpentIndex() when converting txs to JSON if spent index is disabled

Closes #4114.
This commit is contained in:
Homu 2019-08-28 21:09:19 -07:00
commit 424d8b1af5
2 changed files with 9 additions and 4 deletions

View File

@ -1633,10 +1633,15 @@ bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
{
AssertLockHeld(cs_main);
if (!fSpentIndex)
return error("spent index not enabled");
return error("Spent index not enabled");
if (mempool.getSpentIndex(key, value))
return true;
return pblocktree->ReadSpentIndex(key, value);
if (!pblocktree->ReadSpentIndex(key, value))
return error("Unable to get spent index information");
return true;
}
bool GetAddressIndex(const uint160& addressHash, int type,

View File

@ -176,7 +176,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
// Add address and value info if spentindex enabled
CSpentIndexValue spentInfo;
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
if (GetSpentIndex(spentKey, spentInfo)) {
if (fSpentIndex && GetSpentIndex(spentKey, spentInfo)) {
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
in.push_back(Pair("valueSat", spentInfo.satoshis));
@ -206,7 +206,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
// Add spent information if spentindex is enabled
CSpentIndexValue spentInfo;
CSpentIndexKey spentKey(txid, i);
if (GetSpentIndex(spentKey, spentInfo)) {
if (fSpentIndex && GetSpentIndex(spentKey, spentInfo)) {
out.push_back(Pair("spentTxId", spentInfo.txid.GetHex()));
out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex));
out.push_back(Pair("spentHeight", spentInfo.blockHeight));