better fix: make GetSpentIndex() consistent with others...

but don't call it if insight explorer isn't enabled
This commit is contained in:
Larry Ruane 2019-08-27 08:37:42 -06:00
parent 210c46c21d
commit e83168b8c8
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 false;
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));